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

EAC_init:
   71|    131|{
   72|       |    OpenSSL_add_all_algorithms();
   73|    131|    EAC_add_all_objects();
   74|    131|    EAC_set_x509_default_dir(X509DIR);
   75|    131|    EAC_set_cvc_default_dir(CVCDIR);
   76|    131|}
EAC_CTX_clear_free:
  277|     11|{
  278|     11|    if (ctx) {
  ------------------
  |  Branch (278:9): [True: 0, False: 11]
  ------------------
  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|     11|}

EAC_add_all_objects:
  174|    131|{
  175|    131|    int obj;
  176|       |
  177|    131|    if (objects_initialized)
  ------------------
  |  Branch (177:9): [True: 130, False: 1]
  ------------------
  178|    130|        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|    131|{
   64|    131|    if (default_dir) {
  ------------------
  |  Branch (64:9): [True: 131, False: 0]
  ------------------
   65|    131|        strncpy(x509_default_dir, default_dir, (sizeof x509_default_dir) - 1);
   66|    131|        x509_default_dir[(sizeof x509_default_dir) - 1] = '\0';
   67|    131|    }
   68|    131|}

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

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

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

sc_apdu_get_length:
   43|  1.72k|{
   44|  1.72k|	size_t ret = 4;
   45|       |
   46|  1.72k|	switch (apdu->cse) {
   47|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (47:2): [True: 0, False: 1.72k]
  ------------------
   48|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (48:7): [True: 0, False: 0]
  ------------------
   49|      0|			ret++;
   50|      0|		break;
   51|  1.72k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  1.72k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (51:2): [True: 1.72k, False: 0]
  ------------------
   52|  1.72k|		ret++;
   53|  1.72k|		break;
   54|      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 (54:2): [True: 0, False: 1.72k]
  ------------------
   55|      0|		ret += (proto == SC_PROTO_T0 ? 1 : 3);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (55:11): [True: 0, False: 0]
  ------------------
   56|      0|		break;
   57|      0|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (57:2): [True: 0, False: 1.72k]
  ------------------
   58|      0|		ret += 1 + apdu->lc;
   59|      0|		break;
   60|      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 (60:2): [True: 0, False: 1.72k]
  ------------------
   61|      0|		ret += apdu->lc + (proto == SC_PROTO_T0 ? 1 : 3);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (61:22): [True: 0, False: 0]
  ------------------
   62|      0|		break;
   63|      0|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (63:2): [True: 0, False: 1.72k]
  ------------------
   64|      0|		ret += apdu->lc + (proto != SC_PROTO_T0 ? 2 : 1);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (64:22): [True: 0, False: 0]
  ------------------
   65|      0|		break;
   66|      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 (66:2): [True: 0, False: 1.72k]
  ------------------
   67|      0|		ret += apdu->lc + (proto == SC_PROTO_T0 ? 1 : 5);
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (67:22): [True: 0, False: 0]
  ------------------
   68|      0|		break;
   69|      0|	default:
  ------------------
  |  Branch (69:2): [True: 0, False: 1.72k]
  ------------------
   70|      0|		return 0;
   71|  1.72k|	}
   72|  1.72k|	return ret;
   73|  1.72k|}
sc_apdu2bytes:
   85|    860|{
   86|    860|	u8     *p = out;
   87|       |
   88|    860|	size_t len = sc_apdu_get_length(apdu, proto);
   89|       |
   90|    860|	if (out == NULL || outlen < len)
  ------------------
  |  Branch (90:6): [True: 0, False: 860]
  |  Branch (90:21): [True: 0, False: 860]
  ------------------
   91|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|       |	/* CLA, INS, P1 and P2 */
   93|    860|	*p++ = apdu->cla;
   94|    860|	*p++ = apdu->ins;
   95|    860|	*p++ = apdu->p1;
   96|    860|	*p++ = apdu->p2;
   97|       |	/* case depend part */
   98|    860|	switch (apdu->cse) {
  ------------------
  |  Branch (98:10): [True: 860, False: 0]
  ------------------
   99|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (99:2): [True: 0, False: 860]
  ------------------
  100|       |		/* T0 needs an additional 0x00 byte */
  101|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (101:7): [True: 0, False: 0]
  ------------------
  102|      0|			*p = (u8)0x00;
  103|      0|		break;
  104|    860|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|    860|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (104:2): [True: 860, False: 0]
  ------------------
  105|    860|		*p = (u8)apdu->le;
  106|    860|		break;
  107|      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 (107:2): [True: 0, False: 860]
  ------------------
  108|      0|		if (proto == SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (108:7): [True: 0, False: 0]
  ------------------
  109|       |			/* T0 extended APDUs look just like short APDUs */
  110|      0|			*p = (u8)apdu->le;
  111|      0|		else {
  112|       |			/* in case of T1 always use 3 bytes for length */
  113|      0|			*p++ = (u8)0x00;
  114|      0|			*p++ = (u8)(apdu->le >> 8);
  115|      0|			*p = (u8)apdu->le;
  116|      0|		}
  117|      0|		break;
  118|      0|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (118:2): [True: 0, False: 860]
  ------------------
  119|      0|		*p++ = (u8)apdu->lc;
  120|      0|		memcpy(p, apdu->data, apdu->lc);
  121|      0|		break;
  122|      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 (122:2): [True: 0, False: 860]
  ------------------
  123|      0|		if (proto == SC_PROTO_T0) {
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (123:7): [True: 0, False: 0]
  ------------------
  124|       |			/* in case of T0 the command is transmitted in chunks
  125|       |			 * < 255 using the ENVELOPE command ... */
  126|      0|			if (apdu->lc > 255) {
  ------------------
  |  Branch (126:8): [True: 0, False: 0]
  ------------------
  127|       |				/* ... so if Lc is greater than 255 bytes
  128|       |				 * an error has occurred on a higher level */
  129|      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__
  |  |  ------------------
  ------------------
  130|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  131|      0|			}
  132|      0|		}
  133|      0|		else {
  134|       |			/* in case of T1 always use 3 bytes for length */
  135|      0|			*p++ = (u8)0x00;
  136|      0|			*p++ = (u8)(apdu->lc >> 8);
  137|      0|			*p++ = (u8)apdu->lc;
  138|      0|		}
  139|      0|		memcpy(p, apdu->data, apdu->lc);
  140|      0|		break;
  141|      0|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (141:2): [True: 0, False: 860]
  ------------------
  142|      0|		*p++ = (u8)apdu->lc;
  143|      0|		memcpy(p, apdu->data, apdu->lc);
  144|      0|		p += apdu->lc;
  145|       |		/* in case of T0 no Le byte is added */
  146|      0|		if (proto != SC_PROTO_T0)
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (146:7): [True: 0, False: 0]
  ------------------
  147|      0|			*p = (u8)apdu->le;
  148|      0|		break;
  149|      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 (149:2): [True: 0, False: 860]
  ------------------
  150|      0|		if (proto == SC_PROTO_T0) {
  ------------------
  |  |  352|      0|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (150:7): [True: 0, False: 0]
  ------------------
  151|       |			/* again a T0 extended case 4 APDU looks just
  152|       |			 * like a short APDU, the additional data is
  153|       |			 * transferred using ENVELOPE and GET RESPONSE */
  154|      0|			*p++ = (u8)apdu->lc;
  155|      0|			memcpy(p, apdu->data, apdu->lc);
  156|      0|		}
  157|      0|		else {
  158|      0|			*p++ = (u8)0x00;
  159|      0|			*p++ = (u8)(apdu->lc >> 8);
  160|      0|			*p++ = (u8)apdu->lc;
  161|      0|			memcpy(p, apdu->data, apdu->lc);
  162|      0|			p += apdu->lc;
  163|       |			/* only 2 bytes are use to specify the length of the
  164|       |			 * expected data */
  165|      0|			*p++ = (u8)(apdu->le >> 8);
  166|      0|			*p = (u8)apdu->le;
  167|      0|		}
  168|      0|		break;
  169|    860|	}
  170|       |
  171|    860|	return SC_SUCCESS;
  ------------------
  |  |   28|    860|#define SC_SUCCESS				0
  ------------------
  172|    860|}
sc_apdu_get_octets:
  176|    860|{
  177|    860|	size_t	nlen;
  178|    860|	u8	*nbuf;
  179|       |
  180|    860|	if (apdu == NULL || buf == NULL || len == NULL)
  ------------------
  |  Branch (180:6): [True: 0, False: 860]
  |  Branch (180:22): [True: 0, False: 860]
  |  Branch (180:37): [True: 0, False: 860]
  ------------------
  181|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  182|       |
  183|       |	/* get the estimated length of encoded APDU */
  184|    860|	nlen = sc_apdu_get_length(apdu, proto);
  185|    860|	if (nlen == 0)
  ------------------
  |  Branch (185:6): [True: 0, False: 860]
  ------------------
  186|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  187|    860|	nbuf = malloc(nlen);
  188|    860|	if (nbuf == NULL)
  ------------------
  |  Branch (188:6): [True: 0, False: 860]
  ------------------
  189|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  190|       |	/* encode the APDU in the buffer */
  191|    860|	if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) {
  ------------------
  |  |   28|    860|#define SC_SUCCESS				0
  ------------------
  |  Branch (191:6): [True: 0, False: 860]
  ------------------
  192|      0|		free(nbuf);
  193|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  194|      0|	}
  195|    860|	*buf = nbuf;
  196|    860|	*len = nlen;
  197|       |
  198|    860|	return SC_SUCCESS;
  ------------------
  |  |   28|    860|#define SC_SUCCESS				0
  ------------------
  199|    860|}
sc_check_apdu:
  257|   278k|{
  258|   278k|	if ((apdu->cse & ~SC_APDU_SHORT_MASK) == 0) {
  ------------------
  |  |  295|   278k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  |  Branch (258:6): [True: 277k, False: 650]
  ------------------
  259|       |		/* length check for short APDU */
  260|   277k|		if (apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0))   {
  ------------------
  |  |  306|      0|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (260:7): [True: 0, False: 277k]
  |  Branch (260:26): [True: 0, False: 277k]
  |  Branch (260:44): [True: 0, False: 0]
  ------------------
  261|      0|			sc_log(card->ctx, "failed length check for short 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__
  |  |  ------------------
  ------------------
  262|      0|			goto error;
  263|      0|		}
  264|   277k|	}
  265|    650|	else if ((apdu->cse & SC_APDU_EXT) != 0) {
  ------------------
  |  |  296|    650|#define SC_APDU_EXT			0x10
  ------------------
  |  Branch (265:11): [True: 650, False: 0]
  ------------------
  266|       |		/* check if the card supports extended APDUs */
  267|    650|		if ((card->caps & SC_CARD_CAP_APDU_EXT) == 0) {
  ------------------
  |  |  547|    650|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (267:7): [True: 0, False: 650]
  ------------------
  268|      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__
  |  |  ------------------
  ------------------
  269|      0|			goto error;
  270|      0|		}
  271|       |		/* length check for extended APDU */
  272|    650|		if (apdu->le > 65536 || apdu->lc > 65535)   {
  ------------------
  |  Branch (272:7): [True: 0, False: 650]
  |  Branch (272:27): [True: 0, False: 650]
  ------------------
  273|      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__
  |  |  ------------------
  ------------------
  274|      0|			goto error;
  275|      0|		}
  276|    650|	}
  277|      0|	else   {
  278|      0|		goto error;
  279|      0|	}
  280|       |
  281|   278k|	switch (apdu->cse & SC_APDU_SHORT_MASK) {
  ------------------
  |  |  295|   278k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  282|  1.97k|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|  1.97k|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (282:2): [True: 1.97k, False: 276k]
  ------------------
  283|       |		/* no data is sent or received */
  284|  1.97k|		if (apdu->datalen != 0 || apdu->lc != 0 || apdu->le != 0)
  ------------------
  |  Branch (284:7): [True: 0, False: 1.97k]
  |  Branch (284:29): [True: 0, False: 1.97k]
  |  Branch (284:46): [True: 0, False: 1.97k]
  ------------------
  285|      0|			goto error;
  286|  1.97k|		break;
  287|  55.8k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  55.8k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (287:2): [True: 55.8k, False: 222k]
  ------------------
  288|       |		/* no data is sent */
  289|  55.8k|		if (apdu->datalen != 0 || apdu->lc != 0)
  ------------------
  |  Branch (289:7): [True: 0, False: 55.8k]
  |  Branch (289:29): [True: 0, False: 55.8k]
  ------------------
  290|      0|			goto error;
  291|       |		/* data is expected       */
  292|  55.8k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (292:7): [True: 0, False: 55.8k]
  |  Branch (292:29): [True: 0, False: 55.8k]
  ------------------
  293|      0|			goto error;
  294|  55.8k|		break;
  295|  55.8k|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|  30.3k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (295:2): [True: 30.3k, False: 248k]
  ------------------
  296|       |		/* data is sent */
  297|  30.3k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 30.3k]
  |  Branch (297:29): [True: 0, False: 30.3k]
  |  Branch (297:51): [True: 0, False: 30.3k]
  ------------------
  298|      0|			goto error;
  299|       |		/* no data is expected    */
  300|  30.3k|		if (apdu->le != 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 30.3k]
  ------------------
  301|      0|			goto error;
  302|       |		/* inconsistent datalen   */
  303|  30.3k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (303:7): [True: 0, False: 30.3k]
  ------------------
  304|      0|			goto error;
  305|  30.3k|		break;
  306|   190k|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|   190k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (306:2): [True: 190k, False: 88.1k]
  ------------------
  307|       |		/* data is sent */
  308|   190k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (308:7): [True: 11, False: 190k]
  |  Branch (308:29): [True: 0, False: 190k]
  |  Branch (308:51): [True: 0, False: 190k]
  ------------------
  309|     11|			goto error;
  310|       |		/* data is expected       */
  311|   190k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (311:7): [True: 0, False: 190k]
  |  Branch (311:29): [True: 0, False: 190k]
  ------------------
  312|      0|			goto error;
  313|       |		/* inconsistent datalen   */
  314|   190k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (314:7): [True: 0, False: 190k]
  ------------------
  315|      0|			goto error;
  316|   190k|		break;
  317|   190k|	default:
  ------------------
  |  Branch (317:2): [True: 0, False: 278k]
  ------------------
  318|      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__
  |  |  ------------------
  ------------------
  319|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  320|   278k|	}
  321|   278k|	return SC_SUCCESS;
  ------------------
  |  |   28|   278k|#define SC_SUCCESS				0
  ------------------
  322|     11|error:
  323|     11|	sc_log(card->ctx, "Invalid Case %d %s APDU:\n"
  ------------------
  |  |   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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  326|     22|		apdu->cse & SC_APDU_SHORT_MASK,
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     11|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |  327|     22|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     11|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  328|     22|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  |  |  |  |  329|     22|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  |  |  |  |  330|     22|		apdu->resp, (unsigned long) apdu->resplen,
  |  |  |  |  331|     22|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  |  |  ------------------
  ------------------
  324|     11|		"cse=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%lu le=%lu\n"
  325|     11|		"resp=%p resplen=%lu data=%p datalen=%lu flags=0x%8.8lx",
  326|     11|		apdu->cse & SC_APDU_SHORT_MASK,
  327|     11|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  328|     11|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  329|     11|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  330|     11|		apdu->resp, (unsigned long) apdu->resplen,
  331|     11|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  332|     11|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     11|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  333|   278k|}
sc_transmit_apdu:
  542|   252k|{
  543|   252k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   252k|#define SC_SUCCESS				0
  ------------------
  544|       |
  545|   252k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 252k]
  |  Branch (545:22): [True: 0, False: 252k]
  ------------------
  546|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  547|       |
  548|   252k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   252k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   252k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   252k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   252k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 252k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  549|       |
  550|       |	/* determine the APDU type if necessary, i.e. to use
  551|       |	 * short or extended APDUs  */
  552|   252k|	sc_detect_apdu_cse(card, apdu);
  553|       |	/* basic APDU consistency check */
  554|   252k|	r = sc_check_apdu(card, apdu);
  555|   252k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   252k|#define SC_SUCCESS				0
  ------------------
  |  Branch (555:6): [True: 11, False: 252k]
  ------------------
  556|     11|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     11|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  557|       |
  558|   252k|	r = sc_lock(card);	/* acquire card lock*/
  559|   252k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|   252k|#define SC_SUCCESS				0
  ------------------
  |  Branch (559:6): [True: 0, False: 252k]
  ------------------
  560|      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__
  |  |  ------------------
  ------------------
  561|      0|		return r;
  562|      0|	}
  563|       |
  564|   252k|#if ENABLE_SM
  565|   252k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|   505k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (565:6): [True: 1.04k, False: 251k]
  ------------------
  566|  1.04k|			&& (apdu->flags & SC_APDU_FLAGS_CHAINING) != 0
  ------------------
  |  |  306|  1.04k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (566:7): [True: 0, False: 1.04k]
  ------------------
  567|      0|			&& (apdu->flags & SC_APDU_FLAGS_SM_CHAINING) != 0) {
  ------------------
  |  |  316|      0|#define SC_APDU_FLAGS_SM_CHAINING	0x00000010UL
  ------------------
  |  Branch (567:7): [True: 0, False: 0]
  ------------------
  568|      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__
  |  |  ------------------
  ------------------
  569|      0|		r = sc_transmit(card, apdu);
  570|      0|	} else
  571|   252k|#endif
  572|   252k|	if ((apdu->flags & SC_APDU_FLAGS_CHAINING) != 0) {
  ------------------
  |  |  306|   252k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (572:6): [True: 24.8k, False: 227k]
  ------------------
  573|       |		/* divide et impera: transmit APDU in chunks with Lc <= max_send_size
  574|       |		 * bytes using command chaining */
  575|  24.8k|		size_t    len  = apdu->datalen;
  576|  24.8k|		const u8  *buf = apdu->data;
  577|  24.8k|		size_t    max_send_size = sc_get_max_send_size(card);
  578|       |
  579|  49.7k|		while (len != 0) {
  ------------------
  |  Branch (579:10): [True: 25.1k, False: 24.5k]
  ------------------
  580|  25.1k|			size_t    plen;
  581|  25.1k|			sc_apdu_t tapdu;
  582|  25.1k|			int       last = 0;
  583|       |
  584|  25.1k|			tapdu = *apdu;
  585|       |			/* clear chaining flag */
  586|  25.1k|			tapdu.flags &= ~SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  25.1k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  587|  25.1k|			if (len > max_send_size) {
  ------------------
  |  Branch (587:8): [True: 313, False: 24.8k]
  ------------------
  588|       |				/* adjust APDU case: in case of CASE 4 APDU
  589|       |				 * the intermediate APDU are of CASE 3 */
  590|    313|				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  295|    313|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
              				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  294|    313|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (590:9): [True: 313, False: 0]
  ------------------
  591|    313|					tapdu.cse--;
  592|       |				/* XXX: the chunk size must be adjusted when
  593|       |				 *      secure messaging is used */
  594|    313|				plen          = max_send_size;
  595|    313|				tapdu.cla    |= 0x10;
  596|       |				/* the intermediate APDU don't expect response data */
  597|    313|				tapdu.le      = 0;
  598|    313|				tapdu.resplen = 0;
  599|    313|				tapdu.resp    = NULL;
  600|  24.8k|			} else {
  601|  24.8k|				plen = len;
  602|  24.8k|				last = 1;
  603|  24.8k|			}
  604|  25.1k|			tapdu.data    = buf;
  605|  25.1k|			tapdu.datalen = tapdu.lc = plen;
  606|       |
  607|  25.1k|			r = sc_check_apdu(card, &tapdu);
  608|  25.1k|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  25.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (608:8): [True: 0, False: 25.1k]
  ------------------
  609|      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__
  |  |  ------------------
  ------------------
  610|      0|				break;
  611|      0|			}
  612|       |
  613|  25.1k|			r = sc_transmit(card, &tapdu);
  614|  25.1k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  25.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (614:8): [True: 267, False: 24.8k]
  ------------------
  615|    267|				break;
  616|  24.8k|			if (last != 0) {
  ------------------
  |  Branch (616:8): [True: 24.5k, False: 313]
  ------------------
  617|       |				/* in case of the last APDU set the SW1
  618|       |				 * and SW2 bytes in the original APDU */
  619|  24.5k|				apdu->sw1 = tapdu.sw1;
  620|  24.5k|				apdu->sw2 = tapdu.sw2;
  621|  24.5k|				apdu->resplen = tapdu.resplen;
  622|  24.5k|			} else {
  623|       |				/* otherwise check the status bytes */
  624|    313|				r = sc_check_sw(card, tapdu.sw1, tapdu.sw2);
  625|    313|				if (r != SC_SUCCESS)
  ------------------
  |  |   28|    313|#define SC_SUCCESS				0
  ------------------
  |  Branch (625:9): [True: 67, False: 246]
  ------------------
  626|     67|					break;
  627|    313|			}
  628|  24.8k|			len -= plen;
  629|  24.8k|			buf += plen;
  630|  24.8k|		}
  631|   227k|	} else {
  632|       |		/* transmit single APDU */
  633|   227k|		r = sc_transmit(card, apdu);
  634|   227k|	}
  635|       |
  636|   252k|	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   505k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   252k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (636:6): [True: 0, False: 252k]
  |  Branch (636:34): [True: 0, False: 252k]
  ------------------
  637|       |		/* give card driver a chance to react on resets */
  638|      0|		if (card->ops->card_reader_lock_obtained)
  ------------------
  |  Branch (638:7): [True: 0, False: 0]
  ------------------
  639|      0|			card->ops->card_reader_lock_obtained(card, 1);
  640|      0|	}
  641|       |
  642|       |	/* all done => release lock */
  643|   252k|	if (sc_unlock(card) != SC_SUCCESS)
  ------------------
  |  |   28|   252k|#define SC_SUCCESS				0
  ------------------
  |  Branch (643:6): [True: 0, False: 252k]
  ------------------
  644|      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__
  |  |  ------------------
  ------------------
  645|       |
  646|   252k|	return r;
  647|   252k|}
apdu.c:sc_detect_apdu_cse:
  341|   252k|{
  342|   252k|	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  301|   505k|#define SC_APDU_CASE_2			0x22
  ------------------
              	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  302|   465k|#define SC_APDU_CASE_3			0x23
  ------------------
  |  Branch (342:6): [True: 40.4k, False: 212k]
  |  Branch (342:37): [True: 9, False: 212k]
  ------------------
  343|   212k|	    apdu->cse == SC_APDU_CASE_4) {
  ------------------
  |  |  303|   212k|#define SC_APDU_CASE_4			0x24
  ------------------
  |  Branch (343:6): [True: 2.42k, False: 209k]
  ------------------
  344|  42.8k|		int btype = apdu->cse & SC_APDU_SHORT_MASK;
  ------------------
  |  |  295|  42.8k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  345|       |		/* if either Lc or Le is bigger than the maximum for
  346|       |		 * short APDUs and the card supports extended APDUs
  347|       |		 * use extended APDUs (unless Lc is greater than
  348|       |		 * 255 and command chaining is activated) */
  349|  42.8k|		if ((apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
  ------------------
  |  |  306|      0|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (349:8): [True: 648, False: 42.2k]
  |  Branch (349:27): [True: 0, False: 42.2k]
  |  Branch (349:45): [True: 0, False: 0]
  ------------------
  350|    648|		    (card->caps & SC_CARD_CAP_APDU_EXT) != 0)
  ------------------
  |  |  547|    648|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (350:7): [True: 648, False: 0]
  ------------------
  351|    648|			btype |= SC_APDU_EXT;
  ------------------
  |  |  296|    648|#define SC_APDU_EXT			0x10
  ------------------
  352|  42.8k|		apdu->cse = btype;
  353|  42.8k|	}
  354|   252k|}
apdu.c:sc_transmit:
  508|   253k|{
  509|   253k|	struct sc_context *ctx  = card->ctx;
  510|   253k|	size_t       olen  = apdu->resplen;
  511|   253k|	int          r;
  512|       |
  513|   253k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   253k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   253k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   253k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   253k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 253k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|   253k|	r = sc_single_transmit(card, apdu);
  516|   253k|	LOG_TEST_RET(ctx, r, "transmit APDU failed");
  ------------------
  |  |  174|   253k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   253k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   253k|	int _ret = (r); \
  |  |  |  |  168|   253k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 337, False: 252k]
  |  |  |  |  ------------------
  |  |  |  |  169|    337|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    337|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    337|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    337|		return _ret; \
  |  |  |  |  172|    337|	} \
  |  |  |  |  173|   253k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 252k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|       |
  518|       |	/* ok, the APDU was successfully transmitted. Now we have two special cases:
  519|       |	 * 1. the card returned 0x6Cxx: in this case APDU will be re-transmitted with Le set to SW2
  520|       |	 * (possible only if response buffer size is larger than new Le = SW2)
  521|       |	 */
  522|   252k|	if (apdu->sw1 == 0x6C && (apdu->flags & SC_APDU_FLAGS_NO_RETRY_WL) == 0) {
  ------------------
  |  |  312|    516|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  |  Branch (522:6): [True: 516, False: 252k]
  |  Branch (522:27): [True: 479, False: 37]
  ------------------
  523|    479|		r = sc_set_le_and_transmit(card, apdu, olen);
  524|    479|		LOG_TEST_RET(ctx, r, "cannot re-transmit APDU ");
  ------------------
  |  |  174|    479|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    479|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    479|	int _ret = (r); \
  |  |  |  |  168|    479|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 162, False: 317]
  |  |  |  |  ------------------
  |  |  |  |  169|    162|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    162|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    162|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    162|		return _ret; \
  |  |  |  |  172|    162|	} \
  |  |  |  |  173|    479|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 317]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|    479|	}
  526|       |
  527|       |	/* 2. the card returned 0x61xx: more data can be read from the card
  528|       |	 *    using the GET RESPONSE command (mostly used in the T0 protocol).
  529|       |	 *    Unless the SC_APDU_FLAGS_NO_GET_RESP is set we try to read as
  530|       |	 *    much data as possible using GET RESPONSE.
  531|       |	 */
  532|   252k|	if (apdu->sw1 == 0x61 && (apdu->flags & SC_APDU_FLAGS_NO_GET_RESP) == 0) {
  ------------------
  |  |  308|  32.1k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  |  Branch (532:6): [True: 32.1k, False: 220k]
  |  Branch (532:27): [True: 27.7k, False: 4.35k]
  ------------------
  533|  27.7k|		r = sc_get_response(card, apdu, olen);
  534|  27.7k|		LOG_TEST_RET(ctx, r, "cannot get all data with 'GET RESPONSE'");
  ------------------
  |  |  174|  27.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  27.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  27.7k|	int _ret = (r); \
  |  |  |  |  168|  27.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.14k, False: 23.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.14k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.14k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.14k|		return _ret; \
  |  |  |  |  172|  4.14k|	} \
  |  |  |  |  173|  27.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|  27.7k|	}
  536|       |
  537|   248k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|   248k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   248k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   248k|	int _ret = r; \
  |  |  |  |  155|   248k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 248k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   248k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 248k]
  |  |  |  |  ------------------
  |  |  |  |  157|   248k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   248k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   248k|	return _ret; \
  |  |  |  |  163|   248k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|   248k|}
apdu.c:sc_single_transmit:
  359|   253k|{
  360|   253k|	struct sc_context *ctx  = card->ctx;
  361|   253k|	int rv;
  362|       |
  363|   253k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   253k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   253k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   253k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   253k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 253k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|   253k|	if (card->reader->ops->transmit == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 253k]
  ------------------
  365|   253k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|       |
  367|   253k|	sc_log(ctx, "CLA:%X, INS:%X, P1:%X, P2:%X, data(%zu) %p",
  ------------------
  |  |   71|   253k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  368|   253k|			apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen, apdu->data);
  369|   253k|#ifdef ENABLE_SM
  370|   253k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|   506k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (370:6): [True: 1.07k, False: 252k]
  ------------------
  371|  1.07k|		   	&& (apdu->flags & SC_APDU_FLAGS_NO_SM) == 0) {
  ------------------
  |  |  314|  1.07k|#define SC_APDU_FLAGS_NO_SM		0x00000008UL
  ------------------
  |  Branch (371:10): [True: 535, False: 535]
  ------------------
  372|    535|		LOG_FUNC_RETURN(ctx, sc_sm_single_transmit(card, apdu));
  ------------------
  |  |  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|    341|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 341, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    535|	}
  374|   252k|#endif
  375|       |
  376|       |	/* send APDU to the reader driver */
  377|   252k|	rv = card->reader->ops->transmit(card->reader, apdu);
  378|   252k|	LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  174|   252k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   252k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   252k|	int _ret = (r); \
  |  |  |  |  168|   252k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 252k]
  |  |  |  |  ------------------
  |  |  |  |  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|   252k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 252k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|   252k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|   252k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   252k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   252k|	int _ret = r; \
  |  |  |  |  155|   252k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 252k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   252k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 252k]
  |  |  |  |  ------------------
  |  |  |  |  157|   252k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   252k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   252k|	return _ret; \
  |  |  |  |  163|   252k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|   252k|}
apdu.c:sc_set_le_and_transmit:
  386|    479|{
  387|    479|	struct sc_context *ctx  = card->ctx;
  388|    479|	size_t nlen = apdu->sw2 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (388:16): [True: 337, False: 142]
  ------------------
  389|    479|	int rv;
  390|       |
  391|    479|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    479|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    479|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    479|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    479|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 479]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |	/* we cannot re-transmit the APDU with the demanded Le value
  393|       |	 * as the buffer is too small => error */
  394|    479|	if (olen < nlen)
  ------------------
  |  Branch (394:6): [True: 158, False: 321]
  ------------------
  395|    479|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_LENGTH, "wrong length: required length exceeds resplen");
  ------------------
  |  |  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: 158, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    158|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    158|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    158|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    158|		return _ret; \
  |  |  |  |  172|    158|	} \
  |  |  |  |  173|    158|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|       |	/* don't try again if it doesn't work this time */
  398|    321|	apdu->flags  |= SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|    321|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  399|       |	/* set the new expected length */
  400|    321|	apdu->resplen = olen;
  401|    321|	apdu->le      = nlen;
  402|       |#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  403|       |	/* Belpic V1 applets have a problem: if the card sends a 6C XX (only XX bytes available),
  404|       |	 * and we resend the command too soon (i.e. the reader is too fast), the card doesn't respond.
  405|       |	 * So we build in a delay. */
  406|       |	if (card->type == SC_CARD_TYPE_BELPIC_EID)
  407|       |		msleep(40);
  408|       |#endif
  409|       |
  410|       |	/* re-transmit the APDU with new Le length */
  411|    321|	rv = sc_single_transmit(card, apdu);
  412|    321|	LOG_TEST_RET(ctx, rv, "cannot re-transmit APDU");
  ------------------
  |  |  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: 4, False: 317]
  |  |  |  |  ------------------
  |  |  |  |  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|    321|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 317]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  413|       |
  414|    317|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    317|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    317|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    317|	int _ret = r; \
  |  |  |  |  155|    317|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 317, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    317|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 317]
  |  |  |  |  ------------------
  |  |  |  |  157|    317|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    317|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    317|	return _ret; \
  |  |  |  |  163|    317|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|    317|}
apdu.c:sc_get_response:
  420|  27.7k|{
  421|  27.7k|	struct sc_context *ctx  = card->ctx;
  422|  27.7k|	size_t le, minlen, buflen;
  423|  27.7k|	unsigned char *buf;
  424|  27.7k|	int rv;
  425|       |
  426|  27.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  27.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  27.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  27.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  27.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 27.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|  27.7k|	if (apdu->le == 0) {
  ------------------
  |  Branch (427:6): [True: 3.42k, False: 24.3k]
  ------------------
  428|       |		/* no data is requested => change return value to 0x9000 and ignore the remaining data */
  429|  3.42k|		apdu->sw1 = 0x90;
  430|  3.42k|		apdu->sw2 = 0x00;
  431|  3.42k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.42k|#define SC_SUCCESS				0
  ------------------
  432|  3.42k|	}
  433|       |
  434|       |	/* this should _never_ happen */
  435|  24.3k|	if (!card->ops->get_response)
  ------------------
  |  Branch (435:6): [True: 75, False: 24.2k]
  ------------------
  436|  24.3k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "no GET RESPONSE command");
  ------------------
  |  |  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: 75, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     75|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     75|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     75|		return _ret; \
  |  |  |  |  172|     75|	} \
  |  |  |  |  173|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|       |
  438|       |	/* call GET RESPONSE until we have read all data requested or until the card returns 0x9000,
  439|       |	 * whatever happens first. */
  440|       |
  441|       |	/* if there are already data in response append a new data to the end of the buffer */
  442|  24.2k|	buf = apdu->resp + apdu->resplen;
  443|       |
  444|       |	/* read as much data as fits in apdu->resp (i.e. min(apdu->resplen, amount of data available)). */
  445|  24.2k|	buflen = olen - apdu->resplen;
  446|       |
  447|       |	/* 0x6100 means at least 256 more bytes to read */
  448|  24.2k|	le = apdu->sw2 != 0 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (448:7): [True: 14.0k, False: 10.1k]
  ------------------
  449|       |	/* we try to read at least as much as bytes as promised in the response bytes */
  450|  24.2k|	minlen = le;
  451|       |
  452|  28.5k|	do {
  453|  28.5k|		unsigned char resp[256];
  454|  28.5k|		size_t resp_len = le;
  455|       |
  456|       |		/* we have all the data the caller requested even if the card has more data */
  457|  28.5k|		if (buflen == 0)
  ------------------
  |  Branch (457:7): [True: 4.10k, False: 24.4k]
  ------------------
  458|  4.10k|			break;
  459|       |
  460|       |		/* call GET RESPONSE to get more date from the card;
  461|       |		 * note: GET RESPONSE returns the left amount of data (== SW2) */
  462|  24.4k|		memset(resp, 0, sizeof(resp));
  463|  24.4k|		rv = card->ops->get_response(card, &resp_len, resp);
  464|  24.4k|		if (rv < 0)   {
  ------------------
  |  Branch (464:7): [True: 4.06k, False: 20.3k]
  ------------------
  465|  4.06k|#ifdef ENABLE_SM
  466|  4.06k|			if (resp_len)   {
  ------------------
  |  Branch (466:8): [True: 2.31k, False: 1.75k]
  ------------------
  467|  2.31k|				sc_log_hex(ctx, "SM response data", resp, resp_len);
  ------------------
  |  |  129|  2.31k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  2.31k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|  2.31k|				sc_sm_update_apdu_response(card, resp, resp_len, rv, apdu);
  469|  2.31k|			}
  470|  4.06k|#endif
  471|  4.06k|			LOG_TEST_RET(ctx, rv, "GET RESPONSE error");
  ------------------
  |  |  174|  4.06k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.06k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.06k|	int _ret = (r); \
  |  |  |  |  168|  4.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.06k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.06k|		return _ret; \
  |  |  |  |  172|  4.06k|	} \
  |  |  |  |  173|  4.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|  4.06k|		}
  473|       |
  474|  20.3k|		le = resp_len;
  475|       |		/* copy as much as will fit in requested buffer */
  476|  20.3k|		if (buflen < le)
  ------------------
  |  Branch (476:7): [True: 2.22k, False: 18.1k]
  ------------------
  477|  2.22k|			le = buflen;
  478|       |
  479|  20.3k|		memcpy(buf, resp, le);
  480|  20.3k|		buf    += le;
  481|  20.3k|		buflen -= le;
  482|       |
  483|  20.3k|		minlen -= le;
  484|  20.3k|		if (rv != 0)
  ------------------
  |  Branch (484:7): [True: 4.31k, False: 16.0k]
  ------------------
  485|  4.31k|			le = minlen = (size_t)rv;
  486|  16.0k|		else
  487|       |			/* if the card has returned 0x9000 but we still expect data ask for more
  488|       |			 * until we have read enough bytes */
  489|  16.0k|			le = minlen;
  490|  20.3k|	} while (rv != 0 && minlen != 0);
  ------------------
  |  Branch (490:11): [True: 4.31k, False: 16.0k]
  |  Branch (490:22): [True: 4.31k, False: 0]
  ------------------
  491|       |
  492|       |	/* we've read all data, let's return 0x9000 */
  493|  20.1k|	apdu->resplen = buf - apdu->resp;
  494|  20.1k|	apdu->sw1 = 0x90;
  495|  20.1k|	apdu->sw2 = 0x00;
  496|       |
  497|  20.1k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  20.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  20.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  20.1k|	int _ret = r; \
  |  |  |  |  155|  20.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  20.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: 20.1k]
  |  |  |  |  ------------------
  |  |  |  |  157|  20.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  20.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|  20.1k|	return _ret; \
  |  |  |  |  163|  20.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  498|  20.1k|}

sc_asn1_read_tag:
   64|   106k|{
   65|   106k|	const u8 *p = *buf;
   66|   106k|	size_t left = buflen, len;
   67|   106k|	unsigned int cla, tag, i;
   68|       |
   69|   106k|	*buf = NULL;
   70|       |
   71|   106k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (71:6): [True: 1.58k, False: 105k]
  |  Branch (71:19): [True: 0, False: 105k]
  |  Branch (71:25): [True: 0, False: 105k]
  ------------------
   72|  1.58k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.58k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   73|   105k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (73:6): [True: 368, False: 104k]
  |  Branch (73:20): [True: 3.06k, False: 101k]
  ------------------
   74|       |		/* end of data reached */
   75|  3.42k|		*taglen = 0;
   76|  3.42k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  3.42k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  3.42k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.42k|#define SC_SUCCESS				0
  ------------------
   78|  3.42k|	}
   79|       |
   80|       |	/* parse tag byte(s)
   81|       |	 * Resulted tag is presented by integer that has not to be
   82|       |	 * confused with the 'tag number' part of ASN.1 tag.
   83|       |	 */
   84|   101k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   101k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   101k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   101k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   101k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   101k|	p++;
   87|   101k|	left--;
   88|   101k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   101k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (88:6): [True: 2.39k, False: 99.3k]
  ------------------
   89|       |		/* high tag number */
   90|  2.39k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  2.39k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   91|       |		/* search the last tag octet */
   92|  2.94k|		do {
   93|  2.94k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (93:8): [True: 41, False: 2.90k]
  |  Branch (93:21): [True: 114, False: 2.79k]
  ------------------
   94|       |				/* either an invalid tag or it doesn't fit in
   95|       |				 * unsigned int */
   96|    155|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    155|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   97|  2.79k|			tag <<= 8;
   98|  2.79k|			tag |= *p;
   99|  2.79k|			p++;
  100|  2.79k|			left--;
  101|  2.79k|			n--;
  102|  2.79k|		} while (tag & 0x80);
  ------------------
  |  Branch (102:12): [True: 552, False: 2.24k]
  ------------------
  103|  2.39k|	}
  104|       |
  105|       |	/* parse length byte(s) */
  106|   101k|	if (left == 0)
  ------------------
  |  Branch (106:6): [True: 211, False: 101k]
  ------------------
  107|    211|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    211|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  108|   101k|	len = *p;
  109|   101k|	p++;
  110|   101k|	left--;
  111|   101k|	if (len & 0x80) {
  ------------------
  |  Branch (111:6): [True: 9.36k, False: 91.9k]
  ------------------
  112|  9.36k|		len &= 0x7f;
  113|  9.36k|		unsigned int a = 0;
  114|  9.36k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (114:7): [True: 1.78k, False: 7.58k]
  |  Branch (114:25): [True: 72, False: 7.51k]
  ------------------
  115|  1.85k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.85k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  116|  17.5k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (116:15): [True: 10.0k, False: 7.51k]
  ------------------
  117|  10.0k|			a <<= 8;
  118|  10.0k|			a |= *p;
  119|  10.0k|			p++;
  120|  10.0k|			left--;
  121|  10.0k|		}
  122|  7.51k|		len = a;
  123|  7.51k|	}
  124|       |
  125|  99.5k|	*cla_out = cla;
  126|  99.5k|	*tag_out = tag;
  127|  99.5k|	*taglen = len;
  128|  99.5k|	*buf = p;
  129|       |
  130|  99.5k|	if (len > left)
  ------------------
  |  Branch (130:6): [True: 7.86k, False: 91.6k]
  ------------------
  131|  7.86k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  7.86k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  132|       |
  133|  91.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  91.6k|#define SC_SUCCESS				0
  ------------------
  134|  99.5k|}
sc_format_asn1_entry:
  138|   104k|{
  139|   104k|	entry->parm = parm;
  140|   104k|	entry->arg  = arg;
  141|   104k|	if (set_present)
  ------------------
  |  Branch (141:6): [True: 14.4k, False: 90.1k]
  ------------------
  142|  14.4k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  14.4k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  143|   104k|}
sc_copy_asn1_entry:
  147|  32.4k|{
  148|   137k|	while (src->name != NULL) {
  ------------------
  |  Branch (148:9): [True: 105k, False: 32.4k]
  ------------------
  149|   105k|		*dest = *src;
  150|   105k|		dest++;
  151|   105k|		src++;
  152|   105k|	}
  153|       |	dest->name = NULL;
  154|  32.4k|}
sc_asn1_find_tag:
  482|  12.4k|{
  483|  12.4k|	size_t left = buflen, taglen;
  484|  12.4k|	const u8 *p = buf;
  485|       |
  486|  12.4k|	*taglen_in = 0;
  487|  29.5k|	while (left >= 2) {
  ------------------
  |  Branch (487:9): [True: 27.8k, False: 1.69k]
  ------------------
  488|  27.8k|		unsigned int cla = 0, tag, mask = 0xff00;
  489|       |
  490|  27.8k|		buf = p;
  491|       |		/* read a tag */
  492|  27.8k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|  55.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (492:7): [True: 2.68k, False: 25.1k]
  ------------------
  493|  25.1k|				|| p == NULL)
  ------------------
  |  Branch (493:8): [True: 1.55k, False: 23.6k]
  ------------------
  494|  4.23k|			return NULL;
  495|       |
  496|  23.6k|		left -= (p - buf);
  497|       |		/* we need to shift the class byte to the leftmost
  498|       |		 * byte of the tag */
  499|  24.4k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (499:10): [True: 834, False: 23.6k]
  ------------------
  500|    834|			cla  <<= 8;
  501|    834|			mask <<= 8;
  502|    834|		}
  503|       |		/* compare the read tag with the given tag */
  504|  23.6k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (504:7): [True: 6.54k, False: 17.0k]
  ------------------
  505|       |			/* we have a match => return length and value part */
  506|  6.54k|			if (taglen > left)
  ------------------
  |  Branch (506:8): [True: 0, False: 6.54k]
  ------------------
  507|      0|				return NULL;
  508|  6.54k|			*taglen_in = taglen;
  509|  6.54k|			return p;
  510|  6.54k|		}
  511|       |		/* otherwise continue reading tags */
  512|  17.0k|		left -= taglen;
  513|  17.0k|		p += taglen;
  514|  17.0k|	}
  515|  1.69k|	return NULL;
  516|  12.4k|}
sc_asn1_skip_tag:
  520|  24.7k|{
  521|  24.7k|	const u8 *p = *buf;
  522|  24.7k|	size_t len = *buflen, taglen;
  523|  24.7k|	unsigned int cla = 0, tag;
  524|       |
  525|  24.7k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|  49.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (525:6): [True: 6.39k, False: 18.3k]
  ------------------
  526|  18.3k|			|| p == NULL)
  ------------------
  |  Branch (526:7): [True: 812, False: 17.5k]
  ------------------
  527|  7.21k|		return NULL;
  528|  17.5k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (528:10): [True: 17.5k, False: 0]
  ------------------
  529|  11.6k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  11.6k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (529:2): [True: 11.6k, False: 5.86k]
  ------------------
  530|  11.6k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  11.6k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  11.6k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (530:7): [True: 732, False: 10.9k]
  ------------------
  531|    732|			return NULL;
  532|  10.9k|		break;
  533|  10.9k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  2.07k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (533:2): [True: 2.07k, False: 15.4k]
  ------------------
  534|  2.07k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  2.07k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  2.07k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (534:7): [True: 1.04k, False: 1.03k]
  ------------------
  535|  1.04k|			return NULL;
  536|  1.03k|		break;
  537|  3.66k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  3.66k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (537:2): [True: 3.66k, False: 13.8k]
  ------------------
  538|  3.66k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  3.66k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  3.66k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (538:7): [True: 398, False: 3.27k]
  ------------------
  539|    398|			return NULL;
  540|  3.27k|		break;
  541|  3.27k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|    118|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (541:2): [True: 118, False: 17.4k]
  ------------------
  542|    118|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|    118|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|    118|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (542:7): [True: 118, False: 0]
  ------------------
  543|    118|			return NULL;
  544|      0|		break;
  545|  17.5k|	}
  546|  15.2k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|  15.2k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (546:6): [True: 8.19k, False: 7.04k]
  ------------------
  547|  8.19k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  8.19k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (547:7): [True: 713, False: 7.47k]
  ------------------
  548|    713|			return NULL;
  549|  8.19k|	} else
  550|  7.04k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  7.04k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (550:7): [True: 478, False: 6.56k]
  ------------------
  551|    478|			return NULL;
  552|  14.0k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  14.0k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (552:6): [True: 2.20k, False: 11.8k]
  ------------------
  553|  2.20k|		return NULL;
  554|  11.8k|	len -= (p - *buf);	/* header size */
  555|  11.8k|	if (taglen > len) {
  ------------------
  |  Branch (555:6): [True: 0, False: 11.8k]
  ------------------
  556|      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__
  |  |  ------------------
  ------------------
  557|      0|				taglen, len);
  558|      0|		return NULL;
  559|      0|	}
  560|  11.8k|	*buflen -= (p - *buf) + taglen;
  561|  11.8k|	*buf = p + taglen;	/* point to next tag */
  562|  11.8k|	*taglen_out = taglen;
  563|  11.8k|	return p;
  564|  11.8k|}
sc_asn1_verify_tag:
  568|    820|{
  569|    820|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  570|    820|}
sc_asn1_decode_integer:
  729|  1.13k|{
  730|  1.13k|	int    a = 0, is_negative = 0;
  731|  1.13k|	size_t i = 0;
  732|       |
  733|  1.13k|	if (inlen == 0) {
  ------------------
  |  Branch (733:6): [True: 2, False: 1.13k]
  ------------------
  734|      2|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  735|      2|	}
  736|  1.13k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (736:6): [True: 4, False: 1.12k]
  ------------------
  737|      4|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      4|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  738|      4|	}
  739|  1.12k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (739:6): [True: 87, False: 1.03k]
  ------------------
  740|     87|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (740:7): [True: 0, False: 87]
  |  Branch (740:17): [True: 0, False: 0]
  |  Branch (740:30): [True: 0, False: 0]
  |  Branch (740:50): [True: 0, False: 0]
  ------------------
  741|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  742|      0|		}
  743|     87|		is_negative = 1;
  744|     87|		a |= 0xff^(*inbuf++);
  745|     87|		i = 1;
  746|  1.03k|	} else {
  747|  1.03k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (747:7): [True: 0, False: 1.03k]
  |  Branch (747:17): [True: 0, False: 0]
  |  Branch (747:30): [True: 0, False: 0]
  |  Branch (747:50): [True: 0, False: 0]
  ------------------
  748|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  749|      0|		}
  750|  1.03k|	}
  751|  2.38k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (751:9): [True: 1.25k, False: 1.12k]
  ------------------
  752|  1.25k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (752:7): [True: 0, False: 1.25k]
  |  Branch (752:29): [True: 0, False: 1.25k]
  ------------------
  753|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  754|      0|		}
  755|  1.25k|		a <<= 8;
  756|  1.25k|		if (is_negative) {
  ------------------
  |  Branch (756:7): [True: 41, False: 1.21k]
  ------------------
  757|     41|			a |= 0xff^(*inbuf++);
  758|  1.21k|		} else {
  759|  1.21k|			a |= *inbuf++;
  760|  1.21k|		}
  761|  1.25k|	}
  762|  1.12k|	if (is_negative) {
  ------------------
  |  Branch (762:6): [True: 87, False: 1.03k]
  ------------------
  763|       |		/* Calculate Two's complement from previously positive number */
  764|     87|		a = (-1 * a) - 1;
  765|     87|	}
  766|  1.12k|	*out = a;
  767|  1.12k|	return 0;
  768|  1.12k|}
sc_asn1_decode_object_id:
  829|  2.01k|{
  830|  2.01k|	int large_second_octet = 0;
  831|  2.01k|	unsigned int a = 0;
  832|  2.01k|	const u8 *p = inbuf;
  833|  2.01k|	int *octet;
  834|       |
  835|  2.01k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (835:6): [True: 11, False: 2.00k]
  |  Branch (835:20): [True: 0, False: 2.00k]
  |  Branch (835:37): [True: 0, False: 2.00k]
  ------------------
  836|     11|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     11|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  837|       |
  838|  2.00k|	sc_init_oid(id);
  839|  2.00k|	octet = id->value;
  840|       |
  841|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  842|  2.00k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   70|  2.00k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1.76k, False: 248]
  |  |  ------------------
  ------------------
  843|  2.00k|	*octet++ = a;
  844|       |
  845|       |	/* The second octet fits here if the previous was 0 or 1 and second one is smaller than 40.
  846|       |	 * for the value 2 we can go up to 47. Otherwise the first bit needs to be set
  847|       |	 * and we continue reading further */
  848|  2.00k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (848:6): [True: 1.95k, False: 55]
  ------------------
  849|  1.95k|		*octet++ = *p - (a * 40);
  850|  1.95k|		inlen--;
  851|  1.95k|	} else {
  852|     55|		large_second_octet = 1;
  853|     55|	}
  854|       |
  855|  12.2k|	while (inlen) {
  ------------------
  |  Branch (855:9): [True: 10.5k, False: 1.74k]
  ------------------
  856|  10.5k|		if (!large_second_octet)
  ------------------
  |  Branch (856:7): [True: 10.4k, False: 55]
  ------------------
  857|  10.4k|			p++;
  858|       |		/* This signalizes empty most significant bits, which means
  859|       |		 * the unsigned integer encoding is not minimal */
  860|  10.5k|		if (*p == 0x80) {
  ------------------
  |  Branch (860:7): [True: 14, False: 10.5k]
  ------------------
  861|     14|			sc_init_oid(id);
  862|     14|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     14|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  863|     14|		}
  864|       |		/* Use unsigned type here so we can process the whole INT range.
  865|       |		 * Values can not be negative */
  866|  10.5k|		a = *p & 0x7F;
  867|  10.5k|		inlen--;
  868|  14.3k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (868:10): [True: 12.6k, False: 1.78k]
  |  Branch (868:19): [True: 3.93k, False: 8.68k]
  ------------------
  869|       |			/* Limit the OID values to int size and do not overflow */
  870|  3.93k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (870:8): [True: 61, False: 3.87k]
  ------------------
  871|     61|				sc_init_oid(id);
  872|     61|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     61|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  873|     61|			}
  874|  3.87k|			p++;
  875|  3.87k|			a <<= 7;
  876|  3.87k|			a |= *p & 0x7F;
  877|  3.87k|			inlen--;
  878|  3.87k|		}
  879|  10.4k|		if (*p & 0x80) {
  ------------------
  |  Branch (879:7): [True: 57, False: 10.4k]
  ------------------
  880|       |			/* We dropped out from previous cycle on the end of
  881|       |			 * data while still expecting continuation of value */
  882|     57|			sc_init_oid(id);
  883|     57|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     57|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  884|     57|		}
  885|  10.4k|		if (large_second_octet) {
  ------------------
  |  Branch (885:7): [True: 55, False: 10.3k]
  ------------------
  886|     55|			a -= (2 * 40);
  887|     55|		}
  888|  10.4k|		if (a > INT_MAX) {
  ------------------
  |  Branch (888:7): [True: 1, False: 10.4k]
  ------------------
  889|      1|			sc_init_oid(id);
  890|      1|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  891|      1|		}
  892|  10.4k|		*octet++ = a;
  893|  10.4k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  10.4k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (893:7): [True: 133, False: 10.2k]
  ------------------
  894|    133|			sc_init_oid(id);
  895|    133|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    133|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  896|    133|		}
  897|  10.2k|		large_second_octet = 0;
  898|  10.2k|	}
  899|       |
  900|  1.74k|	return 0;
  901|  2.00k|}
sc_asn1_encode_object_id:
  905|  4.06k|{
  906|  4.06k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  907|  4.06k|	int	i;
  908|       |
  909|  4.06k|	if (!buflen || !id)
  ------------------
  |  Branch (909:6): [True: 0, False: 4.06k]
  |  Branch (909:17): [True: 0, False: 4.06k]
  ------------------
  910|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  911|       |
  912|       |	/* an OID must have at least two components */
  913|  4.06k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (913:6): [True: 0, False: 4.06k]
  |  Branch (913:28): [True: 0, False: 4.06k]
  ------------------
  914|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  915|       |
  916|  27.6k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  27.6k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (916:14): [True: 27.6k, False: 0]
  ------------------
  917|  27.6k|		unsigned int k, shift;
  918|       |
  919|  27.6k|		if (id->value[i] == -1)
  ------------------
  |  Branch (919:7): [True: 4.06k, False: 23.5k]
  ------------------
  920|  4.06k|			break;
  921|       |
  922|  23.5k|		k = id->value[i];
  923|  23.5k|		switch (i) {
  924|  4.06k|		case 0:
  ------------------
  |  Branch (924:3): [True: 4.06k, False: 19.4k]
  ------------------
  925|  4.06k|			if (k > 2)
  ------------------
  |  Branch (925:8): [True: 0, False: 4.06k]
  ------------------
  926|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  927|  4.06k|			*p = k * 40;
  928|  4.06k|			break;
  929|  4.06k|		case 1:
  ------------------
  |  Branch (929:3): [True: 4.06k, False: 19.4k]
  ------------------
  930|  4.06k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (930:8): [True: 0, False: 4.06k]
  |  Branch (930:18): [True: 0, False: 0]
  ------------------
  931|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|      0|			}
  933|       |			/* We can encode larger IDs to multiple bytes
  934|       |			 * similarly as the following IDs */
  935|  4.06k|			k += *p;
  936|       |			/* fall through */
  937|  19.4k|		default:
  ------------------
  |  Branch (937:3): [True: 15.3k, False: 8.13k]
  ------------------
  938|  19.4k|			shift = 28;
  939|  92.3k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (939:11): [True: 77.8k, False: 14.5k]
  |  Branch (939:20): [True: 72.8k, False: 4.96k]
  ------------------
  940|  72.8k|				shift -= 7;
  941|  24.4k|			while (shift) {
  ------------------
  |  Branch (941:11): [True: 4.99k, False: 19.4k]
  ------------------
  942|  4.99k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  943|  4.99k|				shift -= 7;
  944|  4.99k|			}
  945|  19.4k|			*p++ = k & 0x7F;
  946|  19.4k|			break;
  947|  23.5k|		}
  948|  23.5k|	}
  949|       |
  950|  4.06k|	*buflen = p - temp;
  951|       |
  952|  4.06k|	if (buf)   {
  ------------------
  |  Branch (952:6): [True: 4.06k, False: 0]
  ------------------
  953|  4.06k|		*buf = malloc(*buflen);
  954|  4.06k|		if (!*buf)
  ------------------
  |  Branch (954:7): [True: 0, False: 4.06k]
  ------------------
  955|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  956|  4.06k|		memcpy(*buf, temp, *buflen);
  957|  4.06k|	}
  958|  4.06k|	return 0;
  959|  4.06k|}
sc_asn1_put_tag:
  976|  24.7k|{
  977|  24.7k|	size_t c = 0;
  978|  24.7k|	unsigned int tag_len, ii;
  979|  24.7k|	u8 *p = out;
  980|  24.7k|	u8 tag_char[4] = {0, 0, 0, 0};
  981|       |
  982|       |	/* Check tag */
  983|  24.7k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (983:6): [True: 0, False: 24.7k]
  |  Branch (983:18): [True: 0, False: 24.7k]
  ------------------
  984|       |		/* A tag of 0x00 is not valid and at most 4-byte tag names are supported. */
  985|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  986|      0|	}
  987|  49.4k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (987:20): [True: 24.7k, False: 24.7k]
  ------------------
  988|       |		/* Note: tag char will be reversed order. */
  989|  24.7k|		tag_char[tag_len++] = tag & 0xFF;
  990|  24.7k|	}
  991|       |
  992|  24.7k|	if (tag_len > 1)   {
  ------------------
  |  Branch (992:6): [True: 0, False: 24.7k]
  ------------------
  993|      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 (993:7): [True: 0, False: 0]
  ------------------
  994|       |			/* First byte is not escape marker. */
  995|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  996|      0|		}
  997|      0|		for (ii = 1; ii < tag_len - 1; ii++) {
  ------------------
  |  Branch (997:16): [True: 0, False: 0]
  ------------------
  998|      0|			if ((tag_char[ii] & 0x80) != 0x80) {
  ------------------
  |  Branch (998:8): [True: 0, False: 0]
  ------------------
  999|       |				/* MS bit is not 'one'. */
 1000|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1001|      0|			}
 1002|      0|		}
 1003|      0|		if ((tag_char[0] & 0x80) != 0x00) {
  ------------------
  |  Branch (1003:7): [True: 0, False: 0]
  ------------------
 1004|       |			/* MS bit of the last byte is not 'zero'. */
 1005|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1006|      0|		}
 1007|      0|	}
 1008|       |
 1009|       |	/* Calculate the number of additional bytes necessary to encode the length. */
 1010|       |	/* c+1 is the size of the length field. */
 1011|  24.7k|	if (datalen > 127) {
  ------------------
  |  Branch (1011:6): [True: 0, False: 24.7k]
  ------------------
 1012|      0|		c = 1;
 1013|      0|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1013:10): [True: 0, False: 0]
  ------------------
 1014|      0|			c++;
 1015|      0|	}
 1016|  24.7k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1016:6): [True: 0, False: 24.7k]
  |  Branch (1016:21): [True: 0, False: 24.7k]
  ------------------
 1017|       |		/* Caller only asks for the length that would be written. */
 1018|      0|		return (int)(tag_len + (c + 1) + datalen);
 1019|      0|	}
 1020|       |	/* We will write the tag, so check the length. */
 1021|  24.7k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1021:6): [True: 0, False: 24.7k]
  ------------------
 1022|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1023|  49.4k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1023:12): [True: 24.7k, False: 24.7k]
  ------------------
 1024|  24.7k|		*p++ = tag_char[tag_len - ii - 1];
 1025|       |
 1026|  24.7k|	if (c > 0) {
  ------------------
  |  Branch (1026:6): [True: 0, False: 24.7k]
  ------------------
 1027|      0|		*p++ = 0x80 | c;
 1028|      0|		while (c--)
  ------------------
  |  Branch (1028:10): [True: 0, False: 0]
  ------------------
 1029|      0|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1030|      0|	}
 1031|  24.7k|	else {
 1032|  24.7k|		*p++ = datalen & 0x7F;
 1033|  24.7k|	}
 1034|  24.7k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1034:5): [True: 24.7k, False: 0]
  |  Branch (1034:13): [True: 24.7k, False: 0]
  ------------------
 1035|  24.7k|		memcpy(p, data, datalen);
 1036|  24.7k|		p += datalen;
 1037|  24.7k|	}
 1038|  24.7k|	if (ptr != NULL)
  ------------------
  |  Branch (1038:6): [True: 24.7k, False: 0]
  ------------------
 1039|  24.7k|		*ptr = p;
 1040|  24.7k|	return 0;
 1041|  24.7k|}
sc_asn1_decode:
 1814|  6.43k|{
 1815|  6.43k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1816|  6.43k|}
sc_asn1_decode_choice:
 1820|    683|{
 1821|    683|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1822|    683|}
sc_asn1_encode:
 2082|  3.04k|{
 2083|  3.04k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2084|  3.04k|}
_sc_asn1_encode:
 2088|  4.06k|{
 2089|  4.06k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2090|  4.06k|}
_sc_asn1_decode:
 2096|    691|{
 2097|    691|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2098|    691|}
sc_der_copy:
 2102|  2.02k|{
 2103|  2.02k|	if (!dst || !src)
  ------------------
  |  Branch (2103:6): [True: 0, False: 2.02k]
  |  Branch (2103:14): [True: 0, False: 2.02k]
  ------------------
 2104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2105|  2.02k|	memset(dst, 0, sizeof(*dst));
 2106|  2.02k|	if (src->len) {
  ------------------
  |  Branch (2106:6): [True: 1.96k, False: 62]
  ------------------
 2107|  1.96k|		if (!src->value)
  ------------------
  |  Branch (2107:7): [True: 0, False: 1.96k]
  ------------------
 2108|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2109|  1.96k|		dst->value = malloc(src->len);
 2110|  1.96k|		if (!dst->value)
  ------------------
  |  Branch (2110:7): [True: 0, False: 1.96k]
  ------------------
 2111|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2112|  1.96k|		dst->len = src->len;
 2113|  1.96k|		memcpy(dst->value, src->value, src->len);
 2114|  1.96k|	}
 2115|  2.02k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.02k|#define SC_SUCCESS				0
  ------------------
 2116|  2.02k|}
sc_encode_oid:
 2121|  3.92k|{
 2122|  3.92k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2123|  3.92k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  3.92k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  3.92k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.92k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2124|  3.92k|		{ NULL, 0, 0, 0, NULL, NULL }
 2125|  3.92k|	};
 2126|  3.92k|	struct sc_asn1_entry asn1_object_id[2];
 2127|  3.92k|	int rv;
 2128|       |
 2129|  3.92k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2130|  3.92k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2131|       |
 2132|  3.92k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2133|  3.92k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|  3.92k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.92k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.92k|	int _ret = (r); \
  |  |  |  |  168|  3.92k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 3.92k]
  |  |  |  |  ------------------
  |  |  |  |  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.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.92k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|  3.92k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.92k|#define SC_SUCCESS				0
  ------------------
 2136|  3.92k|}
asn1.c:decode_bit_string:
  574|    697|{
  575|    697|	const u8 *in = inbuf;
  576|    697|	u8 *out = (u8 *) outbuf;
  577|    697|	int i, count = 0;
  578|    697|	int zero_bits;
  579|    697|	size_t octets_left;
  580|       |
  581|    697|	if (inlen < 1)
  ------------------
  |  Branch (581:6): [True: 1, False: 696]
  ------------------
  582|      1|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  583|       |
  584|       |	/* The formatting is only enforced by SHALL keyword so we should accept
  585|       |	 * by default also non-strict values. */
  586|    696|	if (strict) {
  ------------------
  |  Branch (586:6): [True: 0, False: 696]
  ------------------
  587|       |		/* 8.6.2.3 If the bitstring is empty, there shall be no
  588|       |		 * subsequent octets,and the initial octet shall be zero. */
  589|      0|		if (inlen == 1 && *in != 0)
  ------------------
  |  Branch (589:7): [True: 0, False: 0]
  |  Branch (589:21): [True: 0, False: 0]
  ------------------
  590|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  591|       |		/* ITU-T Rec. X.690 8.6.2.2: The number shall be in the range zero to seven. */
  592|      0|		if ((*in & ~0x07) != 0)
  ------------------
  |  Branch (592:7): [True: 0, False: 0]
  ------------------
  593|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  594|      0|	}
  595|       |
  596|    696|	memset(outbuf, 0, outlen);
  597|    696|	zero_bits = *in & 0x07;
  598|    696|	in++;
  599|    696|	octets_left = inlen - 1;
  600|    696|	if (outlen < octets_left)
  ------------------
  |  Branch (600:6): [True: 1, False: 695]
  ------------------
  601|      1|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  602|       |
  603|  37.4k|	while (octets_left) {
  ------------------
  |  Branch (603:9): [True: 36.7k, False: 690]
  ------------------
  604|       |		/* 1st octet of input:  ABCDEFGH, where A is the MSB */
  605|       |		/* 1st octet of output: HGFEDCBA, where A is the LSB */
  606|       |		/* first bit in bit string is the LSB in first resulting octet */
  607|  36.7k|		int bits_to_go;
  608|       |
  609|  36.7k|		*out = 0;
  610|  36.7k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (610:7): [True: 688, False: 36.0k]
  |  Branch (610:27): [True: 377, False: 311]
  ------------------
  611|    377|			bits_to_go = 8 - zero_bits;
  612|       |			/* Verify the padding is zero bits */
  613|    377|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (613:8): [True: 5, False: 372]
  ------------------
  614|      5|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  615|      5|			}
  616|    377|		} else
  617|  36.3k|			bits_to_go = 8;
  618|  36.7k|		if (invert)
  ------------------
  |  Branch (618:7): [True: 351, False: 36.3k]
  ------------------
  619|  2.21k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (619:16): [True: 1.85k, False: 351]
  ------------------
  620|  1.85k|				*out |= ((*in >> (7 - i)) & 1) << i;
  621|  1.85k|			}
  622|  36.3k|		else {
  623|  36.3k|			*out = *in;
  624|  36.3k|		}
  625|  36.7k|		out++;
  626|  36.7k|		in++;
  627|  36.7k|		octets_left--;
  628|  36.7k|		count++;
  629|  36.7k|	}
  630|    690|	return (count * 8) - zero_bits;
  631|    695|}
asn1.c:asn1_write_element:
 1051|  7.50k|{
 1052|  7.50k|	unsigned char t;
 1053|  7.50k|	unsigned char *buf, *p;
 1054|  7.50k|	int c = 0;
 1055|  7.50k|	unsigned short_tag;
 1056|  7.50k|	unsigned char tag_char[3] = {0, 0, 0};
 1057|  7.50k|	size_t tag_len, ii;
 1058|       |
 1059|  7.50k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|  7.50k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1060|  15.0k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1060:20): [True: 7.50k, False: 7.50k]
  ------------------
 1061|  7.50k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1062|  7.50k|	if (!tag_len)
  ------------------
  |  Branch (1062:6): [True: 0, False: 7.50k]
  ------------------
 1063|      0|		tag_len = 1;
 1064|       |
 1065|  7.50k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1065:6): [True: 0, False: 7.50k]
  ------------------
 1066|      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 (1066:7): [True: 0, False: 0]
  ------------------
 1067|      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]
  |  |  ------------------
  ------------------
 1068|       |
 1069|      0|		for (ii = 1; ii < tag_len - 1; ii++)
  ------------------
  |  Branch (1069:16): [True: 0, False: 0]
  ------------------
 1070|      0|			if (!(tag_char[ii] & 0x80))
  ------------------
  |  Branch (1070:8): [True: 0, False: 0]
  ------------------
 1071|      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]
  |  |  ------------------
  ------------------
 1072|       |
 1073|      0|		if (tag_char[0] & 0x80)
  ------------------
  |  Branch (1073:7): [True: 0, False: 0]
  ------------------
 1074|      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]
  |  |  ------------------
  ------------------
 1075|      0|	}
 1076|       |
 1077|  7.50k|	t = tag_char[tag_len - 1] & 0x1F;
 1078|       |
 1079|  7.50k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|  7.50k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1079:10): [True: 7.50k, False: 0]
  ------------------
 1080|  5.46k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|  5.46k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1080:2): [True: 5.46k, False: 2.03k]
  ------------------
 1081|  5.46k|		break;
 1082|  2.03k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  2.03k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1082:2): [True: 2.03k, False: 5.46k]
  ------------------
 1083|  2.03k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  2.03k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1084|  2.03k|		break;
 1085|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  139|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1085:2): [True: 0, False: 7.50k]
  ------------------
 1086|      0|		t |= SC_ASN1_TAG_CONTEXT;
  ------------------
  |  |  187|      0|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
 1087|      0|		break;
 1088|      0|	case SC_ASN1_PRV:
  ------------------
  |  |  140|      0|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (1088:2): [True: 0, False: 7.50k]
  ------------------
 1089|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1090|      0|		break;
 1091|  7.50k|	}
 1092|  7.50k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|  7.50k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1092:6): [True: 874, False: 6.62k]
  ------------------
 1093|    874|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|    874|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1094|  7.50k|	if (datalen > 127) {
  ------------------
  |  Branch (1094:6): [True: 132, False: 7.36k]
  ------------------
 1095|    132|		c = 1;
 1096|    256|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1096:10): [True: 124, False: 132]
  ------------------
 1097|    124|			c++;
 1098|    132|	}
 1099|       |
 1100|  7.50k|	*outlen = tag_len + 1 + c + datalen;
 1101|  7.50k|	buf = malloc(*outlen);
 1102|  7.50k|	if (buf == NULL)
  ------------------
  |  Branch (1102:6): [True: 0, False: 7.50k]
  ------------------
 1103|      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]
  |  |  ------------------
  ------------------
 1104|       |
 1105|  7.50k|	*out = p = buf;
 1106|  7.50k|	*p++ = t;
 1107|  7.50k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1107:12): [True: 0, False: 7.50k]
  ------------------
 1108|      0|		*p++ = tag_char[tag_len - ii - 1];
 1109|       |
 1110|  7.50k|	if (c) {
  ------------------
  |  Branch (1110:6): [True: 132, False: 7.36k]
  ------------------
 1111|    132|		*p++ = 0x80 | c;
 1112|    388|		while (c--)
  ------------------
  |  Branch (1112:10): [True: 256, False: 132]
  ------------------
 1113|    256|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1114|    132|	}
 1115|  7.36k|	else   {
 1116|  7.36k|		*p++ = datalen & 0x7F;
 1117|  7.36k|	}
 1118|  7.50k|	if (datalen && data) {
  ------------------
  |  Branch (1118:6): [True: 7.46k, False: 32]
  |  Branch (1118:17): [True: 7.46k, False: 0]
  ------------------
 1119|  7.46k|		memcpy(p, data, datalen);
 1120|  7.46k|	}
 1121|       |
 1122|  7.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.50k|#define SC_SUCCESS				0
  ------------------
 1123|  7.50k|}
asn1.c:asn1_decode:
 1723|  10.4k|{
 1724|  10.4k|	int r, idx = 0;
 1725|  10.4k|	const u8 *p = in, *obj;
 1726|  10.4k|	struct sc_asn1_entry *entry = asn1;
 1727|  10.4k|	size_t left = len, objlen;
 1728|       |
 1729|  10.4k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*s""called, left=%zu, depth %d%s",
  ------------------
  |  |   70|  20.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: 895, False: 9.54k]
  |  |  ------------------
  ------------------
 1730|  10.4k|			depth, depth, "", left, depth, choice ? ", choice" : "");
 1731|       |
 1732|  10.4k|	if (!p)
  ------------------
  |  Branch (1732:6): [True: 0, False: 10.4k]
  ------------------
 1733|      0|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      0|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1734|  10.4k|	if (left < 2) {
  ------------------
  |  Branch (1734:6): [True: 540, False: 9.89k]
  ------------------
 1735|  1.01k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|    953|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1735:10): [True: 953, False: 58]
  |  Branch (1735:24): [True: 471, False: 482]
  ------------------
 1736|    471|			asn1++;
 1737|       |		/* If all elements were optional, there's nothing
 1738|       |		 * to complain about */
 1739|    540|		if (asn1->name == NULL)
  ------------------
  |  Branch (1739:7): [True: 58, False: 482]
  ------------------
 1740|     58|			return 0;
 1741|    482|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    482|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1742|    482|			      "non-optional field \"%s\" not found\n",
 1743|    482|			      asn1->name);
 1744|    482|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    482|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1745|    540|	}
 1746|  9.89k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1746:6): [True: 920, False: 8.97k]
  |  Branch (1746:19): [True: 211, False: 8.76k]
  |  Branch (1746:35): [True: 0, False: 8.76k]
  ------------------
 1747|  1.13k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.13k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1748|       |
 1749|  29.0k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1749:16): [True: 23.5k, False: 5.47k]
  ------------------
 1750|  23.5k|		entry = &asn1[idx];
 1751|       |
 1752|  23.5k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|  23.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)
  |  |  ------------------
  |  |  |  | 1753|  23.5k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1754|  23.5k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  23.5k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1753|  23.5k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1754|  23.5k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1755|       |
 1756|       |		/* Special case CHOICE has no tag */
 1757|  23.5k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  23.5k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1757:7): [True: 212, False: 23.3k]
  ------------------
 1758|    212|			r = asn1_decode(ctx,
 1759|    212|				(struct sc_asn1_entry *) entry->parm,
 1760|    212|				p, left, &p, &left, 1, depth + 1);
 1761|       |			/* When the inner call fails it returns before writing
 1762|       |			 * back to *newp and *len_left, so the caller's p/left are
 1763|       |			 * unchanged.  Swallowing the error for an optional
 1764|       |			 * CHOICE is therefore safe: the next field will be
 1765|       |			 * attempted at the same position. */
 1766|    212|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|     26|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1766:8): [True: 186, False: 26]
  |  Branch (1766:18): [True: 12, False: 14]
  ------------------
 1767|    198|				r = 0;
 1768|    212|			goto decode_ok;
 1769|    212|		}
 1770|       |
 1771|  23.3k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1772|  23.3k|		if (obj == NULL) {
  ------------------
  |  Branch (1772:7): [True: 12.5k, False: 10.8k]
  ------------------
 1773|  12.5k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  12.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1774|  12.5k|			if (choice)
  ------------------
  |  Branch (1774:8): [True: 1.64k, False: 10.8k]
  ------------------
 1775|  1.64k|				continue;
 1776|  10.8k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  10.8k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1776:8): [True: 8.86k, False: 2.02k]
  ------------------
 1777|  8.86k|				continue;
 1778|  2.02k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  2.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1779|  2.02k|			if (left) {
  ------------------
  |  Branch (1779:8): [True: 2.02k, False: 7]
  ------------------
 1780|  2.02k|				u8 line[128], *linep = line;
 1781|  2.02k|				size_t i;
 1782|       |
 1783|  2.02k|				line[0] = 0;
 1784|  19.5k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1784:17): [True: 18.0k, False: 1.54k]
  |  Branch (1784:27): [True: 17.5k, False: 478]
  ------------------
 1785|  17.5k|					sprintf((char *) linep, "%02X ", p[i]);
 1786|  17.5k|					linep += 3;
 1787|  17.5k|				}
 1788|  2.02k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  2.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1789|  2.02k|			}
 1790|  2.02k|			sc_free_entry(asn1);
 1791|  2.02k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  2.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.02k|	int _ret = r; \
  |  |  155|  2.02k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.02k, False: 0]
  |  |  ------------------
  |  |  156|  2.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|  2.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.02k, False: 0]
  |  |  ------------------
  |  |  157|  2.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.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|  2.02k|	return _ret; \
  |  |  163|  2.02k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1792|  2.02k|		}
 1793|  10.8k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1794|       |
 1795|  11.0k|decode_ok:
 1796|  11.0k|		if (r)
  ------------------
  |  Branch (1796:7): [True: 533, False: 10.5k]
  ------------------
 1797|    533|			return r;
 1798|  10.5k|		if (choice)
  ------------------
  |  Branch (1798:7): [True: 729, False: 9.78k]
  ------------------
 1799|    729|			break;
 1800|  10.5k| 	}
 1801|  6.20k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1801:7): [True: 788, False: 5.41k]
  |  Branch (1801:17): [True: 59, False: 729]
  ------------------
 1802|     59|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  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|     59|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 59, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1803|  6.14k| 	if (newp != NULL)
  ------------------
  |  Branch (1803:7): [True: 1.37k, False: 4.77k]
  ------------------
 1804|  1.37k|		*newp = p;
 1805|  6.14k| 	if (len_left != NULL)
  ------------------
  |  Branch (1805:7): [True: 1.37k, False: 4.77k]
  ------------------
 1806|  1.37k|		*len_left = left;
 1807|  6.14k|	if (choice)
  ------------------
  |  Branch (1807:6): [True: 729, False: 5.41k]
  ------------------
 1808|    729|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|    729|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    729|	int _ret = r; \
  |  |  155|    729|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 257, False: 472]
  |  |  ------------------
  |  |  156|    257|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 257]
  |  |  ------------------
  |  |  157|    257|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    472|	} else { \
  |  |  159|    472|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    472|			"returning with: %d\n", _ret); \
  |  |  161|    472|	} \
  |  |  162|    729|	return _ret; \
  |  |  163|    729|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1809|  5.41k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  5.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  5.41k|	int _ret = r; \
  |  |  155|  5.41k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5.41k, False: 0]
  |  |  ------------------
  |  |  156|  5.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 5.41k]
  |  |  ------------------
  |  |  157|  5.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.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|  5.41k|	return _ret; \
  |  |  163|  5.41k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1810|  5.41k|}
asn1.c:sc_free_entry:
 1688|  11.3k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1689|  11.3k|	int idx = 0;
 1690|  11.3k|	struct sc_asn1_entry *entry = asn1;
 1691|       |
 1692|  11.3k|	if (!asn1)
  ------------------
  |  Branch (1692:6): [True: 320, False: 11.0k]
  ------------------
 1693|    320|		return;
 1694|       |
 1695|  54.6k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1695:16): [True: 43.6k, False: 11.0k]
  ------------------
 1696|  43.6k|		entry = &asn1[idx];
 1697|  43.6k|		switch (entry->type) {
 1698|  3.53k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  3.53k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1698:3): [True: 3.53k, False: 40.1k]
  ------------------
 1699|  9.30k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  9.30k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1699:3): [True: 5.77k, False: 37.8k]
  ------------------
 1700|  9.30k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1701|  9.30k|			break;
 1702|  5.57k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  5.57k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1702:3): [True: 5.57k, False: 38.0k]
  ------------------
 1703|  5.61k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  5.61k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1703:3): [True: 36, False: 43.6k]
  ------------------
 1704|  5.63k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  5.63k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1704:3): [True: 20, False: 43.6k]
  ------------------
 1705|  5.85k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  5.85k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1705:3): [True: 220, False: 43.4k]
  ------------------
 1706|  6.11k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  6.11k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1706:3): [True: 257, False: 43.3k]
  ------------------
 1707|  7.89k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  7.89k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1707:3): [True: 1.78k, False: 41.8k]
  ------------------
 1708|  7.89k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  7.89k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    380|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1708:8): [True: 380, False: 7.51k]
  |  Branch (1708:42): [True: 67, False: 313]
  ------------------
 1709|     67|				u8 **buf = (u8 **)entry->parm;
 1710|     67|				free(*buf);
 1711|     67|				*buf = NULL;
 1712|     67|			}
 1713|  7.89k|			break;
 1714|  26.4k|		default:
  ------------------
  |  Branch (1714:3): [True: 26.4k, False: 17.2k]
  ------------------
 1715|  26.4k|			break;
 1716|  43.6k|		}
 1717|  43.6k|	}
 1718|  11.0k|}
asn1.c:asn1_decode_entry:
 1486|  10.8k|{
 1487|  10.8k|	void *parm = entry->parm;
 1488|  10.8k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1489|  10.8k|			     size_t nobjlen, int ndepth);
 1490|  10.8k|	size_t *len = (size_t *) entry->arg;
 1491|  10.8k|	int r = 0;
 1492|       |
 1493|  10.8k|	callback_func = parm;
 1494|       |
 1495|  10.8k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|  43.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:115): [True: 3.58k, False: 7.25k]
  |  |  |  Branch (70:115): [True: 3.58k, False: 7.25k]
  |  |  ------------------
  ------------------
 1496|  10.8k|		depth, depth, "", entry->name,
 1497|  10.8k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1498|  10.8k|		objlen > 16 ? "..." : "");
 1499|       |
 1500|  10.8k|	switch (entry->type) {
 1501|  2.88k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  2.88k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1501:2): [True: 2.88k, False: 7.95k]
  ------------------
 1502|  2.88k|		if (parm != NULL)
  ------------------
  |  Branch (1502:7): [True: 2.01k, False: 872]
  ------------------
 1503|  2.01k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1504|  2.01k|				       objlen, NULL, NULL, 0, depth + 1);
 1505|  2.88k|		break;
 1506|    335|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    335|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1506:2): [True: 335, False: 10.5k]
  ------------------
 1507|    335|		break;
 1508|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1508:2): [True: 0, False: 10.8k]
  ------------------
 1509|      0|		if (parm != NULL) {
  ------------------
  |  Branch (1509:7): [True: 0, False: 0]
  ------------------
 1510|      0|			if (objlen != 1) {
  ------------------
  |  Branch (1510:8): [True: 0, False: 0]
  ------------------
 1511|      0|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 object length: %zu", objlen);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1512|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1513|      0|			} else
 1514|      0|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1514:23): [True: 0, False: 0]
  ------------------
 1515|      0|		}
 1516|      0|		break;
 1517|  1.13k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  1.13k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1517:2): [True: 1.13k, False: 9.70k]
  ------------------
 1518|  1.13k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  1.13k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1518:2): [True: 0, False: 10.8k]
  ------------------
 1519|  1.13k|		if (parm != NULL) {
  ------------------
  |  Branch (1519:7): [True: 1.13k, False: 0]
  ------------------
 1520|  1.13k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1521|  1.13k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.13k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1521:8): [True: 1.12k, False: 6]
  ------------------
 1522|  1.12k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  1.12k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1523|  1.12k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1524|  1.12k|			}
 1525|  1.13k|		}
 1526|  1.13k|		break;
 1527|    358|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    358|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1527:2): [True: 358, False: 10.4k]
  ------------------
 1528|    632|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    632|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1528:2): [True: 274, False: 10.5k]
  ------------------
 1529|    632|		if (parm != NULL) {
  ------------------
  |  Branch (1529:7): [True: 358, False: 274]
  ------------------
 1530|    358|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|    358|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1530:17): [True: 0, False: 358]
  ------------------
 1531|    358|			if (len == NULL)
  ------------------
  |  Branch (1531:8): [True: 0, False: 358]
  ------------------
 1532|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1533|    358|			if (objlen < 1) {
  ------------------
  |  Branch (1533:8): [True: 3, False: 355]
  ------------------
 1534|      3|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1535|      3|				break;
 1536|      3|			}
 1537|    355|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    355|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1537:8): [True: 355, False: 0]
  ------------------
 1538|    355|				u8 **buf = (u8 **) parm;
 1539|    355|				if (objlen > 1) {
  ------------------
  |  Branch (1539:9): [True: 351, False: 4]
  ------------------
 1540|    351|					*buf = malloc(objlen-1);
 1541|    351|					if (*buf == NULL) {
  ------------------
  |  Branch (1541:10): [True: 0, False: 351]
  ------------------
 1542|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1543|      0|						break;
 1544|      0|					}
 1545|    351|				} else {
 1546|      4|					*buf = NULL;
 1547|      4|				}
 1548|    355|				*len = objlen-1;
 1549|    355|				parm = *buf;
 1550|    355|			}
 1551|    355|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1552|    355|			if (r >= 0) {
  ------------------
  |  Branch (1552:8): [True: 348, False: 7]
  ------------------
 1553|    348|				*len = r;
 1554|    348|				r = 0;
 1555|    348|			}
 1556|    355|		}
 1557|    629|		break;
 1558|    629|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|    342|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1558:2): [True: 342, False: 10.4k]
  ------------------
 1559|    342|		if (parm != NULL)
  ------------------
  |  Branch (1559:7): [True: 342, False: 0]
  ------------------
 1560|    342|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1561|    342|		break;
 1562|  2.55k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  2.55k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1562:2): [True: 2.55k, False: 8.28k]
  ------------------
 1563|  2.55k|		if (parm != NULL) {
  ------------------
  |  Branch (1563:7): [True: 2.53k, False: 19]
  ------------------
 1564|  2.53k|			size_t c;
 1565|  2.53k|			if (len == NULL)
  ------------------
  |  Branch (1565:8): [True: 0, False: 2.53k]
  ------------------
 1566|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1567|       |
 1568|       |			/* Strip off padding zero */
 1569|  2.53k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  2.53k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1569:8): [True: 181, False: 2.35k]
  ------------------
 1570|    181|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1570:9): [True: 169, False: 12]
  |  Branch (1570:23): [True: 49, False: 120]
  ------------------
 1571|     49|				objlen--;
 1572|     49|				obj++;
 1573|     49|			}
 1574|       |
 1575|       |			/* Allocate buffer if needed */
 1576|  2.53k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  2.53k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1576:8): [True: 1.48k, False: 1.04k]
  ------------------
 1577|  1.48k|				u8 **buf = (u8 **) parm;
 1578|  1.48k|				if (objlen > 0) {
  ------------------
  |  Branch (1578:9): [True: 1.47k, False: 9]
  ------------------
 1579|  1.47k|					*buf = malloc(objlen);
 1580|  1.47k|					if (*buf == NULL) {
  ------------------
  |  Branch (1580:10): [True: 0, False: 1.47k]
  ------------------
 1581|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1582|      0|						break;
 1583|      0|					}
 1584|  1.47k|				} else {
 1585|      9|					*buf = NULL;
 1586|      9|				}
 1587|  1.48k|				c = *len = objlen;
 1588|  1.48k|				parm = *buf;
 1589|  1.48k|			} else
 1590|  1.04k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1590:9): [True: 227, False: 820]
  ------------------
 1591|       |
 1592|  2.53k|			memcpy(parm, obj, c);
 1593|  2.53k|			*len = c;
 1594|  2.53k|		}
 1595|  2.55k|		break;
 1596|  2.55k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      7|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1596:2): [True: 7, False: 10.8k]
  ------------------
 1597|      7|		if (parm != NULL) {
  ------------------
  |  Branch (1597:7): [True: 7, False: 0]
  ------------------
 1598|      7|			size_t c;
 1599|      7|			if (len == NULL)
  ------------------
  |  Branch (1599:8): [True: 0, False: 7]
  ------------------
 1600|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1601|      7|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|      7|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1601:8): [True: 0, False: 7]
  ------------------
 1602|      0|				u8 **buf = (u8 **) parm;
 1603|      0|				if (objlen > 0) {
  ------------------
  |  Branch (1603:9): [True: 0, False: 0]
  ------------------
 1604|      0|					*buf = malloc(objlen);
 1605|      0|					if (*buf == NULL) {
  ------------------
  |  Branch (1605:10): [True: 0, False: 0]
  ------------------
 1606|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1607|      0|						break;
 1608|      0|					}
 1609|      0|				} else {
 1610|      0|					*buf = NULL;
 1611|      0|				}
 1612|      0|				c = *len = objlen;
 1613|      0|				parm = *buf;
 1614|      0|			} else
 1615|      7|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1615:9): [True: 0, False: 7]
  ------------------
 1616|       |
 1617|      7|			memcpy(parm, obj, c);
 1618|      7|			*len = c;
 1619|      7|		}
 1620|      7|		break;
 1621|  1.09k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  1.09k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1621:2): [True: 1.09k, False: 9.74k]
  ------------------
 1622|  1.09k|		if (parm != NULL)
  ------------------
  |  Branch (1622:7): [True: 1.08k, False: 4]
  ------------------
 1623|  1.08k|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1624|  1.09k|		break;
 1625|      2|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      2|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1625:2): [True: 2, False: 10.8k]
  ------------------
 1626|    366|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|    366|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1626:2): [True: 364, False: 10.4k]
  ------------------
 1627|    366|		if (parm != NULL) {
  ------------------
  |  Branch (1627:7): [True: 363, False: 3]
  ------------------
 1628|    363|			if (len == NULL)
  ------------------
  |  Branch (1628:8): [True: 0, False: 363]
  ------------------
 1629|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1630|    363|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    363|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1630:8): [True: 0, False: 363]
  ------------------
 1631|      0|				u8 **buf = (u8 **) parm;
 1632|      0|				*buf = malloc(objlen+1);
 1633|      0|				if (*buf == NULL) {
  ------------------
  |  Branch (1633:9): [True: 0, False: 0]
  ------------------
 1634|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1635|      0|					break;
 1636|      0|				}
 1637|      0|				*len = objlen+1;
 1638|      0|				parm = *buf;
 1639|      0|			}
 1640|    363|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1641|    363|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    363|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1641:8): [True: 0, False: 363]
  ------------------
 1642|      0|				*len -= 1;
 1643|      0|			}
 1644|    363|		}
 1645|    366|		break;
 1646|    366|	case SC_ASN1_PATH:
  ------------------
  |  |  174|    317|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1646:2): [True: 317, False: 10.5k]
  ------------------
 1647|    317|		if (entry->parm != NULL)
  ------------------
  |  Branch (1647:7): [True: 317, False: 0]
  ------------------
 1648|    317|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1649|    317|		break;
 1650|      1|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|      1|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1650:2): [True: 1, False: 10.8k]
  ------------------
 1651|      1|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1651:7): [True: 1, False: 0]
  ------------------
 1652|      1|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1653|      1|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1653:15): [True: 0, False: 1]
  ------------------
 1654|       |
 1655|      1|			memcpy(id->value, obj, c);
 1656|      1|			id->len = c;
 1657|      1|		}
 1658|      1|		break;
 1659|     44|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|     44|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1659:2): [True: 44, False: 10.7k]
  ------------------
 1660|     44|		if (entry->parm != NULL)
  ------------------
  |  Branch (1660:7): [True: 43, False: 1]
  ------------------
 1661|     43|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1662|     44|		break;
 1663|    691|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    691|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1663:2): [True: 691, False: 10.1k]
  ------------------
 1664|    691|		if (entry->parm != NULL)
  ------------------
  |  Branch (1664:7): [True: 691, False: 0]
  ------------------
 1665|    691|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1666|    691|		break;
 1667|     18|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|     18|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1667:2): [True: 18, False: 10.8k]
  ------------------
 1668|     18|		if (entry->parm != NULL)
  ------------------
  |  Branch (1668:7): [True: 18, False: 0]
  ------------------
 1669|     18|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1670|     18|		break;
 1671|    421|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|    421|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1671:2): [True: 421, False: 10.4k]
  ------------------
 1672|    421|		if (entry->parm != NULL)
  ------------------
  |  Branch (1672:7): [True: 421, False: 0]
  ------------------
 1673|    421|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1674|    421|		break;
 1675|      0|	default:
  ------------------
  |  Branch (1675:2): [True: 0, False: 10.8k]
  ------------------
 1676|      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__
  |  |  ------------------
  ------------------
 1677|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1678|  10.8k|	}
 1679|  10.8k|	if (r) {
  ------------------
  |  Branch (1679:6): [True: 519, False: 10.3k]
  ------------------
 1680|    519|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|    519|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1681|    519|		      sc_strerror(r));
 1682|    519|		return r;
 1683|    519|	}
 1684|  10.3k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  10.3k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1685|  10.3k|	return 0;
 1686|  10.8k|}
asn1.c:decode_bit_field:
  687|    342|{
  688|    342|	u8		data[sizeof(unsigned int)];
  689|    342|	unsigned int	field = 0;
  690|    342|	int		i, n;
  691|       |
  692|    342|	if (outlen != sizeof(data))
  ------------------
  |  Branch (692:6): [True: 0, False: 342]
  ------------------
  693|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  694|       |
  695|    342|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  696|    342|	if (n < 0)
  ------------------
  |  Branch (696:6): [True: 6, False: 336]
  ------------------
  697|      6|		return n;
  698|       |
  699|    687|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (699:14): [True: 351, False: 336]
  ------------------
  700|    351|		field |= ((unsigned int) data[i/8] << i);
  701|    351|	}
  702|    336|	memcpy(outbuf, &field, outlen);
  703|    336|	return 0;
  704|    342|}
asn1.c:sc_asn1_decode_utf8string:
  963|    363|{
  964|    363|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (964:6): [True: 1, False: 362]
  ------------------
  965|      1|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  966|    362|	*outlen = inlen+1;
  967|    362|	memcpy(out, inbuf, inlen);
  968|    362|	out[inlen] = 0;
  969|    362|	return 0;
  970|    363|}
asn1.c:asn1_decode_path:
 1145|    317|{
 1146|    317|	int idx, count, r;
 1147|    317|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1148|    317|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1149|    317|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1150|       |
 1151|    317|	memset(path, 0, sizeof(struct sc_path));
 1152|       |
 1153|    317|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1154|    317|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1155|       |
 1156|    317|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1157|    317|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1158|       |
 1159|    317|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1160|    317|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1161|    317|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1162|    317|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1163|       |
 1164|    317|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1165|    317|	if (r)
  ------------------
  |  Branch (1165:6): [True: 10, False: 307]
  ------------------
 1166|     10|		return r;
 1167|       |
 1168|    307|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    307|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1168:6): [True: 0, False: 307]
  ------------------
 1169|       |		/* extended path present: set 'path' and 'aid' */
 1170|      0|		memcpy(path->aid.value, aid_value, aid_len);
 1171|      0|		path->aid.len = aid_len;
 1172|       |
 1173|      0|		memcpy(path->value, path_value, path_len);
 1174|      0|		path->len = path_len;
 1175|      0|	}
 1176|    307|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    307|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1176:11): [True: 303, False: 4]
  ------------------
 1177|       |		/* path present: set 'path' */
 1178|    303|		memcpy(path->value, path_value, path_len);
 1179|    303|		path->len = path_len;
 1180|    303|	}
 1181|      4|	else   {
 1182|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1183|      4|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      4|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1184|      4|	}
 1185|       |
 1186|    303|	if (path->len == 2)
  ------------------
  |  Branch (1186:6): [True: 9, False: 294]
  ------------------
 1187|      9|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      9|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1188|    294|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1188:13): [True: 0, False: 294]
  |  Branch (1188:30): [True: 0, False: 0]
  ------------------
 1189|      0|		path->type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 1190|    294|	else
 1191|    294|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    294|#define SC_PATH_TYPE_PATH		2
  ------------------
 1192|       |
 1193|    303|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|    303|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      2|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1193:6): [True: 2, False: 301]
  |  Branch (1193:48): [True: 0, False: 2]
  ------------------
 1194|      0|		path->index = idx;
 1195|      0|		path->count = count;
 1196|      0|	}
 1197|    303|	else {
 1198|    303|		path->index = 0;
 1199|    303|		path->count = -1;
 1200|    303|	}
 1201|       |
 1202|    303|	return SC_SUCCESS;
  ------------------
  |  |   28|    303|#define SC_SUCCESS				0
  ------------------
 1203|    307|}
asn1.c:asn1_decode_p15_object:
 1391|     43|{
 1392|     43|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1393|     43|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1394|     43|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1395|     43|	size_t flags_len = sizeof(p15_obj->flags);
 1396|     43|	size_t label_len = sizeof(p15_obj->label);
 1397|     43|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1398|     43|	int r, ii;
 1399|       |
 1400|    387|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|    387|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1400:13): [True: 344, False: 43]
  ------------------
 1401|    344|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1402|     43|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1403|       |
 1404|       |
 1405|     43|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1406|     43|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1407|     43|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1408|     43|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1409|     43|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1410|     43|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1411|       |
 1412|    387|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|    387|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1412:13): [True: 344, False: 43]
  ------------------
 1413|    344|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1414|    344|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1415|    344|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1416|    344|	}
 1417|     43|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1418|       |
 1419|     43|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1420|     43|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1421|     43|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1422|     43|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1423|       |
 1424|     43|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1425|     43|	return r;
 1426|     43|}
asn1.c:asn1_decode_se_info:
 1239|     18|{
 1240|     18|	struct sc_pkcs15_sec_env_info **ses;
 1241|     18|	const unsigned char *ptr = obj;
 1242|     18|	size_t idx, ptrlen = objlen;
 1243|     18|	int ret;
 1244|       |
 1245|     18|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1246|       |
 1247|     18|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     18|#define SC_MAX_SE_NUM			8
  ------------------
 1248|     18|	if (ses == NULL) {
  ------------------
  |  Branch (1248:6): [True: 0, False: 18]
  ------------------
 1249|      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]
  |  |  ------------------
  ------------------
 1250|      0|	}
 1251|       |
 1252|     54|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|    108|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1252:14): [True: 54, False: 0]
  |  Branch (1252:37): [True: 44, False: 10]
  ------------------
 1253|     44|		struct sc_asn1_entry asn1_se[2];
 1254|     44|		struct sc_asn1_entry asn1_se_info[4];
 1255|     44|		struct sc_pkcs15_sec_env_info si;
 1256|       |
 1257|     44|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1258|     44|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1259|       |
 1260|     44|		si.aid.len = sizeof(si.aid.value);
 1261|     44|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1262|     44|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1263|     44|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1264|     44|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1265|       |
 1266|     44|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1267|     44|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     44|#define SC_SUCCESS				0
  ------------------
  |  Branch (1267:7): [True: 8, False: 36]
  ------------------
 1268|      8|			goto err;
 1269|     36|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1269:7): [True: 29, False: 7]
  ------------------
 1270|     29|			sc_init_oid(&si.owner);
 1271|       |
 1272|     36|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1273|     36|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1273:7): [True: 0, False: 36]
  ------------------
 1274|      0|			ret = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1275|      0|			goto err;
 1276|      0|		}
 1277|       |
 1278|     36|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1279|     36|		idx++;
 1280|     36|	}
 1281|       |
 1282|     10|	*se  = ses;
 1283|     10|	*num = idx;
 1284|     10|	ret = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 1285|     18|err:
 1286|     18|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (1286:6): [True: 8, False: 10]
  ------------------
 1287|      8|		size_t i;
 1288|     24|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1288:15): [True: 16, False: 8]
  ------------------
 1289|     16|			if (ses[i])
  ------------------
  |  Branch (1289:8): [True: 16, False: 0]
  ------------------
 1290|     16|				free(ses[i]);
 1291|      8|		free(ses);
 1292|      8|	}
 1293|       |
 1294|     18|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  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|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 8, False: 10]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1295|     18|}
asn1.c:asn1_encode:
 2039|  7.29k|{
 2040|  7.29k|	int r, idx = 0;
 2041|  7.29k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2042|  7.29k|	size_t total = 0, objsize;
 2043|       |
 2044|  7.29k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2044:6): [True: 0, False: 7.29k]
  ------------------
 2045|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2046|      0|	}
 2047|       |
 2048|  16.9k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2048:16): [True: 9.66k, False: 7.28k]
  ------------------
 2049|  9.66k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2050|  9.66k|		if (r) {
  ------------------
  |  Branch (2050:7): [True: 12, False: 9.65k]
  ------------------
 2051|     12|			if (obj)
  ------------------
  |  Branch (2051:8): [True: 0, False: 12]
  ------------------
 2052|      0|				free(obj);
 2053|     12|			if (buf)
  ------------------
  |  Branch (2053:8): [True: 5, False: 7]
  ------------------
 2054|      5|				free(buf);
 2055|     12|			return r;
 2056|     12|		}
 2057|       |		/* in case of an empty (optional) element continue with
 2058|       |		 * the next asn1 element */
 2059|  9.65k|		if (!objsize)
  ------------------
  |  Branch (2059:7): [True: 2.15k, False: 7.50k]
  ------------------
 2060|  2.15k|			continue;
 2061|  7.50k|		tmp = (u8 *) realloc(buf, total + objsize);
 2062|  7.50k|		if (!tmp) {
  ------------------
  |  Branch (2062:7): [True: 0, False: 7.50k]
  ------------------
 2063|      0|			if (obj)
  ------------------
  |  Branch (2063:8): [True: 0, False: 0]
  ------------------
 2064|      0|				free(obj);
 2065|      0|			if (buf)
  ------------------
  |  Branch (2065:8): [True: 0, False: 0]
  ------------------
 2066|      0|				free(buf);
 2067|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2068|      0|		}
 2069|  7.50k|		buf = tmp;
 2070|  7.50k|		memcpy(buf + total, obj, objsize);
 2071|  7.50k|		free(obj);
 2072|  7.50k|		obj = NULL;
 2073|  7.50k|		total += objsize;
 2074|  7.50k|	}
 2075|  7.28k|	*ptr = buf;
 2076|  7.28k|	*size = total;
 2077|  7.28k|	return 0;
 2078|  7.29k|}
asn1.c:asn1_encode_entry:
 1826|  9.66k|{
 1827|  9.66k|	void *parm = entry->parm;
 1828|  9.66k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1829|  9.66k|			     size_t *nobjlen, int ndepth);
 1830|  9.66k|	const size_t *len = (const size_t *) entry->arg;
 1831|  9.66k|	int r = 0;
 1832|  9.66k|	u8 * buf = NULL;
 1833|  9.66k|	size_t buflen = 0;
 1834|       |
 1835|  9.66k|	callback_func = parm;
 1836|       |
 1837|  9.66k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  9.66k|#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)
  |  |  ------------------
  |  |  |  | 1838|  9.66k|	       	depth, depth, "", entry->name,
  |  |  |  | 1839|  9.66k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  9.66k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1838|  9.66k|	       	depth, depth, "", entry->name,
 1839|  9.66k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1840|  9.66k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  9.66k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1840:6): [True: 2.15k, False: 7.51k]
  ------------------
 1841|  2.15k|		goto no_object;
 1842|  7.51k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*stype=%d, tag=0x%02x, parm=%p, len=%zu",
  ------------------
  |  |   70|  15.0k|#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: 3.07k, False: 4.43k]
  |  |  ------------------
  ------------------
 1843|  7.51k|			depth, depth, "", entry->type, entry->tag, parm, len ? *len : 0);
 1844|       |
 1845|  7.51k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  7.51k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1845:6): [True: 0, False: 7.51k]
  ------------------
 1846|      0|		const struct sc_asn1_entry *list, *choice = NULL;
 1847|       |
 1848|      0|		list = (const struct sc_asn1_entry *) parm;
 1849|      0|		while (list->name != NULL) {
  ------------------
  |  Branch (1849:10): [True: 0, False: 0]
  ------------------
 1850|      0|			if (list->flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1850:8): [True: 0, False: 0]
  ------------------
 1851|      0|				if (choice) {
  ------------------
  |  Branch (1851:9): [True: 0, False: 0]
  ------------------
 1852|      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__
  |  |  ------------------
  ------------------
 1853|      0|						"ASN.1 problem: more than "
 1854|      0|						"one CHOICE when encoding %s: "
 1855|      0|						"%s and %s both present\n",
 1856|      0|						entry->name,
 1857|      0|						choice->name,
 1858|      0|						list->name);
 1859|      0|					return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1860|      0|				}
 1861|      0|				choice = list;
 1862|      0|			}
 1863|      0|			list++;
 1864|      0|		}
 1865|      0|		if (choice == NULL)
  ------------------
  |  Branch (1865:7): [True: 0, False: 0]
  ------------------
 1866|      0|			goto no_object;
 1867|      0|		return asn1_encode_entry(ctx, choice, obj, objlen, depth + 1);
 1868|      0|	}
 1869|       |
 1870|  7.51k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|  15.0k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1870:6): [True: 7.48k, False: 32]
  |  Branch (1870:37): [True: 6, False: 7.47k]
  ------------------
 1871|      6|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1872|      6|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1873|      6|	}
 1874|       |
 1875|  7.50k|	switch (entry->type) {
 1876|    186|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|    186|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1876:2): [True: 186, False: 7.32k]
  ------------------
 1877|    186|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1878|    186|				&buflen, depth + 1);
 1879|    186|		break;
 1880|     32|	case SC_ASN1_NULL:
  ------------------
  |  |  158|     32|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1880:2): [True: 32, False: 7.47k]
  ------------------
 1881|     32|		buf = NULL;
 1882|     32|		buflen = 0;
 1883|     32|		break;
 1884|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1884:2): [True: 0, False: 7.50k]
  ------------------
 1885|      0|		buf = malloc(1);
 1886|      0|		if (buf == NULL) {
  ------------------
  |  Branch (1886:7): [True: 0, False: 0]
  ------------------
 1887|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1888|      0|			break;
 1889|      0|		}
 1890|      0|		buf[0] = *((int *) parm) ? 0xFF : 0;
  ------------------
  |  Branch (1890:12): [True: 0, False: 0]
  ------------------
 1891|      0|		buflen = 1;
 1892|      0|		break;
 1893|      0|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|      0|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1893:2): [True: 0, False: 7.50k]
  ------------------
 1894|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1894:2): [True: 0, False: 7.50k]
  ------------------
 1895|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1896|      0|		break;
 1897|    148|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|    148|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1897:2): [True: 148, False: 7.35k]
  ------------------
 1898|    148|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|    148|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1898:2): [True: 0, False: 7.50k]
  ------------------
 1899|    148|		if (len != NULL) {
  ------------------
  |  Branch (1899:7): [True: 148, False: 0]
  ------------------
 1900|    148|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|    148|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1900:8): [True: 0, False: 148]
  ------------------
 1901|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1902|    148|			else
 1903|    148|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1904|    148|		} else {
 1905|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1906|      0|		}
 1907|    148|		break;
 1908|      0|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|      0|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1908:2): [True: 0, False: 7.50k]
  ------------------
 1909|      0|		if (len != NULL) {
  ------------------
  |  Branch (1909:7): [True: 0, False: 0]
  ------------------
 1910|      0|			r = encode_bit_field((const u8 *) parm, *len, &buf, &buflen);
 1911|      0|		} else {
 1912|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1913|      0|		}
 1914|      0|		break;
 1915|      0|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      0|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1915:2): [True: 0, False: 7.50k]
  ------------------
 1916|  2.92k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  2.92k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1916:2): [True: 2.92k, False: 4.58k]
  ------------------
 1917|  2.92k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  2.92k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1917:2): [True: 0, False: 7.50k]
  ------------------
 1918|  2.92k|		if (len != NULL) {
  ------------------
  |  Branch (1918:7): [True: 2.92k, False: 0]
  ------------------
 1919|  2.92k|			buf = malloc(*len + 1);
 1920|  2.92k|			if (buf == NULL) {
  ------------------
  |  Branch (1920:8): [True: 0, False: 2.92k]
  ------------------
 1921|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1922|      0|				break;
 1923|      0|			}
 1924|  2.92k|			buflen = 0;
 1925|       |			/* If the integer is supposed to be unsigned, insert
 1926|       |			 * a padding byte if the MSB is one */
 1927|  2.92k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  2.92k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1927:8): [True: 69, False: 2.85k]
  ------------------
 1928|     69|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1928:9): [True: 26, False: 43]
  ------------------
 1929|     26|				buf[buflen++] = 0x00;
 1930|     26|			}
 1931|  2.92k|			memcpy(buf + buflen, parm, *len);
 1932|  2.92k|			buflen += *len;
 1933|  2.92k|		} else {
 1934|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1935|      0|		}
 1936|  2.92k|		break;
 1937|  2.92k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1937:2): [True: 0, False: 7.50k]
  ------------------
 1938|      0|		if (len != NULL) {
  ------------------
  |  Branch (1938:7): [True: 0, False: 0]
  ------------------
 1939|      0|			buf = malloc(*len);
 1940|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1940:8): [True: 0, False: 0]
  ------------------
 1941|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1942|      0|				break;
 1943|      0|			}
 1944|      0|			memcpy(buf, parm, *len);
 1945|      0|			buflen = *len;
 1946|      0|		} else {
 1947|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1948|      0|		}
 1949|      0|		break;
 1950|  4.06k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  4.06k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1950:2): [True: 4.06k, False: 3.43k]
  ------------------
 1951|  4.06k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1952|  4.06k|		break;
 1953|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  174|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1953:2): [True: 0, False: 7.50k]
  ------------------
 1954|      0|		r = asn1_encode_path(ctx, (const sc_path_t *) parm, &buf, &buflen, depth, entry->flags);
 1955|      0|		break;
 1956|      0|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|      0|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1956:2): [True: 0, False: 7.50k]
  ------------------
 1957|      0|		{
 1958|      0|			const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm;
 1959|       |
 1960|      0|			buf = malloc(id->len);
 1961|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1961:8): [True: 0, False: 0]
  ------------------
 1962|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1963|      0|				break;
 1964|      0|			}
 1965|      0|			memcpy(buf, id->value, id->len);
 1966|      0|			buflen = id->len;
 1967|      0|		}
 1968|      0|		break;
 1969|      0|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|      0|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1969:2): [True: 0, False: 7.50k]
  ------------------
 1970|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1971|      0|		break;
 1972|    148|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|    148|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1972:2): [True: 148, False: 7.35k]
  ------------------
 1973|    148|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1974|    148|		break;
 1975|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1975:2): [True: 0, False: 7.50k]
  ------------------
 1976|      0|		if (!len)
  ------------------
  |  Branch (1976:7): [True: 0, False: 0]
  ------------------
 1977|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1978|      0|		r = asn1_encode_se_info(ctx, (struct sc_pkcs15_sec_env_info **)parm, *len, &buf, &buflen, depth);
 1979|      0|		break;
 1980|      0|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|      0|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1980:2): [True: 0, False: 7.50k]
  ------------------
 1981|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1982|      0|		break;
 1983|      0|	default:
  ------------------
  |  Branch (1983:2): [True: 0, False: 7.50k]
  ------------------
 1984|      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__
  |  |  ------------------
  ------------------
 1985|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1986|  7.50k|	}
 1987|  7.50k|	if (r) {
  ------------------
  |  Branch (1987:6): [True: 6, False: 7.50k]
  ------------------
 1988|      6|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1989|      6|		      sc_strerror(r));
 1990|      6|		if (buf)
  ------------------
  |  Branch (1990:7): [True: 0, False: 6]
  ------------------
 1991|      0|			free(buf);
 1992|      6|		return r;
 1993|      6|	}
 1994|       |
 1995|       |	/* Treatment of OPTIONAL elements:
 1996|       |	 *  -	if the encoding has 0 length, and the element is OPTIONAL,
 1997|       |	 *	we don't write anything (unless it's an ASN1 NULL and the
 1998|       |	 *      SC_ASN1_PRESENT flag is set).
 1999|       |	 *  -	if the encoding has 0 length, but the element is non-OPTIONAL,
 2000|       |	 *	constructed, we write a empty element (e.g. a SEQUENCE of
 2001|       |	 *      length 0). In case of an ASN1 NULL just write the tag and
 2002|       |	 *      length (i.e. 0x05,0x00).
 2003|       |	 *  -	any other empty objects are considered bogus
 2004|       |	 */
 2005|  9.65k|no_object:
 2006|  9.65k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|  11.8k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  2.18k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2006:6): [True: 2.18k, False: 7.46k]
  |  Branch (2006:17): [True: 2.18k, False: 0]
  |  Branch (2006:52): [True: 2.15k, False: 32]
  ------------------
 2007|       |		/* This happens when we try to encode e.g. the
 2008|       |		 * subClassAttributes, which may be empty */
 2009|  2.15k|		*obj = NULL;
 2010|  2.15k|		*objlen = 0;
 2011|  2.15k|		r = 0;
 2012|  7.50k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|     32|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2012:13): [True: 32, False: 7.46k]
  |  Branch (2012:24): [True: 0, False: 32]
  ------------------
 2013|      0|		*obj = NULL;
 2014|      0|		*objlen = 0;
 2015|      0|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2016|      0|		if (r)
  ------------------
  |  Branch (2016:7): [True: 0, False: 0]
  ------------------
 2017|      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__
  |  |  ------------------
  ------------------
 2018|  7.50k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|  7.53k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|      0|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2018:13): [True: 7.46k, False: 32]
  |  Branch (2018:23): [True: 32, False: 0]
  |  Branch (2018:54): [True: 0, False: 0]
  ------------------
 2019|  7.50k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2020|  7.50k|		if (r)
  ------------------
  |  Branch (2020:7): [True: 0, False: 7.50k]
  ------------------
 2021|      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__
  |  |  ------------------
  ------------------
 2022|  7.50k|					sc_strerror(r));
 2023|  7.50k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2023:13): [True: 0, False: 0]
  ------------------
 2024|      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__
  |  |  ------------------
  ------------------
 2025|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2026|      0|	} else {
 2027|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\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__
  |  |  ------------------
  ------------------
 2028|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2029|      0|	}
 2030|  9.65k|	if (buf)
  ------------------
  |  Branch (2030:6): [True: 7.46k, False: 2.18k]
  ------------------
 2031|  7.46k|		free(buf);
 2032|  9.65k|	if (r >= 0)
  ------------------
  |  Branch (2032:6): [True: 9.65k, False: 0]
  ------------------
 2033|  9.65k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*slength of encoded item=%zu", depth, depth, "", *objlen);
  ------------------
  |  |   70|  9.65k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2034|  9.65k|	return r;
 2035|  7.50k|}
asn1.c:encode_bit_string:
  647|    148|{
  648|    148|	const u8 *in = inbuf;
  649|    148|	u8 *out;
  650|    148|	size_t bytes, skipped = 0;
  651|       |
  652|    148|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  146|    148|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  653|    148|	*outbuf = out = malloc(bytes);
  654|    148|	if (out == NULL)
  ------------------
  |  Branch (654:6): [True: 0, False: 148]
  ------------------
  655|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  656|    148|	*outlen = bytes;
  657|    148|	out += 1;
  658|  15.9k|	while (bits_left) {
  ------------------
  |  Branch (658:9): [True: 15.8k, False: 148]
  ------------------
  659|  15.8k|		size_t i, bits_to_go = 8;
  660|       |
  661|  15.8k|		*out = 0;
  662|  15.8k|		if (bits_left < 8) {
  ------------------
  |  Branch (662:7): [True: 0, False: 15.8k]
  ------------------
  663|      0|			bits_to_go = bits_left;
  664|      0|			skipped = 8 - bits_left;
  665|      0|		}
  666|  15.8k|		if (invert) {
  ------------------
  |  Branch (666:7): [True: 0, False: 15.8k]
  ------------------
  667|      0|			for (i = 0; i < bits_to_go; i++)
  ------------------
  |  Branch (667:16): [True: 0, False: 0]
  ------------------
  668|      0|				*out |= ((*in >> i) & 1) << (7 - i);
  669|  15.8k|		} else {
  670|  15.8k|			*out = *in;
  671|  15.8k|			if (bits_left < 8)
  ------------------
  |  Branch (671:8): [True: 0, False: 15.8k]
  ------------------
  672|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  673|  15.8k|		}
  674|  15.8k|		bits_left -= bits_to_go;
  675|  15.8k|		out++, in++;
  676|  15.8k|	}
  677|    148|	out = *outbuf;
  678|    148|	out[0] = skipped;
  679|    148|	return 0;
  680|    148|}

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

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

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

sc_get_authentic_driver:
 2149|  8.50k|{
 2150|  8.50k|	return sc_get_driver();
 2151|  8.50k|}
card-authentic.c:sc_get_driver:
 2114|  8.50k|{
 2115|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2116|       |
 2117|  8.50k|	if (!iso_ops)
  ------------------
  |  Branch (2117:6): [True: 1, False: 8.49k]
  ------------------
 2118|      1|		iso_ops = iso_drv->ops;
 2119|       |
 2120|  8.50k|	authentic_ops = *iso_ops;
 2121|       |
 2122|  8.50k|	authentic_ops.match_card = authentic_match_card;
 2123|  8.50k|	authentic_ops.init = authentic_init;
 2124|  8.50k|	authentic_ops.finish = authentic_finish;
 2125|  8.50k|	authentic_ops.read_binary = authentic_read_binary;
 2126|  8.50k|	authentic_ops.write_binary = authentic_write_binary;
 2127|  8.50k|	authentic_ops.update_binary = authentic_update_binary;
 2128|  8.50k|	authentic_ops.erase_binary = authentic_erase_binary;
 2129|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2130|  8.50k|	authentic_ops.select_file = authentic_select_file;
 2131|       |	/* get_response: Untested */
 2132|  8.50k|	authentic_ops.get_challenge = authentic_get_challenge;
 2133|  8.50k|	authentic_ops.set_security_env = authentic_set_security_env;
 2134|       |	/* decipher: Untested */
 2135|  8.50k|	authentic_ops.decipher = authentic_decipher;
 2136|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2137|  8.50k|	authentic_ops.create_file = authentic_create_file;
 2138|  8.50k|	authentic_ops.delete_file = authentic_delete_file;
 2139|  8.50k|	authentic_ops.card_ctl = authentic_card_ctl;
 2140|  8.50k|	authentic_ops.process_fci = authentic_process_fci;
 2141|  8.50k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2142|  8.50k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2143|       |
 2144|  8.50k|	return &authentic_drv;
 2145|  8.50k|}
card-authentic.c:authentic_match_card:
  390|  7.21k|{
  391|  7.21k|	struct sc_context *ctx = card->ctx;
  392|  7.21k|	int i;
  393|       |
  394|  7.21k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  7.21k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  7.21k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|  7.21k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  396|  7.21k|	if (i < 0)   {
  ------------------
  |  Branch (396:6): [True: 7.21k, False: 0]
  ------------------
  397|  7.21k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  7.21k|#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|  7.21k|		return 0;
  399|  7.21k|	}
  400|       |
  401|      0|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[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__
  |  |  ------------------
  ------------------
  402|      0|	return 1;
  403|  7.21k|}

sc_get_belpic_driver:
  446|  8.50k|{
  447|  8.50k|	return sc_get_driver();
  448|  8.50k|}
card-belpic.c:sc_get_driver:
  423|  8.50k|{
  424|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (424:6): [True: 1, False: 8.49k]
  ------------------
  425|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  426|       |
  427|  8.50k|	belpic_ops.match_card = belpic_match_card;
  428|  8.50k|	belpic_ops.init = belpic_init;
  429|       |
  430|  8.50k|	belpic_ops.update_binary = iso_ops->update_binary;
  431|  8.50k|	belpic_ops.select_file = belpic_select_file;
  432|  8.50k|	belpic_ops.read_binary = belpic_read_binary;
  433|  8.50k|	belpic_ops.pin_cmd = belpic_pin_cmd;
  434|  8.50k|	belpic_ops.set_security_env = belpic_set_security_env;
  435|       |
  436|  8.50k|	belpic_ops.compute_signature = iso_ops->compute_signature;
  437|  8.50k|	belpic_ops.get_challenge = iso_ops->get_challenge;
  438|  8.50k|	belpic_ops.get_response = iso_ops->get_response;
  439|  8.50k|	belpic_ops.check_sw = iso_ops->check_sw;
  440|       |
  441|  8.50k|	return &belpic_drv;
  442|  8.50k|}
card-belpic.c:belpic_match_card:
  208|  7.00k|{
  209|  7.00k|	int i;
  210|       |
  211|  7.00k|	i = _sc_match_atr(card, belpic_atrs, &card->type);
  212|  7.00k|	if (i < 0)
  ------------------
  |  Branch (212:6): [True: 7.00k, False: 0]
  ------------------
  213|  7.00k|		return 0;
  214|      0|	return 1;
  215|  7.00k|}

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

sc_get_cac_driver:
 1911|  17.0k|{
 1912|  17.0k|	return sc_get_driver();
 1913|  17.0k|}
card-cac.c:sc_get_driver:
 1885|  17.0k|{
 1886|  17.0k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1887|       |
 1888|  17.0k|	cac_ops = *iso_drv->ops;
 1889|  17.0k|	cac_ops.match_card = cac_match_card;
 1890|  17.0k|	cac_ops.init = cac_init;
 1891|  17.0k|	cac_ops.finish = cac_finish;
 1892|       |
 1893|  17.0k|	cac_ops.select_file =  cac_select_file; /* need to record object type */
 1894|  17.0k|	cac_ops.get_challenge = cac_get_challenge;
 1895|  17.0k|	cac_ops.read_binary = cac_read_binary;
 1896|       |	/* CAC driver is read only */
 1897|  17.0k|	cac_ops.write_binary = NULL;
 1898|  17.0k|	cac_ops.set_security_env = cac_set_security_env;
 1899|  17.0k|	cac_ops.restore_security_env = cac_restore_security_env;
 1900|  17.0k|	cac_ops.compute_signature = cac_compute_signature;
 1901|  17.0k|	cac_ops.decipher =  cac_decipher;
 1902|  17.0k|	cac_ops.card_ctl = cac_card_ctl;
 1903|  17.0k|	cac_ops.pin_cmd = cac_pin_cmd;
 1904|  17.0k|	cac_ops.logout = cac_logout;
 1905|       |
 1906|  17.0k|	return &cac_drv;
 1907|  17.0k|}
card-cac.c:cac_match_card:
 1796|  3.27k|{
 1797|  3.27k|	int r;
 1798|  3.27k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.27k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.27k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.27k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.27k]
  |  |  ------------------
  ------------------
 1799|       |
 1800|  3.27k|	r = cac_find_and_initialize(card, 0);
 1801|  3.27k|	return (r == SC_SUCCESS); /* never match */
  ------------------
  |  |   28|  3.27k|#define SC_SUCCESS				0
  ------------------
 1802|  3.27k|}
card-cac.c:cac_find_and_initialize:
 1719|  3.99k|{
 1720|  3.99k|	int r, index;
 1721|  3.99k|	cac_private_data_t *priv = NULL;
 1722|       |
 1723|       |	/* already initialized? */
 1724|  3.99k|	if (card->drv_data) {
  ------------------
  |  Branch (1724:6): [True: 0, False: 3.99k]
  ------------------
 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|  3.99k|	r = cac_select_CCC(card);
 1731|  3.99k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.99k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1731:6): [True: 715, False: 3.28k]
  ------------------
 1732|    715|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "CCC found, is CAC-2");
  ------------------
  |  |   70|    715|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1733|    715|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1733:7): [True: 414, False: 301]
  ------------------
 1734|    414|			return r;
 1735|       |
 1736|    301|		priv = cac_new_private_data();
 1737|    301|		if (!priv)
  ------------------
  |  Branch (1737:7): [True: 0, False: 301]
  ------------------
 1738|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1739|    301|		r = cac_process_CCC(card, priv, 0);
 1740|    301|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    301|#define SC_SUCCESS				0
  ------------------
  |  Branch (1740:7): [True: 112, False: 189]
  ------------------
 1741|    112|			card->type = SC_CARD_TYPE_CAC_II;
 1742|    112|			card->drv_data = priv;
 1743|    112|			return r;
 1744|    112|		}
 1745|    301|	}
 1746|       |
 1747|       |	/* Even some ALT tokens can be missing CCC so we should try with ACA */
 1748|  3.47k|	r = cac_select_ACA(card);
 1749|  3.47k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.47k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1749:6): [True: 455, False: 3.01k]
  ------------------
 1750|    455|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "ACA found, is CAC-2 without CCC");
  ------------------
  |  |   70|    455|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1751|    455|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1751:7): [True: 105, False: 350]
  ------------------
 1752|    105|			return r;
 1753|       |
 1754|    350|		if (!priv) {
  ------------------
  |  Branch (1754:7): [True: 291, False: 59]
  ------------------
 1755|    291|			priv = cac_new_private_data();
 1756|    291|			if (!priv)
  ------------------
  |  Branch (1756:8): [True: 0, False: 291]
  ------------------
 1757|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1758|    291|		}
 1759|    350|		r = cac_process_ACA(card, priv);
 1760|    350|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    350|#define SC_SUCCESS				0
  ------------------
  |  Branch (1760:7): [True: 187, False: 163]
  ------------------
 1761|    187|			card->type = SC_CARD_TYPE_CAC_ALT_HID;
 1762|    187|			card->drv_data = priv;
 1763|    187|			return r;
 1764|    187|		}
 1765|    350|	}
 1766|       |
 1767|       |	/* is this a CAC Alt token without any accompanying structures */
 1768|  3.18k|	r = cac_find_first_pki_applet(card, &index);
 1769|  3.18k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.18k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1769:6): [True: 367, False: 2.81k]
  ------------------
 1770|    367|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "PKI applet found, is bare CAC Alt");
  ------------------
  |  |   70|    367|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1771|    367|		if (!initialize) /* match card only */
  ------------------
  |  Branch (1771:7): [True: 208, False: 159]
  ------------------
 1772|    208|			return r;
 1773|       |
 1774|    159|		if (!priv) {
  ------------------
  |  Branch (1774:7): [True: 51, False: 108]
  ------------------
 1775|     51|			priv = cac_new_private_data();
 1776|     51|			if (!priv)
  ------------------
  |  Branch (1776:8): [True: 0, False: 51]
  ------------------
 1777|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1778|     51|		}
 1779|    159|		card->drv_data = priv; /* needed for the read_binary() */
 1780|    159|		r = cac_populate_cac_alt(card, index, priv);
 1781|    159|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (1781:7): [True: 112, False: 47]
  ------------------
 1782|    112|			card->type = SC_CARD_TYPE_CAC_II;
 1783|    112|			return r;
 1784|    112|		}
 1785|     47|		card->drv_data = NULL; /* reset on failure */
 1786|     47|	}
 1787|  2.86k|	if (priv) {
  ------------------
  |  Branch (1787:6): [True: 232, False: 2.62k]
  ------------------
 1788|    232|		cac_free_private_data(priv);
 1789|    232|	}
 1790|  2.86k|	return r;
 1791|  3.18k|}
card-cac.c:cac_select_CCC:
 1218|  3.99k|{
 1219|       |	return cac_select_file_by_type(card, &cac_CCC_Path, NULL);
 1220|  3.99k|}
card-cac.c:cac_select_file_by_type:
 1023|  59.7k|{
 1024|  59.7k|	struct sc_context *ctx;
 1025|  59.7k|	struct sc_apdu apdu;
 1026|  59.7k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
 1027|  59.7k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
 1028|  59.7k|	int r, pathtype;
 1029|  59.7k|	size_t pathlen;
 1030|  59.7k|	struct sc_file *file = NULL;
 1031|  59.7k|	cac_private_data_t *priv;
 1032|       |
 1033|  59.7k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1033:6): [True: 0, False: 59.7k]
  |  Branch (1033:22): [True: 0, False: 59.7k]
  ------------------
 1034|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1035|       |
 1036|  59.7k|	priv = CAC_DATA(card);
  ------------------
  |  |   61|  59.7k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
 1037|  59.7k|	ctx = card->ctx;
 1038|       |
 1039|  59.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  59.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  59.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  59.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 59.7k]
  |  |  ------------------
  ------------------
 1040|       |
 1041|  59.7k|	memcpy(path, in_path->value, in_path->len);
 1042|  59.7k|	pathlen = in_path->len;
 1043|  59.7k|	pathtype = in_path->type;
 1044|       |
 1045|  59.7k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  59.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1046|  59.7k|	    "path=%s, path->value=%s path->type=%d (%x)",
 1047|  59.7k|	    sc_print_path(in_path),
 1048|  59.7k|	    sc_dump_hex(in_path->value, in_path->len),
 1049|  59.7k|	    in_path->type, in_path->type);
 1050|  59.7k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "file_out=%p index=%d count=%d\n",
  ------------------
  |  |   70|  59.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1051|  59.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|  59.7k|	if ((pathlen > 2) && (pathlen <= 4) && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (1058:6): [True: 1.20k, False: 58.5k]
  |  Branch (1058:23): [True: 1.20k, False: 0]
  |  Branch (1058:41): [True: 1.20k, False: 0]
  ------------------
 1059|  1.20k|		path += 2;
 1060|  1.20k|		pathlen -= 2;
 1061|  1.20k|	}
 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|  59.7k|	if (priv) { /* don't record anything if we haven't been initialized yet */
  ------------------
  |  Branch (1068:6): [True: 5.44k, False: 54.2k]
  ------------------
 1069|  5.44k|		priv->object_type = CAC_OBJECT_TYPE_GENERIC;
  ------------------
  |  |  172|  5.44k|#define CAC_OBJECT_TYPE_GENERIC		5
  ------------------
 1070|  5.44k|		if (cac_is_cert(priv, in_path)) {
  ------------------
  |  Branch (1070:7): [True: 982, False: 4.45k]
  ------------------
 1071|    982|			priv->object_type = CAC_OBJECT_TYPE_CERT;
  ------------------
  |  |  170|    982|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
 1072|    982|		}
 1073|       |
 1074|       |		/* forget any old cached values */
 1075|  5.44k|		if (priv->cache_buf) {
  ------------------
  |  Branch (1075:7): [True: 0, False: 5.44k]
  ------------------
 1076|      0|			free(priv->cache_buf);
 1077|      0|			priv->cache_buf = NULL;
 1078|      0|		}
 1079|  5.44k|		priv->cache_buf_len = 0;
 1080|  5.44k|		priv->cached = 0;
 1081|  5.44k|	}
 1082|       |
 1083|  59.7k|	if (in_path->aid.len) {
  ------------------
  |  Branch (1083:6): [True: 58.5k, False: 1.20k]
  ------------------
 1084|  58.5k|		if (!pathlen) {
  ------------------
  |  Branch (1084:7): [True: 58.3k, False: 123]
  ------------------
 1085|  58.3k|			memcpy(path, in_path->aid.value, in_path->aid.len);
 1086|  58.3k|			pathlen = in_path->aid.len;
 1087|  58.3k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  58.3k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1088|  58.3k|		} else {
 1089|       |			/* First, select the application */
 1090|    123|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"select application" );
  ------------------
  |  |   70|    123|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1091|    123|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    123|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1092|    123|			apdu.data = in_path->aid.value;
 1093|    123|			apdu.datalen = in_path->aid.len;
 1094|    123|			apdu.lc = in_path->aid.len;
 1095|       |
 1096|    123|			r = sc_transmit_apdu(card, &apdu);
 1097|    123|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    123|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    123|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    123|	int _ret = (r); \
  |  |  |  |  168|    123|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  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|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1098|    122|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1099|    122|			if (r)
  ------------------
  |  Branch (1099:8): [True: 44, False: 78]
  ------------------
 1100|    122|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     44|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     44|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     44|	int _ret = r; \
  |  |  |  |  155|     44|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 44, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     44|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     44|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     44|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     44|	return _ret; \
  |  |  |  |  163|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|       |
 1102|    122|		}
 1103|  58.5k|	}
 1104|       |
 1105|  59.6k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  59.6k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1106|       |
 1107|  59.6k|	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|     78|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|     78|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1111:2): [True: 78, False: 59.5k]
  ------------------
 1112|     78|		apdu.p1 = 2;
 1113|     78|		if (pathlen != 2)
  ------------------
  |  Branch (1113:7): [True: 0, False: 78]
  ------------------
 1114|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1115|     78|		break;
 1116|  58.3k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  58.3k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1116:2): [True: 58.3k, False: 1.27k]
  ------------------
 1117|  58.3k|		apdu.p1 = 4;
 1118|  58.3k|		break;
 1119|  1.20k|	default:
  ------------------
  |  Branch (1119:2): [True: 1.20k, False: 58.4k]
  ------------------
 1120|  1.20k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.20k|	} else { \
  |  |  |  |  159|      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.20k|	return _ret; \
  |  |  |  |  163|  1.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1121|  59.6k|	}
 1122|  58.4k|	apdu.lc = pathlen;
 1123|  58.4k|	apdu.data = path;
 1124|  58.4k|	apdu.datalen = pathlen;
 1125|  58.4k|	apdu.resp = buf;
 1126|  58.4k|	apdu.resplen = sizeof(buf);
 1127|  58.4k|	apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (1127:12): [True: 0, False: 58.4k]
  ------------------
 1128|       |
 1129|  58.4k|	if (file_out != NULL) {
  ------------------
  |  Branch (1129:6): [True: 894, False: 57.5k]
  ------------------
 1130|    894|		apdu.p2 = 0;		/* first record, return FCI */
 1131|    894|	}
 1132|  57.5k|	else {
 1133|  57.5k|		apdu.p2 = 0x0C;
 1134|  57.5k|	}
 1135|       |
 1136|  58.4k|	r = sc_transmit_apdu(card, &apdu);
 1137|  58.4k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  58.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  58.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  58.4k|	int _ret = (r); \
  |  |  |  |  168|  58.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.08k, False: 57.3k]
  |  |  |  |  ------------------
  |  |  |  |  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|  58.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1138|       |
 1139|  57.3k|	if (file_out == NULL) {
  ------------------
  |  Branch (1139:6): [True: 56.4k, False: 888]
  ------------------
 1140|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
 1141|  56.4k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1142|  56.4k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (1142:7): [True: 176, False: 56.3k]
  |  Branch (1142:27): [True: 75, False: 101]
  ------------------
 1143|     75|			apdu.p2 = 0x00;
 1144|     75|			apdu.resplen = sizeof(buf);
 1145|     75|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     75|#define SC_SUCCESS				0
  ------------------
  |  Branch (1145:8): [True: 72, False: 3]
  ------------------
 1146|     72|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1147|     75|		}
 1148|  56.4k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1148:7): [True: 3, False: 56.4k]
  ------------------
 1149|  56.4k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|  56.4k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  56.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  56.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  56.4k|	int _ret = r; \
  |  |  |  |  155|  56.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 56.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  56.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|  53.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 53.0k, False: 3.39k]
  |  |  |  |  ------------------
  |  |  |  |  157|  56.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  56.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|  56.4k|	return _ret; \
  |  |  |  |  163|  56.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|  56.4k|	}
 1152|       |
 1153|    888|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1154|    888|	if (r)
  ------------------
  |  Branch (1154:6): [True: 540, False: 348]
  ------------------
 1155|    888|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    540|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    540|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    540|	int _ret = r; \
  |  |  |  |  155|    540|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    540|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    540|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    540|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    540|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    540|	return _ret; \
  |  |  |  |  163|    540|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1156|       |
 1157|       |	/* This needs to come after the applet selection */
 1158|    348|	if (priv && in_path->len >= 2) {
  ------------------
  |  Branch (1158:6): [True: 348, False: 0]
  |  Branch (1158:14): [True: 53, False: 295]
  ------------------
 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|     53|		cac_properties_t prop = {0};
 1166|     53|		size_t i = -1;
 1167|       |
 1168|     53|		r = cac_get_properties(card, &prop);
 1169|     53|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     53|#define SC_SUCCESS				0
  ------------------
  |  Branch (1169:7): [True: 47, False: 6]
  ------------------
 1170|    112|			for (i = 0; i < prop.num_objects; i++) {
  ------------------
  |  Branch (1170:16): [True: 70, False: 42]
  ------------------
 1171|     70|				sc_log(card->ctx, "Searching for our OID: 0x%02x 0x%02x = 0x%02x 0x%02x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1172|     70|				    prop.objects[i].oid[0], prop.objects[i].oid[1],
 1173|     70|					in_path->value[0], in_path->value[1]);
 1174|     70|				if (memcmp(prop.objects[i].oid,
  ------------------
  |  Branch (1174:9): [True: 5, False: 65]
  ------------------
 1175|     70|				    in_path->value, 2) == 0)
 1176|      5|					break;
 1177|     70|			}
 1178|     47|		}
 1179|     53|		if (i < prop.num_objects) {
  ------------------
  |  Branch (1179:7): [True: 5, False: 48]
  ------------------
 1180|      5|			if (prop.objects[i].privatekey)
  ------------------
  |  Branch (1180:8): [True: 3, False: 2]
  ------------------
 1181|      3|				priv->object_type = CAC_OBJECT_TYPE_CERT;
  ------------------
  |  |  170|      3|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
 1182|      2|			else if (prop.objects[i].simpletlv == 0)
  ------------------
  |  Branch (1182:13): [True: 1, False: 1]
  ------------------
 1183|      1|				priv->object_type = CAC_OBJECT_TYPE_TLV_FILE;
  ------------------
  |  |  171|      1|#define CAC_OBJECT_TYPE_TLV_FILE	4
  ------------------
 1184|      5|		}
 1185|     53|	}
 1186|       |
 1187|       |	/* CAC cards never return FCI, fake one */
 1188|    348|	file = sc_file_new();
 1189|    348|	if (file == NULL)
  ------------------
  |  Branch (1189:6): [True: 0, False: 348]
  ------------------
 1190|    348|			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|    348|	file->path = *in_path;
 1192|    348|	file->size = CAC_MAX_SIZE; /* we don't know how big, just give a large size until we can read the file */
  ------------------
  |  |   26|    348|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
 1193|       |
 1194|    348|	*file_out = file;
 1195|    348|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    348|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    348|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    348|	int _ret = r; \
  |  |  |  |  155|    348|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 348, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    348|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 348]
  |  |  |  |  ------------------
  |  |  |  |  157|    348|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    348|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    348|	return _ret; \
  |  |  |  |  163|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1196|       |
 1197|    348|}
card-cac.c:cac_is_cert:
  231|  5.44k|{
  232|  5.44k|	cac_object_t test_obj = {0};
  233|  5.44k|	test_obj.path = *in_path;
  234|  5.44k|	test_obj.path.index = 0;
  235|  5.44k|	test_obj.path.count = 0;
  236|       |
  237|  5.44k|	return (list_contains(&priv->pki_list, &test_obj) != 0);
  238|  5.44k|}
card-cac.c:cac_get_properties:
  919|    176|{
  920|    176|	u8 *rbuf = NULL;
  921|    176|	size_t rbuflen = 0, len;
  922|    176|	const u8 *val, *val_end;
  923|    176|	u8 tag;
  924|    176|	size_t i = 0;
  925|    176|	int r;
  926|    176|	prop->num_objects = 0;
  927|       |
  928|    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]
  |  |  ------------------
  ------------------
  929|       |
  930|    176|	r = cac_apdu_io(card, CAC_INS_GET_PROPERTIES, 0x01, 0x00, NULL, 0,
  ------------------
  |  |   63|    176|#define CAC_INS_GET_PROPERTIES        0x56
  ------------------
  931|    176|		&rbuf, &rbuflen);
  932|    176|	if (r < 0)
  ------------------
  |  Branch (932:6): [True: 7, False: 169]
  ------------------
  933|      7|		return r;
  934|       |
  935|    169|	val = rbuf;
  936|    169|	val_end = val + rbuflen;
  937|  6.56k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (937:9): [True: 6.55k, False: 17]
  ------------------
  938|       |		/* get the tag and the length */
  939|  6.55k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  6.55k|#define SC_SUCCESS				0
  ------------------
  |  Branch (939:7): [True: 149, False: 6.40k]
  ------------------
  940|    149|			break;
  941|       |
  942|  6.40k|		switch (tag) {
  943|    497|		case CAC_TAG_APPLET_INFORMATION:
  ------------------
  |  |   89|    497|#define CAC_TAG_APPLET_INFORMATION    0x01
  ------------------
  |  Branch (943:3): [True: 497, False: 5.90k]
  ------------------
  944|    497|			if (len != 5) {
  ------------------
  |  Branch (944:8): [True: 317, False: 180]
  ------------------
  945|    317|				sc_log(card->ctx, "TAG: Applet Information: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  946|    317|				break;
  947|    317|			}
  948|    180|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    180|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  949|    180|			    "TAG: Applet Information: Family: 0x%0x", val[0]);
  950|    180|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    180|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  951|    180|			    "     Applet Version: 0x%02x 0x%02x 0x%02x 0x%02x",
  952|    180|			    val[1], val[2], val[3], val[4]);
  953|    180|			break;
  954|       |
  955|    164|		case CAC_TAG_NUMBER_OF_OBJECTS:
  ------------------
  |  |   90|    164|#define CAC_TAG_NUMBER_OF_OBJECTS     0x40
  ------------------
  |  Branch (955:3): [True: 164, False: 6.23k]
  ------------------
  956|    164|			if (len != 1) {
  ------------------
  |  Branch (956:8): [True: 74, False: 90]
  ------------------
  957|     74|				sc_log(card->ctx, "TAG: Num objects: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  958|     74|				break;
  959|     74|			}
  960|     90|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|     90|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  961|     90|			    "TAG: Num objects = %hhd", *val);
  962|       |			/* make sure we do not overrun buffer */
  963|     90|			prop->num_objects = MIN(val[0], CAC_MAX_OBJECTS);
  ------------------
  |  |   70|     90|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 68, False: 22]
  |  |  ------------------
  ------------------
  964|     90|			break;
  965|       |
  966|    142|		case CAC_TAG_TV_BUFFER:
  ------------------
  |  |   91|    142|#define CAC_TAG_TV_BUFFER             0x50
  ------------------
  |  Branch (966:3): [True: 142, False: 6.26k]
  ------------------
  967|    142|			if (len != 17) {
  ------------------
  |  Branch (967:8): [True: 87, False: 55]
  ------------------
  968|     87|				sc_log(card->ctx, "TAG: TV Object: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  969|     87|				break;
  970|     87|			}
  971|     55|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "TAG: TV Object nr. %zu", i);
  ------------------
  |  |   70|     55|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  972|     55|			if (i >= CAC_MAX_OBJECTS) {
  ------------------
  |  |  145|     55|#define CAC_MAX_OBJECTS 16
  ------------------
  |  Branch (972:8): [True: 1, False: 54]
  ------------------
  973|      1|				free(rbuf);
  974|      1|				return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  975|      1|			}
  976|       |
  977|     54|			if (cac_parse_properties_object(card, tag, val, len,
  ------------------
  |  Branch (977:8): [True: 28, False: 26]
  ------------------
  978|     54|			    &prop->objects[i]) == SC_SUCCESS)
  ------------------
  |  |   28|     54|#define SC_SUCCESS				0
  ------------------
  979|     28|				i++;
  980|     54|			break;
  981|       |
  982|    913|		case CAC_TAG_PKI_OBJECT:
  ------------------
  |  |   92|    913|#define CAC_TAG_PKI_OBJECT            0x51
  ------------------
  |  Branch (982:3): [True: 913, False: 5.48k]
  ------------------
  983|    913|			if (len != 17) {
  ------------------
  |  Branch (983:8): [True: 87, False: 826]
  ------------------
  984|     87|				sc_log(card->ctx, "TAG: PKI Object: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  985|     87|				break;
  986|     87|			}
  987|    826|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "TAG: PKI Object nr. %zu", i);
  ------------------
  |  |   70|    826|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  988|    826|			if (i >= CAC_MAX_OBJECTS) {
  ------------------
  |  |  145|    826|#define CAC_MAX_OBJECTS 16
  ------------------
  |  Branch (988:8): [True: 2, False: 824]
  ------------------
  989|      2|				free(rbuf);
  990|      2|				return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  991|      2|			}
  992|       |
  993|    824|			if (cac_parse_properties_object(card, tag, val, len,
  ------------------
  |  Branch (993:8): [True: 513, False: 311]
  ------------------
  994|    824|			    &prop->objects[i]) == SC_SUCCESS)
  ------------------
  |  |   28|    824|#define SC_SUCCESS				0
  ------------------
  995|    513|				i++;
  996|    824|			break;
  997|       |
  998|  4.68k|		default:
  ------------------
  |  Branch (998:3): [True: 4.68k, False: 1.71k]
  ------------------
  999|       |			/* ignore tags we don't understand */
 1000|  4.68k|			sc_log(card->ctx, "TAG: Unknown (0x%02x), len=%zu", tag, len);
  ------------------
  |  |   71|  4.68k|#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|  4.68k|			break;
 1002|  6.40k|		}
 1003|  6.40k|	}
 1004|    166|	free(rbuf);
 1005|       |	/* sanity */
 1006|    166|	if (i != prop->num_objects)
  ------------------
  |  Branch (1006:6): [True: 102, False: 64]
  ------------------
 1007|    102|		sc_log(card->ctx, "The announced number of objects (%zu) did not match reality (%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1008|    166|				prop->num_objects, i);
 1009|    166|	prop->num_objects = i;
 1010|       |
 1011|    166|	return SC_SUCCESS;
  ------------------
  |  |   28|    166|#define SC_SUCCESS				0
  ------------------
 1012|    169|}
card-cac.c:cac_apdu_io:
  253|  4.81k|{
  254|  4.81k|	int r;
  255|  4.81k|	sc_apdu_t apdu = {0};
  256|  4.81k|	u8 rbufinitbuf[CAC_MAX_SIZE];
  257|  4.81k|	u8 *rbuf;
  258|  4.81k|	size_t rbuflen;
  259|  4.81k|	unsigned int apdu_case = SC_APDU_CASE_1;
  ------------------
  |  |  291|  4.81k|#define SC_APDU_CASE_1			0x01
  ------------------
  260|       |
  261|       |
  262|  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]
  |  |  ------------------
  ------------------
  263|       |
  264|  4.81k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  4.81k|#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|  4.81k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  266|       |
  267|  4.81k|	rbuf = rbufinitbuf;
  268|  4.81k|	rbuflen = sizeof(rbufinitbuf);
  269|       |
  270|       |	/* if caller provided a buffer and length */
  271|  4.81k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (271:6): [True: 4.81k, False: 0]
  |  Branch (271:17): [True: 4.29k, False: 526]
  |  Branch (271:29): [True: 4.29k, False: 0]
  |  Branch (271:43): [True: 4.29k, False: 0]
  ------------------
  272|  4.29k|		rbuf = *recvbuf;
  273|  4.29k|		rbuflen = *recvbuflen;
  274|  4.29k|	}
  275|       |
  276|  4.81k|	if (recvbuf) {
  ------------------
  |  Branch (276:6): [True: 4.81k, False: 0]
  ------------------
  277|  4.81k|		if (sendbuf)
  ------------------
  |  Branch (277:7): [True: 4.29k, False: 526]
  ------------------
  278|  4.29k|			apdu_case = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  4.29k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  279|    526|		else
  280|    526|			apdu_case = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    526|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  281|  4.81k|	} 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|  4.81k|	sc_format_apdu(card, &apdu, apdu_case, ins, p1, p2);
  286|       |
  287|  4.81k|	apdu.lc = sendbuflen;
  288|  4.81k|	apdu.datalen = sendbuflen;
  289|  4.81k|	apdu.data = sendbuf;
  290|       |
  291|  4.81k|	if (recvbuf) {
  ------------------
  |  Branch (291:6): [True: 4.81k, False: 0]
  ------------------
  292|  4.81k|		apdu.resp = rbuf;
  293|  4.81k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (293:13): [True: 526, False: 4.29k]
  ------------------
  294|  4.81k|		apdu.resplen = rbuflen;
  295|  4.81k|	} else {
  296|      0|		 apdu.resp =  rbuf;
  297|      0|		 apdu.le = 0;
  298|      0|		 apdu.resplen = 0;
  299|      0|	}
  300|       |
  301|  4.81k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  4.81k|#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|  4.81k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  303|       |
  304|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  305|  4.81k|	r = sc_transmit_apdu(card, &apdu);
  306|       |
  307|  4.81k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  4.81k|#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|  4.81k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  309|  4.81k|	if (r < 0) {
  ------------------
  |  Branch (309:6): [True: 126, False: 4.69k]
  ------------------
  310|    126|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    126|#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|    126|		goto err;
  312|    126|	}
  313|       |
  314|  4.69k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  315|       |
  316|  4.69k|	if (r < 0) {
  ------------------
  |  Branch (316:6): [True: 509, False: 4.18k]
  ------------------
  317|    509|		sc_log(card->ctx,  "Card returned error ");
  ------------------
  |  |   71|    509|#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|    509|		goto err;
  319|    509|	}
  320|       |
  321|  4.18k|	if (recvbuflen) {
  ------------------
  |  Branch (321:6): [True: 4.18k, False: 0]
  ------------------
  322|  4.18k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (322:7): [True: 4.18k, False: 0]
  |  Branch (322:18): [True: 450, False: 3.73k]
  ------------------
  323|    450|			*recvbuf =  malloc(apdu.resplen);
  324|    450|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (324:8): [True: 0, False: 450]
  ------------------
  325|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  326|      0|				goto err;
  327|      0|			}
  328|    450|			memcpy(*recvbuf, rbuf, apdu.resplen);
  329|    450|		}
  330|  4.18k|		*recvbuflen =  apdu.resplen;
  331|  4.18k|		r = (int)*recvbuflen;
  332|  4.18k|	}
  333|       |
  334|  4.81k|err:
  335|  4.81k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.81k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.81k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.81k|	int _ret = r; \
  |  |  |  |  155|  4.81k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 912, False: 3.90k]
  |  |  |  |  ------------------
  |  |  |  |  156|    912|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    635|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 635, False: 277]
  |  |  |  |  ------------------
  |  |  |  |  157|    912|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.90k|	} else { \
  |  |  |  |  159|  3.90k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.90k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.90k|	} \
  |  |  |  |  162|  4.81k|	return _ret; \
  |  |  |  |  163|  4.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|  4.81k|}
card-cac.c:cac_parse_properties_object:
  844|    878|{
  845|    878|	size_t len;
  846|    878|	const u8 *val, *val_end;
  847|    878|	u8 tag;
  848|    878|	int parsed = 0;
  849|       |
  850|    878|	if (data_len < 11)
  ------------------
  |  Branch (850:6): [True: 0, False: 878]
  ------------------
  851|      0|		return -1;
  852|       |
  853|       |	/* Initialize: non-PKI applet */
  854|    878|	object->privatekey = 0;
  855|       |
  856|    878|	val = data;
  857|    878|	val_end = data + data_len;
  858|  3.26k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (858:9): [True: 2.78k, False: 483]
  ------------------
  859|       |		/* get the tag and the length */
  860|  2.78k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  2.78k|#define SC_SUCCESS				0
  ------------------
  |  Branch (860:7): [True: 395, False: 2.39k]
  ------------------
  861|    395|			break;
  862|       |
  863|  2.39k|		switch (tag) {
  864|    818|		case CAC_TAG_OBJECT_ID:
  ------------------
  |  |   93|    818|#define CAC_TAG_OBJECT_ID             0x41
  ------------------
  |  Branch (864:3): [True: 818, False: 1.57k]
  ------------------
  865|    818|			if (len != 2) {
  ------------------
  |  Branch (865:8): [True: 37, False: 781]
  ------------------
  866|     37|				sc_log(card->ctx, "TAG: Object ID: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  867|     37|				break;
  868|     37|			}
  869|    781|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    781|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  870|    781|			    "TAG: Object ID = 0x%02x 0x%02x", val[0], val[1]);
  871|    781|			memcpy(&object->oid, val, 2);
  872|    781|			parsed++;
  873|    781|			break;
  874|       |
  875|    626|		case CAC_TAG_BUFFER_PROPERTIES:
  ------------------
  |  |   94|    626|#define CAC_TAG_BUFFER_PROPERTIES     0x42
  ------------------
  |  Branch (875:3): [True: 626, False: 1.76k]
  ------------------
  876|    626|			if (len != 5) {
  ------------------
  |  Branch (876:8): [True: 116, False: 510]
  ------------------
  877|    116|				sc_log(card->ctx, "TAG: Buffer Properties: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  878|    116|				break;
  879|    116|			}
  880|       |			/* First byte is "Type of Tag Supported" */
  881|    510|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    510|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  882|    510|			    "TAG: Buffer Properties: Type of Tag Supported = 0x%02x",
  883|    510|			    val[0]);
  884|    510|			object->simpletlv = val[0];
  885|    510|			parsed++;
  886|    510|			break;
  887|       |
  888|    470|		case CAC_TAG_PKI_PROPERTIES:
  ------------------
  |  |   95|    470|#define CAC_TAG_PKI_PROPERTIES        0x43
  ------------------
  |  Branch (888:3): [True: 470, False: 1.92k]
  ------------------
  889|       |			/* 4th byte is "Private Key Initialized" */
  890|    470|			if (len != 4) {
  ------------------
  |  Branch (890:8): [True: 31, False: 439]
  ------------------
  891|     31|				sc_log(card->ctx, "TAG: PKI Properties: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  892|     31|				break;
  893|     31|			}
  894|    439|			if (type != CAC_TAG_PKI_OBJECT) {
  ------------------
  |  |   92|    439|#define CAC_TAG_PKI_OBJECT            0x51
  ------------------
  |  Branch (894:8): [True: 29, False: 410]
  ------------------
  895|     29|				sc_log(card->ctx, "TAG: PKI Properties outside of PKI Object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  896|     29|				break;
  897|     29|			}
  898|    410|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    410|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  899|    410|			    "TAG: PKI Properties: Private Key Initialized = 0x%02x",
  900|    410|			    val[2]);
  901|    410|			object->privatekey = val[2];
  902|    410|			parsed++;
  903|    410|			break;
  904|       |
  905|    477|		default:
  ------------------
  |  Branch (905:3): [True: 477, False: 1.91k]
  ------------------
  906|       |			/* ignore tags we don't understand */
  907|    477|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    477|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  908|    477|			    "TAG: Unknown (0x%02x)",tag );
  909|    477|			break;
  910|  2.39k|		}
  911|  2.39k|	}
  912|    878|	if (parsed < 2)
  ------------------
  |  Branch (912:6): [True: 337, False: 541]
  ------------------
  913|    337|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    337|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  914|       |
  915|    541|	return SC_SUCCESS;
  ------------------
  |  |   28|    541|#define SC_SUCCESS				0
  ------------------
  916|    878|}
card-cac.c:cac_process_CCC:
 1498|    324|{
 1499|    324|	u8 *tl = NULL, *val = NULL;
 1500|    324|	size_t tl_len = 0, val_len = 0;
 1501|    324|	int r;
 1502|       |
 1503|    324|	if (depth > CAC_MAX_CCC_DEPTH) {
  ------------------
  |  |  106|    324|#define CAC_MAX_CCC_DEPTH             16
  ------------------
  |  Branch (1503:6): [True: 0, False: 324]
  ------------------
 1504|      0|		sc_log(card->ctx, "Too much recursive CCC found. Exiting");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1505|      0|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1506|      0|	}
 1507|       |
 1508|    324|	r = cac_read_file(card, CAC_FILE_TAG, &tl, &tl_len);
  ------------------
  |  |   66|    324|#define CAC_FILE_TAG    1
  ------------------
 1509|    324|	if (r < 0)
  ------------------
  |  Branch (1509:6): [True: 166, False: 158]
  ------------------
 1510|    166|		goto done;
 1511|       |
 1512|    158|	r = cac_read_file(card, CAC_FILE_VALUE, &val, &val_len);
  ------------------
  |  |   67|    158|#define CAC_FILE_VALUE  2
  ------------------
 1513|    158|	if (r < 0)
  ------------------
  |  Branch (1513:6): [True: 13, False: 145]
  ------------------
 1514|     13|		goto done;
 1515|       |
 1516|    145|	r = cac_parse_CCC(card, priv, tl, tl_len, val, val_len, depth);
 1517|    324|done:
 1518|    324|	if (tl)
  ------------------
  |  Branch (1518:6): [True: 158, False: 166]
  ------------------
 1519|    158|		free(tl);
 1520|    324|	if (val)
  ------------------
  |  Branch (1520:6): [True: 145, False: 179]
  ------------------
 1521|    145|		free(val);
 1522|    324|	return r;
 1523|    145|}
card-cac.c:cac_read_file:
  385|  1.04k|{
  386|  1.04k|	u8 params[2];
  387|  1.04k|	u8 count[2] = {0};
  388|  1.04k|	u8 *out = NULL;
  389|  1.04k|	u8 *out_ptr = NULL;
  390|  1.04k|	size_t offset = 0;
  391|  1.04k|	size_t size = 0;
  392|  1.04k|	size_t left = 0;
  393|  1.04k|	size_t len = 0;
  394|  1.04k|	int r;
  395|       |
  396|  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]
  |  |  ------------------
  ------------------
  397|       |
  398|  1.04k|	params[0] = file_type;
  399|  1.04k|	params[1] = 2;
  400|       |
  401|       |	/* get the size */
  402|  1.04k|	len = sizeof(count);
  403|  1.04k|	out_ptr = count;
  404|  1.04k|	r = cac_apdu_io(card, CAC_INS_READ_FILE, 0, 0, &params[0], sizeof(params), &out_ptr, &len);
  ------------------
  |  |   61|  1.04k|#define CAC_INS_READ_FILE             0x52  /* read a TL or V file */
  ------------------
  405|  1.04k|	if (len == 0) {
  ------------------
  |  Branch (405:6): [True: 22, False: 1.02k]
  ------------------
  406|     22|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     22|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  407|     22|	}
  408|  1.04k|	if (r < 0)
  ------------------
  |  Branch (408:6): [True: 248, False: 798]
  ------------------
  409|    248|		goto fail;
  410|       |
  411|    798|	left = size = lebytes2ushort(count);
  412|    798|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    798|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  413|    798|			"got %zu bytes out_ptr=%p count&=%p count[0]=0x%02x count[1]=0x%02x, len=0x%04zx (%zu)",
  414|    798|			len, out_ptr, &count, count[0], count[1], size, size);
  415|    798|	out = out_ptr = malloc(size);
  416|    798|	if (out == NULL) {
  ------------------
  |  Branch (416:6): [True: 0, False: 798]
  ------------------
  417|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  418|      0|		goto fail;
  419|      0|	}
  420|  3.09k|	for (offset += 2; left > 0; offset += len, left -= len, out_ptr += len) {
  ------------------
  |  Branch (420:20): [True: 2.63k, False: 466]
  ------------------
  421|  2.63k|		len = MIN(left, CAC_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  2.63k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 633, False: 1.99k]
  |  |  ------------------
  ------------------
  422|  2.63k|		params[1] = len;
  423|  2.63k|		r = cac_apdu_io(card, CAC_INS_READ_FILE, HIGH_BYTE_OF_SHORT(offset), LOW_BYTE_OF_SHORT(offset),
  ------------------
  |  |   61|  2.63k|#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|  2.63k|#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|  2.63k|#define LOW_BYTE_OF_SHORT(x) ((x) & 0xff)
  ------------------
  424|  2.63k|						&params[0], sizeof(params), &out_ptr, &len);
  425|       |		/* if there is no data, assume there is no file */
  426|  2.63k|		if (len == 0) {
  ------------------
  |  Branch (426:7): [True: 237, False: 2.39k]
  ------------------
  427|    237|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    237|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  428|    237|		}
  429|  2.63k|		if (r < 0) {
  ------------------
  |  Branch (429:7): [True: 332, False: 2.29k]
  ------------------
  430|    332|			goto fail;
  431|    332|		}
  432|  2.63k|	}
  433|    466|	*out_len = size;
  434|    466|	*out_buf = out;
  435|    466|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    466|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    466|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    466|	int _ret = r; \
  |  |  |  |  155|    466|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 466, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    466|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 466]
  |  |  |  |  ------------------
  |  |  |  |  157|    466|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    466|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    466|	return _ret; \
  |  |  |  |  163|    466|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|    580|fail:
  437|    580|	if (out)
  ------------------
  |  Branch (437:6): [True: 332, False: 248]
  ------------------
  438|    332|		free(out);
  439|    580|	*out_len = 0;
  440|    580|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    580|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    580|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    580|	int _ret = r; \
  |  |  |  |  155|    580|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 580, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    580|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    580|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 580, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    580|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    580|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    580|	return _ret; \
  |  |  |  |  163|    580|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  441|    580|}
card-cac.c:cac_parse_CCC:
 1391|    145|{
 1392|    145|	size_t len = 0;
 1393|    145|	const u8 *tl_end = tl + tl_len;
 1394|    145|	const u8 *val_end = val + val_len;
 1395|    145|	sc_path_t new_path;
 1396|    145|	int r;
 1397|       |
 1398|       |
 1399|    832|	for (; (tl < tl_end) && (val< val_end); val += len) {
  ------------------
  |  Branch (1399:9): [True: 815, False: 17]
  |  Branch (1399:26): [True: 811, False: 4]
  ------------------
 1400|       |		/* get the tag and the length */
 1401|    811|		u8 tag;
 1402|    811|		r = sc_simpletlv_read_tag(&tl, tl_end - tl, &tag, &len);
 1403|    811|		if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) {
  ------------------
  |  |   28|  1.62k|#define SC_SUCCESS				0
  ------------------
              		if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) {
  ------------------
  |  |   99|    236|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (1403:7): [True: 236, False: 575]
  |  Branch (1403:26): [True: 17, False: 219]
  ------------------
 1404|     17|			sc_log(card->ctx, "Failed to parse tag from buffer");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1405|     17|			break;
 1406|     17|		}
 1407|    794|		if (val + len > val_end) {
  ------------------
  |  Branch (1407:7): [True: 81, False: 713]
  ------------------
 1408|     81|			sc_log(card->ctx, "Invalid length %zu", len);
  ------------------
  |  |   71|     81|#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|     81|			break;
 1410|     81|		}
 1411|    713|		switch (tag) {
 1412|      7|		case CAC_TAG_CUID:
  ------------------
  |  |   72|      7|#define CAC_TAG_CUID                  0xF0
  ------------------
  |  Branch (1412:3): [True: 7, False: 706]
  ------------------
 1413|      7|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:CUID");
  ------------------
  |  |   70|      7|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1414|      7|			r = cac_parse_cuid(card, priv, (cac_cuid_t *)val, len);
 1415|      7|			if (r < 0)
  ------------------
  |  Branch (1415:8): [True: 2, False: 5]
  ------------------
 1416|      2|				return r;
 1417|      5|			break;
 1418|      5|		case CAC_TAG_CC_VERSION_NUMBER:
  ------------------
  |  |   73|      3|#define CAC_TAG_CC_VERSION_NUMBER     0xF1
  ------------------
  |  Branch (1418:3): [True: 3, False: 710]
  ------------------
 1419|      3|			if (len != 1) {
  ------------------
  |  Branch (1419:8): [True: 1, False: 2]
  ------------------
 1420|      1|				sc_log(card->ctx, "TAG: CC Version: Invalid length %zu", 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__
  |  |  ------------------
  ------------------
 1421|      1|				break;
 1422|      1|			}
 1423|       |			/* ignore the version numbers for now */
 1424|      2|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|      2|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1425|      2|				"TAG: CC Version = 0x%02x", *val);
 1426|      2|			break;
 1427|      9|		case CAC_TAG_GRAMMAR_VERION_NUMBER:
  ------------------
  |  |   74|      9|#define CAC_TAG_GRAMMAR_VERION_NUMBER 0xF2
  ------------------
  |  Branch (1427:3): [True: 9, False: 704]
  ------------------
 1428|      9|			if (len != 1) {
  ------------------
  |  Branch (1428:8): [True: 5, False: 4]
  ------------------
 1429|      5|				sc_log(card->ctx, "TAG: Grammar Version: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1430|      5|				break;
 1431|      5|			}
 1432|       |			/* ignore the version numbers for now */
 1433|      4|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|      4|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1434|      4|				"TAG: Grammar Version = 0x%02x", *val);
 1435|      4|			break;
 1436|     85|		case CAC_TAG_CARDURL:
  ------------------
  |  |   75|     85|#define CAC_TAG_CARDURL               0xF3
  ------------------
  |  Branch (1436:3): [True: 85, False: 628]
  ------------------
 1437|     85|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:CARDURL");
  ------------------
  |  |   70|     85|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1438|     85|			r = cac_parse_cardurl(card, priv, (cac_card_url_t *)val, len);
 1439|     85|			if (r < 0)
  ------------------
  |  Branch (1439:8): [True: 1, False: 84]
  ------------------
 1440|      1|				return r;
 1441|     84|			break;
 1442|       |		/*
 1443|       |		 * The following are really for file systems cards. This code only cares about CAC VM cards
 1444|       |		 */
 1445|     84|		case CAC_TAG_PKCS15:
  ------------------
  |  |   76|      8|#define CAC_TAG_PKCS15                0xF4
  ------------------
  |  Branch (1445:3): [True: 8, False: 705]
  ------------------
 1446|      8|			if (len != 1) {
  ------------------
  |  Branch (1446:8): [True: 7, False: 1]
  ------------------
 1447|      7|				sc_log(card->ctx, "TAG: PKCS15: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1448|      7|				break;
 1449|      7|			}
 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|      1|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: PKCS15 = 0x%02x", *val);
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1454|      1|			break;
 1455|     13|		case CAC_TAG_DATA_MODEL:
  ------------------
  |  |   78|     13|#define CAC_TAG_DATA_MODEL            0xF5
  ------------------
  |  Branch (1455:3): [True: 13, False: 700]
  ------------------
 1456|     13|			if (len != 1) {
  ------------------
  |  Branch (1456:8): [True: 12, False: 1]
  ------------------
 1457|     12|				sc_log(card->ctx, "TAG: Registered Data Model Number: Invalid length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1458|     12|				break;
 1459|     12|			}
 1460|      1|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: Registered Data Model Number (0x%02x)", *val);
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1461|      1|			break;
 1462|      6|		case CAC_TAG_CARD_APDU:
  ------------------
  |  |   79|      6|#define CAC_TAG_CARD_APDU             0xF7
  ------------------
  |  Branch (1462:3): [True: 6, False: 707]
  ------------------
 1463|      7|		case CAC_TAG_CAPABILITY_TUPLES:
  ------------------
  |  |   81|      7|#define CAC_TAG_CAPABILITY_TUPLES     0xFB
  ------------------
  |  Branch (1463:3): [True: 1, False: 712]
  ------------------
 1464|     10|		case CAC_TAG_STATUS_TUPLES:
  ------------------
  |  |   82|     10|#define CAC_TAG_STATUS_TUPLES         0xFC
  ------------------
  |  Branch (1464:3): [True: 3, False: 710]
  ------------------
 1465|     13|		case CAC_TAG_REDIRECTION:
  ------------------
  |  |   80|     13|#define CAC_TAG_REDIRECTION           0xFA
  ------------------
  |  Branch (1465:3): [True: 3, False: 710]
  ------------------
 1466|     18|		case CAC_TAG_ERROR_CODES:
  ------------------
  |  |   84|     18|#define CAC_TAG_ERROR_CODES           0xFE
  ------------------
  |  Branch (1466:3): [True: 5, False: 708]
  ------------------
 1467|     18|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG: FSSpecific(0x%02x)", tag);
  ------------------
  |  |   70|     18|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1468|     18|			break;
 1469|      6|		case CAC_TAG_ACCESS_CONTROL:
  ------------------
  |  |   77|      6|#define CAC_TAG_ACCESS_CONTROL        0xF6
  ------------------
  |  Branch (1469:3): [True: 6, False: 707]
  ------------------
 1470|       |			/* TODO handle access control later */
 1471|      6|			sc_log_hex(card->ctx, "TAG:ACCESS Control", val, len);
  ------------------
  |  |  129|      6|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      6|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1472|      6|			break;
 1473|     30|		case CAC_TAG_NEXT_CCC:
  ------------------
  |  |   83|     30|#define CAC_TAG_NEXT_CCC              0xFD
  ------------------
  |  Branch (1473:3): [True: 30, False: 683]
  ------------------
 1474|     30|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:NEXT CCC");
  ------------------
  |  |   70|     30|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1475|     30|			r = cac_path_from_cardurl(card, &new_path, (cac_card_url_t *)val, len);
 1476|     30|			if (r < 0)
  ------------------
  |  Branch (1476:8): [True: 2, False: 28]
  ------------------
 1477|      2|				return r;
 1478|       |
 1479|     28|			r = cac_select_file_by_type(card, &new_path, NULL);
 1480|     28|			if (r < 0)
  ------------------
  |  Branch (1480:8): [True: 5, False: 23]
  ------------------
 1481|      5|				return r;
 1482|       |
 1483|       |			/* Increase depth to avoid infinite recursion */
 1484|     23|			r = cac_process_CCC(card, priv, depth + 1);
 1485|     23|			if (r < 0)
  ------------------
  |  Branch (1485:8): [True: 16, False: 7]
  ------------------
 1486|     16|				return r;
 1487|      7|			break;
 1488|    534|		default:
  ------------------
  |  Branch (1488:3): [True: 534, False: 179]
  ------------------
 1489|       |			/* ignore tags we don't understand */
 1490|    534|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"TAG:Unknown (0x%02x)",tag );
  ------------------
  |  |   70|    534|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1491|    534|			break;
 1492|    713|		}
 1493|    713|	}
 1494|    119|	return SC_SUCCESS;
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
 1495|    145|}
card-cac.c:cac_parse_cuid:
 1364|      7|{
 1365|      7|	size_t card_id_len;
 1366|       |
 1367|      7|	if (len < sizeof(cac_cuid_t) || len > 256) {
  ------------------
  |  Branch (1367:6): [True: 2, False: 5]
  |  Branch (1367:34): [True: 0, False: 5]
  ------------------
 1368|      2|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1369|      2|	}
 1370|       |
 1371|      5|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "gsc_rid=%s", sc_dump_hex(val->gsc_rid, sizeof(val->gsc_rid)));
  ------------------
  |  |   70|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1372|      5|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "manufacture id=%x", val->manufacturer_id);
  ------------------
  |  |   70|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1373|      5|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "cac_type=%d", val->card_type);
  ------------------
  |  |   70|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1374|      5|	card_id_len = len - (&val->card_id - (u8 *)val);
 1375|      5|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "card_id=%s (%zu)",
  ------------------
  |  |   70|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1376|      5|			sc_dump_hex(&val->card_id, card_id_len), card_id_len);
 1377|      5|	priv->cuid = *val;
 1378|      5|	free(priv->cac_id);
 1379|      5|	priv->cac_id = malloc(card_id_len);
 1380|      5|	if (priv->cac_id == NULL) {
  ------------------
  |  Branch (1380:6): [True: 0, False: 5]
  ------------------
 1381|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1382|      0|	}
 1383|      5|	memcpy(priv->cac_id, &val->card_id, card_id_len);
 1384|      5|	priv->cac_id_len = card_id_len;
 1385|      5|	return SC_SUCCESS;
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
 1386|      5|}
card-cac.c:cac_parse_cardurl:
 1318|     85|{
 1319|     85|	cac_object_t new_object;
 1320|     85|	const cac_object_t *obj;
 1321|     85|	unsigned short object_id;
 1322|     85|	int r;
 1323|       |
 1324|     85|	r = cac_path_from_cardurl(card, &new_object.path, val, len);
 1325|     85|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     85|#define SC_SUCCESS				0
  ------------------
  |  Branch (1325:6): [True: 1, False: 84]
  ------------------
 1326|      1|		return r;
 1327|      1|	}
 1328|     84|	switch (val->cardApplicationType) {
 1329|     60|	case CAC_APP_TYPE_PKI:
  ------------------
  |  |   99|     60|#define CAC_APP_TYPE_PKI              0x04
  ------------------
  |  Branch (1329:2): [True: 60, False: 24]
  ------------------
 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|     60|		if (priv->cert_next >= MAX_CAC_SLOTS)
  ------------------
  |  |   70|     60|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1334:7): [True: 0, False: 60]
  ------------------
 1335|      0|			break; /* don't fail just because we have more certs than we can support */
 1336|     60|		new_object.name = get_cac_label(priv->cert_next);
 1337|     60|		new_object.fd = priv->cert_next+1;
 1338|     60|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: pki_object found, cert_next=%d (%s),", priv->cert_next, new_object.name);
  ------------------
  |  |   70|     60|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1339|     60|		cac_add_object_to_list(&priv->pki_list, &new_object);
 1340|     60|		priv->cert_next++;
 1341|     60|		break;
 1342|     10|	case CAC_APP_TYPE_GENERAL:
  ------------------
  |  |   97|     10|#define CAC_APP_TYPE_GENERAL          0x01
  ------------------
  |  Branch (1342:2): [True: 10, False: 74]
  ------------------
 1343|     10|		object_id = bebytes2ushort(val->objectID);
 1344|     10|		obj = cac_find_obj_by_id(object_id);
 1345|     10|		if (obj == NULL)
  ------------------
  |  Branch (1345:7): [True: 7, False: 3]
  ------------------
 1346|      7|			break; /* don't fail just because we don't recognize the object */
 1347|      3|		new_object.name = obj->name;
 1348|      3|		new_object.fd = 0;
 1349|      3|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: gen_object found, objectID=%x (%s),", object_id, new_object.name);
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1350|      3|		cac_add_object_to_list(&priv->general_list, &new_object);
 1351|      3|		break;
 1352|      1|	case CAC_APP_TYPE_SKI:
  ------------------
  |  |   98|      1|#define CAC_APP_TYPE_SKI              0x02
  ------------------
  |  Branch (1352:2): [True: 1, False: 83]
  ------------------
 1353|      1|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: ski_object 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__
  |  |  ------------------
  ------------------
 1354|      1|	break;
 1355|     13|	default:
  ------------------
  |  Branch (1355:2): [True: 13, False: 71]
  ------------------
 1356|     13|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"CARDURL: unknown object_object found (type=0x%02x)", val->cardApplicationType);
  ------------------
  |  |   70|     13|#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|     13|		break;
 1359|     84|	}
 1360|     84|	return SC_SUCCESS;
  ------------------
  |  |   28|     84|#define SC_SUCCESS				0
  ------------------
 1361|     84|}
card-cac.c:cac_find_obj_by_id:
  216|     10|{
  217|     10|	int i;
  218|       |
  219|     58|	for (i = 0; i < cac_object_count; i++) {
  ------------------
  |  Branch (219:14): [True: 51, False: 7]
  ------------------
  220|     51|		if (cac_objects[i].fd == object_id) {
  ------------------
  |  Branch (220:7): [True: 3, False: 48]
  ------------------
  221|      3|			return &cac_objects[i];
  222|      3|		}
  223|     51|	}
  224|      7|	return NULL;
  225|     10|}
card-cac.c:cac_path_from_cardurl:
 1229|    115|{
 1230|    115|	if (len < 10) {
  ------------------
  |  Branch (1230:6): [True: 3, False: 112]
  ------------------
 1231|      3|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1232|      3|	}
 1233|    112|	sc_mem_clear(path, sizeof(sc_path_t));
 1234|    112|	memcpy(path->aid.value, &val->rid, sizeof(val->rid));
 1235|    112|	memcpy(&path->aid.value[5], val->applicationID, sizeof(val->applicationID));
 1236|    112|	path->aid.len = sizeof(val->rid) + sizeof(val->applicationID);
 1237|    112|	memcpy(path->value, val->objectID, sizeof(val->objectID));
 1238|    112|	path->len = sizeof(val->objectID);
 1239|    112|	path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    112|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1240|    112|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    112|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1241|    112|			"path->aid=%x %x %x %x %x %x %x  len=%zu, path->value = %x %x len=%zu path->type=%d (%x)",
 1242|    112|			path->aid.value[0], path->aid.value[1], path->aid.value[2], path->aid.value[3],
 1243|    112|			path->aid.value[4], path->aid.value[5], path->aid.value[6], path->aid.len,
 1244|    112|			path->value[0], path->value[1], path->len, path->type, path->type);
 1245|    112|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    112|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1246|    112|			"rid=%x %x %x %x %x  len=%zu appid= %x %x len=%zu objid= %x %x len=%zu",
 1247|    112|			val->rid[0], val->rid[1], val->rid[2], val->rid[3], val->rid[4],
 1248|    112|			sizeof(val->rid), val->applicationID[0], val->applicationID[1],
 1249|    112|			sizeof(val->applicationID), val->objectID[0], val->objectID[1], sizeof(val->objectID));
 1250|       |
 1251|    112|	return SC_SUCCESS;
  ------------------
  |  |   28|    112|#define SC_SUCCESS				0
  ------------------
 1252|    115|}
card-cac.c:cac_select_ACA:
 1224|  3.47k|{
 1225|       |	return cac_select_file_by_type(card, &cac_ACA_Path, NULL);
 1226|  3.47k|}
card-cac.c:cac_process_ACA:
 1688|    350|{
 1689|    350|	int r;
 1690|    350|	u8 *val = NULL;
 1691|    350|	size_t val_len;
 1692|       |
 1693|    350|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    350|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    350|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    350|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 350]
  |  |  ------------------
  ------------------
 1694|       |
 1695|       |	/* Assuming ACA is already selected */
 1696|    350|	r = cac_get_acr(card, CAC_ACR_SERVICE, &val, &val_len);
  ------------------
  |  |  104|    350|#define CAC_ACR_SERVICE               0x21
  ------------------
 1697|    350|	if (r < 0)
  ------------------
  |  Branch (1697:6): [True: 74, False: 276]
  ------------------
 1698|     74|		goto done;
 1699|       |
 1700|    276|	r = cac_parse_ACA_service(card, priv, val, val_len);
 1701|    276|        if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    276|#define SC_SUCCESS				0
  ------------------
  |  Branch (1701:13): [True: 187, False: 89]
  ------------------
 1702|    187|		priv->aca_path = malloc(sizeof(sc_path_t));
 1703|    187|		if (!priv->aca_path) {
  ------------------
  |  Branch (1703:7): [True: 0, False: 187]
  ------------------
 1704|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1705|      0|			goto done;
 1706|      0|		}
 1707|    187|		memcpy(priv->aca_path, &cac_ACA_Path, sizeof(sc_path_t));
 1708|    187|	}
 1709|    350|done:
 1710|    350|	if (val)
  ------------------
  |  Branch (1710:6): [True: 276, False: 74]
  ------------------
 1711|    276|		free(val);
 1712|    350|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    350|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    350|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    350|	int _ret = r; \
  |  |  |  |  155|    350|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 350, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    350|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    163|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 163, False: 187]
  |  |  |  |  ------------------
  |  |  |  |  157|    350|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    350|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    350|	return _ret; \
  |  |  |  |  163|    350|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1713|    350|}
card-cac.c:cac_get_acr:
  344|    350|{
  345|    350|	u8 *out = NULL;
  346|       |	/* XXX assuming it will not be longer than 255 B */
  347|    350|	size_t len = 256;
  348|    350|	int r;
  349|       |
  350|    350|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    350|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    350|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    350|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 350]
  |  |  ------------------
  ------------------
  351|       |
  352|       |	/* for simplicity we support only ACR without arguments now */
  353|    350|	if (acr_type != 0x00 && acr_type != 0x10
  ------------------
  |  Branch (353:6): [True: 350, False: 0]
  |  Branch (353:26): [True: 350, False: 0]
  ------------------
  354|    350|	    && acr_type != 0x20 && acr_type != 0x21) {
  ------------------
  |  Branch (354:9): [True: 350, False: 0]
  |  Branch (354:29): [True: 0, False: 350]
  ------------------
  355|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  356|      0|	}
  357|       |
  358|    350|	r = cac_apdu_io(card, CAC_INS_GET_ACR, acr_type, 0, NULL, 0, &out, &len);
  ------------------
  |  |   62|    350|#define CAC_INS_GET_ACR               0x4c
  ------------------
  359|    350|	if (len == 0) {
  ------------------
  |  Branch (359:6): [True: 5, False: 345]
  ------------------
  360|      5|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      5|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  361|      5|	}
  362|    350|	if (r < 0)
  ------------------
  |  Branch (362:6): [True: 74, False: 276]
  ------------------
  363|     74|		goto fail;
  364|       |
  365|    276|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "got %zu bytes out=%p", len, out);
  ------------------
  |  |   70|    276|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  366|       |
  367|    276|	*out_len = len;
  368|    276|	*out_buf = out;
  369|    276|	return SC_SUCCESS;
  ------------------
  |  |   28|    276|#define SC_SUCCESS				0
  ------------------
  370|       |
  371|     74|fail:
  372|     74|	if (out)
  ------------------
  |  Branch (372:6): [True: 5, False: 69]
  ------------------
  373|      5|		free(out);
  374|       |	*out_buf = NULL;
  375|     74|	*out_len = 0;
  376|     74|	return r;
  377|    350|}
card-cac.c:cac_parse_ACA_service:
 1530|    276|{
 1531|    276|	size_t len = 0;
 1532|    276|	const u8 *val_end = val + val_len;
 1533|    276|	int r;
 1534|       |
 1535|    276|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    276|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    276|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    276|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 276]
  |  |  ------------------
  ------------------
 1536|       |
 1537|  7.41k|	for (; val < val_end; val += len) {
  ------------------
  |  Branch (1537:9): [True: 7.37k, False: 32]
  ------------------
 1538|       |		/* get the tag and the length */
 1539|  7.37k|		u8 tag;
 1540|  7.37k|		if (sc_simpletlv_read_tag(&val, val_end - val, &tag, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  7.37k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1540:7): [True: 155, False: 7.22k]
  ------------------
 1541|    155|			break;
 1542|       |
 1543|  7.22k|		switch (tag) {
 1544|  1.58k|		case CAC_TAG_APPLET_FAMILY:
  ------------------
  |  |   85|  1.58k|#define CAC_TAG_APPLET_FAMILY         0x01
  ------------------
  |  Branch (1544:3): [True: 1.58k, False: 5.63k]
  ------------------
 1545|  1.58k|			if (len != 5) {
  ------------------
  |  Branch (1545:8): [True: 1.38k, False: 198]
  ------------------
 1546|  1.38k|				sc_log(card->ctx, "TAG: Applet Information: bad length %zu", len);
  ------------------
  |  |   71|  1.38k|#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|  1.38k|				break;
 1548|  1.38k|			}
 1549|    198|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    198|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1550|    198|			    "TAG: Applet Information: Family: 0x%02x", val[0]);
 1551|    198|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    198|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1552|    198|			    "     Applet Version: 0x%02x 0x%02x 0x%02x 0x%02x",
 1553|    198|			    val[1], val[2], val[3], val[4]);
 1554|    198|			break;
 1555|    207|		case CAC_TAG_NUMBER_APPLETS:
  ------------------
  |  |   86|    207|#define CAC_TAG_NUMBER_APPLETS        0x94
  ------------------
  |  Branch (1555:3): [True: 207, False: 7.01k]
  ------------------
 1556|    207|			if (len != 1) {
  ------------------
  |  Branch (1556:8): [True: 39, False: 168]
  ------------------
 1557|     39|				sc_log(card->ctx, "TAG: Num applets: bad length %zu", len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1558|     39|				break;
 1559|     39|			}
 1560|    168|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    168|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1561|    168|			    "TAG: Num applets = %hhd", *val);
 1562|    168|			break;
 1563|    635|		case CAC_TAG_APPLET_ENTRY:
  ------------------
  |  |   87|    635|#define CAC_TAG_APPLET_ENTRY          0x93
  ------------------
  |  Branch (1563:3): [True: 635, False: 6.58k]
  ------------------
 1564|       |			/* Make sure we match the outer length */
 1565|    635|			if (len < 3 || val[2] != len - 3) {
  ------------------
  |  Branch (1565:8): [True: 72, False: 563]
  |  Branch (1565:19): [True: 61, False: 502]
  ------------------
 1566|    133|				sc_log(card->ctx, "TAG: Applet Entry: bad length (%zu) or length of internal buffer", len);
  ------------------
  |  |   71|    133|#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|    133|				break;
 1568|    133|			}
 1569|    502|			sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|    502|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1570|    502|			    "TAG: Applet Entry: AID", val + 3, val[2]);
 1571|       |			/* This is SimpleTLV prefixed with applet ID (1B) */
 1572|    502|			r = cac_parse_aid(card, priv, val + 3, val[2]);
 1573|    502|			if (r < 0)
  ------------------
  |  Branch (1573:8): [True: 89, False: 413]
  ------------------
 1574|     89|				return r;
 1575|    413|			break;
 1576|  4.79k|		default:
  ------------------
  |  Branch (1576:3): [True: 4.79k, False: 2.42k]
  ------------------
 1577|       |			/* ignore tags we don't understand */
 1578|  4.79k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1579|  4.79k|			    "TAG: Unknown (0x%02x)", tag);
 1580|  4.79k|			break;
 1581|  7.22k|		}
 1582|  7.22k|	}
 1583|    187|	return SC_SUCCESS;
  ------------------
  |  |   28|    187|#define SC_SUCCESS				0
  ------------------
 1584|    276|}
card-cac.c:cac_parse_aid:
 1255|    502|{
 1256|    502|	cac_object_t new_object;
 1257|    502|	cac_properties_t prop = {0};
 1258|    502|	size_t i;
 1259|    502|	int r;
 1260|       |
 1261|    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]
  |  |  ------------------
  ------------------
 1262|       |
 1263|    502|	if (aid_len < 0 || aid_len > SC_MAX_AID_SIZE) {
  ------------------
  |  |   43|    502|#define SC_MAX_AID_SIZE			16
  ------------------
  |  Branch (1263:6): [True: 0, False: 502]
  |  Branch (1263:21): [True: 2, False: 500]
  ------------------
 1264|      2|		sc_log(card->ctx, "AID length too large (%d)", aid_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1265|      2|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1266|      2|	}
 1267|       |
 1268|       |	/* Search for PKI applets (7 B). Ignore generic objects for now */
 1269|    500|	if (aid_len != 7 || (memcmp(aid, CAC_1_RID "\x01", 6) != 0
  ------------------
  |  |   66|    449|#define CAC_1_RID "\xA0\x00\x00\x00\x79"
  ------------------
  |  Branch (1269:6): [True: 51, False: 449]
  |  Branch (1269:23): [True: 347, False: 102]
  ------------------
 1270|    347|	    && memcmp(aid, CAC_1_RID "\x00", 6) != 0))
  ------------------
  |  |   66|    347|#define CAC_1_RID "\xA0\x00\x00\x00\x79"
  ------------------
  |  Branch (1270:9): [True: 240, False: 107]
  ------------------
 1271|    291|		return SC_SUCCESS;
  ------------------
  |  |   28|    291|#define SC_SUCCESS				0
  ------------------
 1272|       |
 1273|    209|	sc_mem_clear(&new_object.path, sizeof(sc_path_t));
 1274|    209|	memcpy(new_object.path.aid.value, aid, aid_len);
 1275|    209|	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|    209|	r = cac_select_file_by_type(card, &new_object.path, NULL);
 1281|    209|	LOG_TEST_RET(card->ctx, r, "Cannot select AID");
  ------------------
  |  |  174|    209|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    209|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    209|	int _ret = (r); \
  |  |  |  |  168|    209|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 86, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  169|     86|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     86|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     86|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     86|		return _ret; \
  |  |  |  |  172|     86|	} \
  |  |  |  |  173|    209|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1282|    123|	r = cac_get_properties(card, &prop);
 1283|    123|	LOG_TEST_RET(card->ctx, r, "Cannot get CAC properties");
  ------------------
  |  |  174|    123|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    123|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    123|	int _ret = (r); \
  |  |  |  |  168|    123|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  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|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1284|       |
 1285|    571|	for (i = 0; i < prop.num_objects; i++) {
  ------------------
  |  Branch (1285:14): [True: 450, False: 121]
  ------------------
 1286|       |		/* don't fail just because we have more certs than we can support */
 1287|    450|		if (priv->cert_next >= MAX_CAC_SLOTS)
  ------------------
  |  |   70|    450|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1287:7): [True: 1, False: 449]
  ------------------
 1288|      1|			return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1289|       |
 1290|    449|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    449|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1291|    449|		    "ACA: pki_object found, cert_next=%d (%s), privkey=%d",
 1292|    449|		    priv->cert_next, get_cac_label(priv->cert_next),
 1293|    449|		    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|    449|		if (!prop.objects[i].privatekey) {
  ------------------
  |  Branch (1299:7): [True: 383, False: 66]
  ------------------
 1300|    383|			priv->cert_next++;
 1301|    383|			continue;
 1302|    383|		}
 1303|       |
 1304|       |		/* OID here has always 2B */
 1305|     66|		memcpy(new_object.path.value, &prop.objects[i].oid, 2);
 1306|     66|		new_object.path.len = 2;
 1307|     66|		new_object.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     66|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1308|     66|		new_object.name = get_cac_label(priv->cert_next);
 1309|     66|		new_object.fd = priv->cert_next+1;
 1310|     66|		cac_add_object_to_list(&priv->pki_list, &new_object);
 1311|     66|		priv->cert_next++;
 1312|     66|	}
 1313|       |
 1314|    121|	return SC_SUCCESS;
  ------------------
  |  |   28|    121|#define SC_SUCCESS				0
  ------------------
 1315|    122|}
card-cac.c:cac_find_first_pki_applet:
 1598|  3.18k|{
 1599|  3.18k|	int r, i;
 1600|  49.3k|	for (i = 0; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  49.3k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1600:14): [True: 46.5k, False: 2.81k]
  ------------------
 1601|  46.5k|		r = cac_select_pki_applet(card, i);
 1602|  46.5k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  46.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1602:7): [True: 615, False: 45.9k]
  ------------------
 1603|       |			/* Try to read first two bytes of the buffer to
 1604|       |			 * make sure it is not just malfunctioning card
 1605|       |			 */
 1606|    615|			u8 params[2] = {CAC_FILE_TAG, 2};
  ------------------
  |  |   66|    615|#define CAC_FILE_TAG    1
  ------------------
 1607|    615|			u8 data[2], *out_ptr = data;
 1608|    615|			size_t len = 2;
 1609|    615|			r = cac_apdu_io(card, CAC_INS_READ_FILE, 0, 0,
  ------------------
  |  |   61|    615|#define CAC_INS_READ_FILE             0x52  /* read a TL or V file */
  ------------------
 1610|    615|			    &params[0], sizeof(params), &out_ptr, &len);
 1611|    615|			if (r != 2)
  ------------------
  |  Branch (1611:8): [True: 248, False: 367]
  ------------------
 1612|    248|				continue;
 1613|       |
 1614|    367|			*index_out = i;
 1615|    367|			return SC_SUCCESS;
  ------------------
  |  |   28|    367|#define SC_SUCCESS				0
  ------------------
 1616|    615|		}
 1617|  46.5k|	}
 1618|  2.81k|	return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  2.81k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1619|  3.18k|}
card-cac.c:cac_select_pki_applet:
 1588|  48.8k|{
 1589|  48.8k|	sc_path_t applet_path = cac_cac_pki_obj.path;
 1590|  48.8k|	applet_path.aid.value[applet_path.aid.len-1] = index;
 1591|       |	return cac_select_file_by_type(card, &applet_path, NULL);
 1592|  48.8k|}
card-cac.c:cac_populate_cac_alt:
 1625|    159|{
 1626|    159|	int r, i;
 1627|    159|	cac_object_t pki_obj = cac_cac_pki_obj;
 1628|    159|	u8 buf[100];
 1629|    159|	u8 *val;
 1630|       |
 1631|       |	/* populate PKI objects */
 1632|  2.28k|	for (i = index; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  2.28k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (1632:18): [True: 2.12k, False: 159]
  ------------------
 1633|  2.12k|		r = cac_select_pki_applet(card, i);
 1634|  2.12k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.12k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1634:7): [True: 981, False: 1.14k]
  ------------------
 1635|    981|			pki_obj.name = get_cac_label(i);
 1636|    981|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    981|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1637|    981|			    "CAC: pki_object found, cert_next=%d (%s),", i, pki_obj.name);
 1638|    981|			pki_obj.path.aid.value[pki_obj.path.aid.len-1] = i;
 1639|    981|			pki_obj.fd = i+1; /* don't use id of zero */
 1640|    981|			cac_add_object_to_list(&priv->pki_list, &pki_obj);
 1641|    981|		}
 1642|  2.12k|	}
 1643|       |
 1644|       |	/* populate non-PKI objects */
 1645|  1.11k|	for (i=0; i < cac_object_count; i++) {
  ------------------
  |  Branch (1645:12): [True: 954, False: 159]
  ------------------
 1646|    954|		r = cac_select_file_by_type(card, &cac_objects[i].path, NULL);
 1647|    954|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    954|#define SC_SUCCESS				0
  ------------------
  |  Branch (1647:7): [True: 343, False: 611]
  ------------------
 1648|    343|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|    343|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1649|    343|			    "CAC: obj_object found, cert_next=%d (%s),",
 1650|    343|			    i, cac_objects[i].name);
 1651|    343|			cac_add_object_to_list(&priv->general_list, &cac_objects[i]);
 1652|    343|		}
 1653|    954|	}
 1654|       |
 1655|       |	/*
 1656|       |	 * create a cuid to simulate the cac 2 cuid.
 1657|       |	 */
 1658|    159|	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|    159|	r = cac_select_pki_applet(card, index);
 1662|    159|	if (r < 0) {
  ------------------
  |  Branch (1662:6): [True: 47, False: 112]
  ------------------
 1663|     47|		return r; /* shouldn't happen unless the card has been removed or is malfunctioning */
 1664|     47|	}
 1665|    112|	val = buf;
 1666|    112|	r = cac_read_binary(card, 0, val, sizeof(buf), 0);
 1667|    112|	if (r > 0) {
  ------------------
  |  Branch (1667:6): [True: 0, False: 112]
  ------------------
 1668|      0|#ifdef ENABLE_OPENSSL
 1669|      0|		size_t val_len = r;
 1670|      0|		free(priv->cac_id);
 1671|      0|		priv->cac_id = malloc(20);
 1672|      0|		if (priv->cac_id == NULL) {
  ------------------
  |  Branch (1672:7): [True: 0, False: 0]
  ------------------
 1673|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1674|      0|		}
 1675|      0|		SHA1(val, val_len, priv->cac_id);
 1676|      0|		priv->cac_id_len = 20;
 1677|      0|		sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|      0|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1678|      0|		    "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|      0|	}
 1684|    112|	return SC_SUCCESS;
  ------------------
  |  |   28|    112|#define SC_SUCCESS				0
  ------------------
 1685|    112|}
card-cac.c:cac_init:
 1806|    727|{
 1807|    727|	int r;
 1808|    727|	unsigned long flags;
 1809|       |
 1810|    727|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    727|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    727|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    727|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 727]
  |  |  ------------------
  ------------------
 1811|       |
 1812|    727|	r = cac_find_and_initialize(card, 1);
 1813|    727|	if (r < 0) {
  ------------------
  |  Branch (1813:6): [True: 316, False: 411]
  ------------------
 1814|    316|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    316|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    316|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    316|	int _ret = r; \
  |  |  |  |  155|    316|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 316, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    316|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    316|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 316, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    316|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    316|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    316|	return _ret; \
  |  |  |  |  163|    316|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1815|    316|	}
 1816|    411|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    411|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 1817|       |
 1818|    411|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 1819|    411|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 1820|    411|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 1821|       |
 1822|    411|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    411|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    411|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1823|       |
 1824|    411|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    411|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    411|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    411|	int _ret = r; \
  |  |  |  |  155|    411|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 411, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    411|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 411]
  |  |  |  |  ------------------
  |  |  |  |  157|    411|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    411|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    411|	return _ret; \
  |  |  |  |  163|    411|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1825|    411|}
card-cac.c:cac_finish:
 1205|    411|{
 1206|    411|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    411|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
 1207|       |
 1208|    411|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    411|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    411|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    411|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 411]
  |  |  ------------------
  ------------------
 1209|    411|	if (priv) {
  ------------------
  |  Branch (1209:6): [True: 411, False: 0]
  ------------------
 1210|    411|		cac_free_private_data(priv);
 1211|    411|	}
 1212|    411|	return SC_SUCCESS;
  ------------------
  |  |   28|    411|#define SC_SUCCESS				0
  ------------------
 1213|    411|}
card-cac.c:cac_select_file:
 1200|  2.20k|{
 1201|  2.20k|	return cac_select_file_by_type(card, in_path, file_out);
 1202|  2.20k|}
card-cac.c:cac_read_binary:
  451|    458|{
  452|    458|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    458|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  453|    458|	int r = 0;
  454|    458|	u8 *tl = NULL, *val = NULL;
  455|    458|	const u8 *tl_ptr, *val_ptr, *tl_start;
  456|    458|	u8 *tlv_ptr;
  457|    458|	const u8 *cert_ptr;
  458|    458|	size_t tl_len = 0, val_len = 0, tlv_len;
  459|    458|	size_t len, tl_head_len, cert_len;
  460|    458|	u8 cert_type, tag;
  461|       |
  462|    458|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    458|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    458|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    458|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 458]
  |  |  ------------------
  ------------------
  463|       |
  464|       |	/* if we didn't return it all last time, return the remainder */
  465|    458|	if (priv->cached) {
  ------------------
  |  Branch (465:6): [True: 0, False: 458]
  ------------------
  466|      0|		sc_log(card->ctx, "returning cached value idx=%d count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  467|      0|		if (idx > priv->cache_buf_len) {
  ------------------
  |  Branch (467:7): [True: 0, False: 0]
  ------------------
  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|      0|		len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  471|      0|		memcpy(buf, &priv->cache_buf[idx], len);
  472|      0|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|      0|	}
  474|       |
  475|    458|	sc_log(card->ctx, "clearing cache idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|    458|#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|    458|	if (priv->cache_buf) {
  ------------------
  |  Branch (476:6): [True: 0, False: 458]
  ------------------
  477|      0|		free(priv->cache_buf);
  478|      0|		priv->cache_buf = NULL;
  479|      0|		priv->cache_buf_len = 0;
  480|      0|	}
  481|       |
  482|       |
  483|    458|	if (priv->object_type <= 0)
  ------------------
  |  Branch (483:6): [True: 0, False: 458]
  ------------------
  484|    458|		 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|    458|	r = cac_read_file(card, CAC_FILE_TAG, &tl, &tl_len);
  ------------------
  |  |   66|    458|#define CAC_FILE_TAG    1
  ------------------
  487|    458|	if (r < 0)  {
  ------------------
  |  Branch (487:6): [True: 352, False: 106]
  ------------------
  488|    352|		goto done;
  489|    352|	}
  490|       |
  491|    106|	r = cac_read_file(card, CAC_FILE_VALUE, &val, &val_len);
  ------------------
  |  |   67|    106|#define CAC_FILE_VALUE  2
  ------------------
  492|    106|	if (r < 0)
  ------------------
  |  Branch (492:6): [True: 49, False: 57]
  ------------------
  493|     49|		goto done;
  494|       |
  495|     57|	switch (priv->object_type) {
  496|      0|	case CAC_OBJECT_TYPE_TLV_FILE:
  ------------------
  |  |  171|      0|#define CAC_OBJECT_TYPE_TLV_FILE	4
  ------------------
  |  Branch (496:2): [True: 0, False: 57]
  ------------------
  497|      0|		tlv_len = tl_len + val_len;
  498|      0|		priv->cache_buf = malloc(tlv_len);
  499|      0|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (499:7): [True: 0, False: 0]
  ------------------
  500|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  501|      0|			goto done;
  502|      0|		}
  503|      0|		priv->cache_buf_len = tlv_len;
  504|       |
  505|      0|		for (tl_ptr = tl, val_ptr = val, tlv_ptr = priv->cache_buf;
  506|      0|				tl_len >= 2 && tlv_len > 0;
  ------------------
  |  Branch (506:5): [True: 0, False: 0]
  |  Branch (506:20): [True: 0, False: 0]
  ------------------
  507|      0|				val_len -= len, tlv_len -= len, val_ptr += len, tlv_ptr += len) {
  508|       |			/* get the tag and the length */
  509|      0|			tl_start = tl_ptr;
  510|      0|			r = sc_simpletlv_read_tag(&tl_ptr, tl_len, &tag, &len);
  511|      0|			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   99|      0|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (511:8): [True: 0, False: 0]
  |  Branch (511:27): [True: 0, False: 0]
  ------------------
  512|      0|				break;
  513|      0|			tl_head_len = (tl_ptr - tl_start);
  514|      0|			sc_simpletlv_put_tag(tag, len, tlv_ptr, tlv_len, &tlv_ptr);
  515|      0|			tlv_len -= tl_head_len;
  516|      0|			tl_len -= tl_head_len;
  517|       |
  518|       |			/* don't crash on bad data */
  519|      0|			if (val_len < len) {
  ------------------
  |  Branch (519:8): [True: 0, False: 0]
  ------------------
  520|      0|				sc_log(card->ctx, "Received too long value %zu, while only %zu left. Truncating",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  521|      0|						len, val_len);
  522|      0|				len = val_len;
  523|      0|			}
  524|       |			/* if we run out of return space, truncate */
  525|      0|			if (tlv_len < len) {
  ------------------
  |  Branch (525:8): [True: 0, False: 0]
  ------------------
  526|      0|				len = tlv_len;
  527|      0|			}
  528|      0|			memcpy(tlv_ptr, val_ptr, len);
  529|      0|		}
  530|       |		/* fixup the cache_buf_le to reflect for the bad data ignored above */
  531|      0|		priv->cache_buf_len = (tlv_ptr - priv->cache_buf);
  532|      0|		break;
  533|       |
  534|     54|	case CAC_OBJECT_TYPE_CERT:
  ------------------
  |  |  170|     54|#define CAC_OBJECT_TYPE_CERT		1
  ------------------
  |  Branch (534:2): [True: 54, False: 3]
  ------------------
  535|       |		/* read file */
  536|     54|		sc_log(card->ctx, " obj= cert_file, val_len=%zu (0x%04zx)", val_len, val_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  537|     54|		cert_len = 0;
  538|     54|		cert_ptr = NULL;
  539|     54|		cert_type = 0;
  540|    476|		for (tl_ptr = tl, val_ptr = val; tl_len >= 2;
  ------------------
  |  Branch (540:36): [True: 449, False: 27]
  ------------------
  541|    449|		    val_len -= len, val_ptr += len, tl_len -= tl_head_len) {
  542|    449|			tl_start = tl_ptr;
  543|    449|			r = sc_simpletlv_read_tag(&tl_ptr, tl_len, &tag, &len);
  544|    449|			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   28|    898|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS)
  ------------------
  |  |   99|     22|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (544:8): [True: 22, False: 427]
  |  Branch (544:27): [True: 3, False: 19]
  ------------------
  545|      3|				break;
  546|    446|			tl_head_len = tl_ptr - tl_start;
  547|       |
  548|       |			/* incomplete value */
  549|    446|			if (val_len < len) {
  ------------------
  |  Branch (549:8): [True: 24, False: 422]
  ------------------
  550|     24|				sc_log(card->ctx, "Read incomplete value %zu, while only %zu left",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  551|     24|						len, val_len);
  552|     24|				break;
  553|     24|			}
  554|       |
  555|    422|			if (tag == CAC_TAG_CERTIFICATE) {
  ------------------
  |  |   69|    422|#define CAC_TAG_CERTIFICATE           0x70
  ------------------
  |  Branch (555:8): [True: 10, False: 412]
  ------------------
  556|     10|				cert_len = len;
  557|     10|				cert_ptr = val_ptr;
  558|     10|			}
  559|    422|			if (tag == CAC_TAG_CERTINFO) {
  ------------------
  |  |   70|    422|#define CAC_TAG_CERTINFO              0x71
  ------------------
  |  Branch (559:8): [True: 4, False: 418]
  ------------------
  560|      4|				if ((len >= 1) && (val_len >=1)) {
  ------------------
  |  Branch (560:9): [True: 0, False: 4]
  |  Branch (560:23): [True: 0, False: 0]
  ------------------
  561|      0|					cert_type = *val_ptr;
  562|      0|				}
  563|      4|			}
  564|    422|			if (tag == CAC_TAG_MSCUID) {
  ------------------
  |  |   71|    422|#define CAC_TAG_MSCUID                0x72
  ------------------
  |  Branch (564:8): [True: 3, False: 419]
  ------------------
  565|      3|				sc_log_hex(card->ctx, "MSCUID", val_ptr, len);
  ------------------
  |  |  129|      3|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      3|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|      3|			}
  567|    422|		}
  568|       |		/* if the info byte is 1, then the cert is compressed, decompress it */
  569|     54|		if ((cert_type & 0x3) == 1 && flags) {
  ------------------
  |  Branch (569:7): [True: 0, False: 54]
  |  Branch (569:33): [True: 0, False: 0]
  ------------------
  570|      0|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|      0|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  571|      0|		}
  572|     54|		if (cert_len > 0) {
  ------------------
  |  Branch (572:7): [True: 0, False: 54]
  ------------------
  573|      0|			priv->cache_buf = malloc(cert_len);
  574|      0|			if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (574:8): [True: 0, False: 0]
  ------------------
  575|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  576|      0|				goto done;
  577|      0|			}
  578|      0|			priv->cache_buf_len = cert_len;
  579|      0|			memcpy(priv->cache_buf, cert_ptr, cert_len);
  580|     54|		} else {
  581|     54|			sc_log(card->ctx, "Can't read zero-length certificate");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  582|     54|			goto done;
  583|     54|		}
  584|      0|		break;
  585|      3|	case CAC_OBJECT_TYPE_GENERIC:
  ------------------
  |  |  172|      3|#define CAC_OBJECT_TYPE_GENERIC		5
  ------------------
  |  Branch (585:2): [True: 3, False: 54]
  ------------------
  586|       |		/* TODO
  587|       |		 * We have some two buffers in unknown encoding that we
  588|       |		 * need to present in PKCS#15 layer.
  589|       |		 */
  590|      3|	default:
  ------------------
  |  Branch (590:2): [True: 0, False: 57]
  ------------------
  591|       |		/* Unknown object type */
  592|      3|		sc_log(card->ctx, "Unknown object type: %x", priv->object_type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  593|      3|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
  594|      3|		goto done;
  595|     57|	}
  596|       |
  597|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
  598|      0|	priv->cached = 1;
  599|      0|	len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  600|      0|	memcpy(buf, &priv->cache_buf[idx], len);
  601|      0|	r = (int)len;
  602|    458|done:
  603|    458|	if (tl)
  ------------------
  |  Branch (603:6): [True: 106, False: 352]
  ------------------
  604|    106|		free(tl);
  605|    458|	if (val)
  ------------------
  |  Branch (605:6): [True: 57, False: 401]
  ------------------
  606|     57|		free(val);
  607|    458|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    458|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    458|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    458|	int _ret = r; \
  |  |  |  |  155|    458|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 458, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    458|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    426|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 426, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|    458|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    458|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    458|	return _ret; \
  |  |  |  |  163|    458|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|    458|}
card-cac.c:cac_card_ctl:
  673|  5.60k|{
  674|  5.60k|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|  5.60k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  675|       |
  676|  5.60k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.60k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.60k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.60k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|  5.60k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  5.60k|#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|  5.60k|	if (priv == NULL) {
  ------------------
  |  Branch (679:6): [True: 0, False: 5.60k]
  ------------------
  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|  5.60k|	switch(cmd) {
  ------------------
  |  Branch (682:9): [True: 5.35k, False: 255]
  ------------------
  683|    531|		case SC_CARDCTL_CAC_GET_ACA_PATH:
  ------------------
  |  Branch (683:3): [True: 531, False: 5.07k]
  ------------------
  684|    531|			return cac_get_ACA_path(card, (sc_path_t *) ptr);
  685|    531|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (685:3): [True: 531, False: 5.07k]
  ------------------
  686|    531|			return cac_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
  687|    531|		case SC_CARDCTL_CAC_INIT_GET_GENERIC_OBJECTS:
  ------------------
  |  Branch (687:3): [True: 531, False: 5.07k]
  ------------------
  688|    531|			return cac_get_init_and_get_count(&priv->general_list, &priv->general_current, (int *)ptr);
  689|    531|		case SC_CARDCTL_CAC_INIT_GET_CERT_OBJECTS:
  ------------------
  |  Branch (689:3): [True: 531, False: 5.07k]
  ------------------
  690|    531|			return cac_get_init_and_get_count(&priv->pki_list, &priv->pki_current, (int *)ptr);
  691|    289|		case SC_CARDCTL_CAC_GET_NEXT_GENERIC_OBJECT:
  ------------------
  |  Branch (691:3): [True: 289, False: 5.31k]
  ------------------
  692|    289|			return cac_fill_object_info(&priv->general_list, &priv->general_current, (sc_pkcs15_data_info_t *)ptr);
  693|  1.87k|		case SC_CARDCTL_CAC_GET_NEXT_CERT_OBJECT:
  ------------------
  |  Branch (693:3): [True: 1.87k, False: 3.73k]
  ------------------
  694|  1.87k|			return cac_fill_object_info(&priv->pki_list, &priv->pki_current, (sc_pkcs15_data_info_t *)ptr);
  695|    531|		case SC_CARDCTL_CAC_FINAL_GET_GENERIC_OBJECTS:
  ------------------
  |  Branch (695:3): [True: 531, False: 5.07k]
  ------------------
  696|    531|			return cac_final_iterator(&priv->general_list);
  697|    531|		case SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS:
  ------------------
  |  Branch (697:3): [True: 531, False: 5.07k]
  ------------------
  698|    531|			return cac_final_iterator(&priv->pki_list);
  699|  5.60k|	}
  700|       |
  701|    255|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|    255|}
card-cac.c:cac_get_ACA_path:
  662|    531|{
  663|    531|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    531|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  664|       |
  665|    531|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    531|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    531|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    531|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    531|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|    531|	if (priv->aca_path) {
  ------------------
  |  Branch (666:6): [True: 184, False: 347]
  ------------------
  667|    184|		*path = *priv->aca_path;
  668|    184|	}
  669|    531|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    531|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    531|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    531|	int _ret = r; \
  |  |  |  |  155|    531|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 531, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    531|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  157|    531|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    531|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    531|	return _ret; \
  |  |  |  |  163|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  670|    531|}
card-cac.c:cac_get_serial_nr_from_CUID:
  645|    531|{
  646|    531|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    531|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  647|       |
  648|    531|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    531|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    531|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    531|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    531|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  649|    531|        if (card->serialnr.len)   {
  ------------------
  |  Branch (649:13): [True: 0, False: 531]
  ------------------
  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|    531|	if (priv->cac_id_len) {
  ------------------
  |  Branch (653:6): [True: 69, False: 462]
  ------------------
  654|     69|		serial->len = MIN(priv->cac_id_len, SC_MAX_SERIALNR);
  ------------------
  |  |   70|     69|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 68, False: 1]
  |  |  ------------------
  ------------------
  655|     69|		memcpy(serial->value, priv->cac_id, serial->len);
  656|     69|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  657|     69|	}
  658|    462|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  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|    462|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 462, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  659|    462|}
card-cac.c:cac_get_init_and_get_count:
  612|  1.06k|{
  613|  1.06k|	*countp = list_size(list);
  614|  1.06k|	list_iterator_start(list);
  615|  1.06k|	*entry = list_iterator_next(list);
  616|  1.06k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.06k|#define SC_SUCCESS				0
  ------------------
  617|  1.06k|}
card-cac.c:cac_fill_object_info:
  628|  2.16k|{
  629|  2.16k|	memset(obj_info, 0, sizeof(sc_pkcs15_data_info_t));
  630|  2.16k|	if (*entry == NULL) {
  ------------------
  |  Branch (630:6): [True: 0, False: 2.16k]
  ------------------
  631|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  632|      0|	}
  633|       |
  634|  2.16k|	obj_info->path = (*entry)->path;
  635|  2.16k|	obj_info->path.count = CAC_MAX_SIZE-1; /* read something from the object */
  ------------------
  |  |   26|  2.16k|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
  636|  2.16k|	obj_info->id.value[0] = ((*entry)->fd >> 8) & 0xff;
  637|  2.16k|	obj_info->id.value[1] = (*entry)->fd & 0xff;
  638|  2.16k|	obj_info->id.len = 2;
  639|  2.16k|	strncpy(obj_info->app_label, (*entry)->name, SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|  2.16k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  640|  2.16k|	*entry = list_iterator_next(list);
  641|  2.16k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.16k|#define SC_SUCCESS				0
  ------------------
  642|  2.16k|}
card-cac.c:cac_final_iterator:
  621|  1.06k|{
  622|  1.06k|	list_iterator_stop(list);
  623|  1.06k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.06k|#define SC_SUCCESS				0
  ------------------
  624|  1.06k|}
card-cac.c:cac_pin_cmd:
 1834|     48|{
 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|     48|	sc_apdu_t apdu;
 1841|     48|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1842|     48|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1843|     48|	int rv;
 1844|       |
 1845|     48|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|     48|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1845:6): [True: 10, False: 38]
  ------------------
 1846|     10|		size_t i = 0;
 1847|     10|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (1847:7): [True: 1, False: 9]
  ------------------
 1848|      1|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      1|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1849|      1|		}
 1850|     49|		for(i=0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (1850:12): [True: 44, False: 5]
  ------------------
 1851|     44|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (1851:8): [True: 4, False: 40]
  ------------------
 1852|      4|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1853|      4|			}
 1854|     44|		}
 1855|       |
 1856|       |		/* We can change the PIN of Giesecke & Devrient CAC ALT tokens
 1857|       |		 * with a bit non-standard APDU */
 1858|      5|		if (card->type == SC_CARD_TYPE_CAC_ALT_HID) {
  ------------------
  |  Branch (1858:7): [True: 4, False: 1]
  ------------------
 1859|      4|			int r = 0;
 1860|      4|			r = iso7816_build_pin_apdu(card, &apdu, data, sbuf, sizeof(sbuf));
 1861|      4|			if (r < 0)
  ------------------
  |  Branch (1861:8): [True: 0, False: 4]
  ------------------
 1862|      0|				return r;
 1863|       |			/* it requires P1 = 0x01 completely against the ISO specs */
 1864|      4|			apdu.p1 = 0x01;
 1865|      4|			data->apdu = &apdu;
 1866|      4|		}
 1867|      5|	}
 1868|       |
 1869|     43|	rv = iso_drv->ops->pin_cmd(card, data);
 1870|       |
 1871|       |	data->apdu = NULL;
 1872|     43|	return rv;
 1873|     48|}

sc_get_cac1_driver:
  554|  8.50k|{
  555|  8.50k|	return sc_get_driver();
  556|  8.50k|}
card-cac1.c:sc_get_driver:
  536|  8.50k|{
  537|       |	/* Inherit most of the things from the CAC driver */
  538|  8.50k|	struct sc_card_driver *cac_drv = sc_get_cac_driver();
  539|       |
  540|  8.50k|	cac_ops = *cac_drv->ops;
  541|  8.50k|	cac_ops.match_card = cac_match_card;
  542|  8.50k|	cac_ops.init = cac_init;
  543|  8.50k|	cac_ops.finish = cac_finish;
  544|       |
  545|  8.50k|	cac_ops.select_file =  cac_select_file; /* need to record object type */
  546|  8.50k|	cac_ops.read_binary = cac_read_binary;
  547|  8.50k|	cac_ops.logout = cac_logout;
  548|       |
  549|  8.50k|	return &cac1_drv;
  550|  8.50k|}
card-cac1.c:cac_match_card:
  489|  2.05k|{
  490|  2.05k|	int r;
  491|  2.05k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.05k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.05k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.05k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.05k]
  |  |  ------------------
  ------------------
  492|       |
  493|  2.05k|	r = cac_find_and_initialize(card, 0);
  494|  2.05k|	return (r == SC_SUCCESS); /* never match */
  ------------------
  |  |   28|  2.05k|#define SC_SUCCESS				0
  ------------------
  495|  2.05k|}
card-cac1.c:cac_find_and_initialize:
  451|  2.21k|{
  452|  2.21k|	int r, index;
  453|  2.21k|	cac_private_data_t *priv = NULL;
  454|       |
  455|       |	/* already initialized? */
  456|  2.21k|	if (card->drv_data) {
  ------------------
  |  Branch (456:6): [True: 0, False: 2.21k]
  ------------------
  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.21k|	r = cac_find_first_pki_applet(card, &index);
  462|  2.21k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.21k|#define SC_SUCCESS				0
  ------------------
  |  Branch (462:6): [True: 303, False: 1.90k]
  ------------------
  463|    303|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "PKI applet found, is bare CAC-1");
  ------------------
  |  |   70|    303|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|    303|		if (!initialize) /* match card only */
  ------------------
  |  Branch (464:7): [True: 155, False: 148]
  ------------------
  465|    155|			return r;
  466|       |
  467|    148|		if (!priv) {
  ------------------
  |  Branch (467:7): [True: 148, False: 0]
  ------------------
  468|    148|			priv = cac_new_private_data();
  469|    148|			if (!priv)
  ------------------
  |  Branch (469:8): [True: 0, False: 148]
  ------------------
  470|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  471|    148|		}
  472|    148|		card->drv_data = priv; /* needed for the read_binary() */
  473|    148|		r = cac_populate_cac1(card, index, priv);
  474|    148|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    148|#define SC_SUCCESS				0
  ------------------
  |  Branch (474:7): [True: 125, False: 23]
  ------------------
  475|    125|			card->type = SC_CARD_TYPE_CAC_I;
  476|    125|			return r;
  477|    125|		}
  478|     23|		card->drv_data = NULL; /* reset on failure */
  479|     23|	}
  480|  1.93k|	if (priv) {
  ------------------
  |  Branch (480:6): [True: 23, False: 1.90k]
  ------------------
  481|     23|		cac_free_private_data(priv);
  482|     23|	}
  483|  1.93k|	return r;
  484|  2.21k|}
card-cac1.c:cac_find_first_pki_applet:
  365|  2.21k|{
  366|  2.21k|	int r, i;
  367|       |
  368|  33.5k|	for (i = 0; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  33.5k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (368:14): [True: 31.6k, False: 1.90k]
  ------------------
  369|  31.6k|		r = cac_select_pki_applet(card, i);
  370|  31.6k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  31.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (370:7): [True: 388, False: 31.2k]
  ------------------
  371|    388|			u8 data[2];
  372|    388|			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|    388|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2,
  ------------------
  |  |  301|    388|#define SC_APDU_CASE_2			0x22
  ------------------
  378|    388|				CAC_INS_GET_CERTIFICATE, 0x00, 0x00);
  ------------------
  |  |   59|    388|#define CAC_INS_GET_CERTIFICATE       0x36  /* CAC1 command to read a certificate */
  ------------------
  379|    388|			apdu.le = 0x02;
  380|    388|			apdu.resplen = 2;
  381|    388|			apdu.resp = data;
  382|    388|			r = sc_transmit_apdu(card, &apdu);
  383|       |			/* SW1 = 0x63 means more data in CAC1 */
  384|    388|			if (r == SC_SUCCESS && apdu.sw1 != 0x63)
  ------------------
  |  |   28|    776|#define SC_SUCCESS				0
  ------------------
  |  Branch (384:8): [True: 94, False: 294]
  |  Branch (384:27): [True: 85, False: 9]
  ------------------
  385|     85|				continue;
  386|       |
  387|    303|			*index_out = i;
  388|    303|			return SC_SUCCESS;
  ------------------
  |  |   28|    303|#define SC_SUCCESS				0
  ------------------
  389|    388|		}
  390|  31.6k|	}
  391|  1.90k|	return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  1.90k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  392|  2.21k|}
card-cac1.c:cac_select_pki_applet:
  355|  33.7k|{
  356|  33.7k|	sc_path_t applet_path = cac_cac_pki_obj.path;
  357|  33.7k|	applet_path.aid.value[applet_path.aid.len-1] = index;
  358|       |	return cac_select_file_by_type(card, &applet_path, NULL);
  359|  33.7k|}
card-cac1.c:cac_select_file_by_type:
  201|  35.0k|{
  202|  35.0k|	struct sc_context *ctx;
  203|  35.0k|	struct sc_apdu apdu;
  204|  35.0k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  205|  35.0k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  206|  35.0k|	int r, pathtype;
  207|  35.0k|	size_t pathlen;
  208|  35.0k|	struct sc_file *file = NULL;
  209|  35.0k|	cac_private_data_t *priv;
  210|       |
  211|  35.0k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (211:6): [True: 0, False: 35.0k]
  |  Branch (211:22): [True: 0, False: 35.0k]
  ------------------
  212|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  213|       |
  214|  35.0k|	ctx = card->ctx;
  215|  35.0k|	priv = CAC_DATA(card);
  ------------------
  |  |   61|  35.0k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  216|       |
  217|  35.0k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  35.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  35.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  35.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 35.0k]
  |  |  ------------------
  ------------------
  218|       |
  219|  35.0k|	memcpy(path, in_path->value, in_path->len);
  220|  35.0k|	pathlen = in_path->len;
  221|  35.0k|	pathtype = in_path->type;
  222|       |
  223|  35.0k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  35.0k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  224|  35.0k|		"path=%s, path->value=%s path->type=%d (%x)",
  225|  35.0k|		sc_print_path(in_path),
  226|  35.0k|		sc_dump_hex(in_path->value, in_path->len),
  227|  35.0k|		in_path->type, in_path->type);
  228|  35.0k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "file_out=%p index=%d count=%d\n",
  ------------------
  |  |   70|  35.0k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  229|  35.0k|		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|  35.0k|	if ((pathlen > 2) && (pathlen <= 4) && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (236:6): [True: 369, False: 34.6k]
  |  Branch (236:23): [True: 369, False: 0]
  |  Branch (236:41): [True: 369, False: 0]
  ------------------
  237|    369|		path += 2;
  238|    369|		pathlen -= 2;
  239|    369|	}
  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|  35.0k|	if (priv) { /* don't record anything if we haven't been initialized yet */
  ------------------
  |  Branch (246:6): [True: 3.43k, False: 31.6k]
  ------------------
  247|       |		/* forget any old cached values */
  248|  3.43k|		if (priv->cache_buf) {
  ------------------
  |  Branch (248:7): [True: 189, False: 3.24k]
  ------------------
  249|    189|			free(priv->cache_buf);
  250|    189|			priv->cache_buf = NULL;
  251|    189|		}
  252|  3.43k|		priv->cache_buf_len = 0;
  253|  3.43k|		priv->cached = 0;
  254|  3.43k|	}
  255|       |
  256|  35.0k|	if (in_path->aid.len) {
  ------------------
  |  Branch (256:6): [True: 34.6k, False: 369]
  ------------------
  257|  34.6k|		if (!pathlen) {
  ------------------
  |  Branch (257:7): [True: 34.6k, False: 0]
  ------------------
  258|  34.6k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  259|  34.6k|			pathlen = in_path->aid.len;
  260|  34.6k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  34.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  261|  34.6k|		} 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|  34.6k|	}
  277|       |
  278|  35.0k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  35.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  279|       |
  280|  35.0k|	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: 35.0k]
  ------------------
  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|  34.6k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  34.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (289:2): [True: 34.6k, False: 369]
  ------------------
  290|  34.6k|		apdu.p1 = 4;
  291|  34.6k|		break;
  292|    369|	default:
  ------------------
  |  Branch (292:2): [True: 369, False: 34.6k]
  ------------------
  293|    369|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    369|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    369|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    369|	int _ret = r; \
  |  |  |  |  155|    369|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 369, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    369|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    369|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 369, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    369|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    369|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    369|	return _ret; \
  |  |  |  |  163|    369|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|  35.0k|	}
  295|  34.6k|	apdu.lc = pathlen;
  296|  34.6k|	apdu.data = path;
  297|  34.6k|	apdu.datalen = pathlen;
  298|  34.6k|	apdu.resp = buf;
  299|  34.6k|	apdu.resplen = sizeof(buf);
  300|  34.6k|	apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (300:12): [True: 0, False: 34.6k]
  ------------------
  301|  34.6k|	apdu.p2 = 0x00;
  302|       |
  303|  34.6k|	r = sc_transmit_apdu(card, &apdu);
  304|  34.6k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  34.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  34.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  34.6k|	int _ret = (r); \
  |  |  |  |  168|  34.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 419, False: 34.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|    419|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    419|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    419|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    419|		return _ret; \
  |  |  |  |  172|    419|	} \
  |  |  |  |  173|  34.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|  34.2k|	if (file_out == NULL) {
  ------------------
  |  Branch (306:6): [True: 33.2k, False: 980]
  ------------------
  307|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  308|  33.2k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  309|  33.2k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (309:7): [True: 158, False: 33.1k]
  |  Branch (309:27): [True: 68, False: 90]
  ------------------
  310|     68|			apdu.p2 = 0x00;
  311|     68|			apdu.resplen = sizeof(buf);
  312|     68|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  |  Branch (312:8): [True: 64, False: 4]
  ------------------
  313|     64|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  314|     68|		}
  315|  33.2k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (315:7): [True: 4, False: 33.2k]
  ------------------
  316|  33.2k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|  33.2k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  33.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  33.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  33.2k|	int _ret = r; \
  |  |  |  |  155|  33.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 33.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  33.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|  31.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31.7k, False: 1.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  33.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  33.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|  33.2k|	return _ret; \
  |  |  |  |  163|  33.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|  33.2k|	}
  319|       |
  320|    980|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  321|    980|	if (r)
  ------------------
  |  Branch (321:6): [True: 669, False: 311]
  ------------------
  322|    980|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    669|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    669|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    669|	int _ret = r; \
  |  |  |  |  155|    669|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 669, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    669|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    669|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 669, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    669|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    669|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    669|	return _ret; \
  |  |  |  |  163|    669|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|       |	/* CAC cards never return FCI, fake one */
  325|    311|	file = sc_file_new();
  326|    311|	if (file == NULL)
  ------------------
  |  Branch (326:6): [True: 0, False: 311]
  ------------------
  327|    311|			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|    311|	file->path = *in_path;
  329|    311|	file->size = CAC_MAX_SIZE; /* we don't know how big, just give a large size until we can read the file */
  ------------------
  |  |   26|    311|#define CAC_MAX_SIZE 4096		/* arbitrary, just needs to be 'large enough' */
  ------------------
  330|       |
  331|    311|	*file_out = file;
  332|    311|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 311]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  333|       |
  334|    311|}
card-cac1.c:cac_populate_cac1:
  395|    148|{
  396|    148|	int r, i;
  397|    148|	cac_object_t pki_obj = cac_cac_pki_obj;
  398|    148|	u8 buf[100];
  399|    148|	u8 *val;
  400|    148|	size_t val_len;
  401|       |
  402|       |	/* populate PKI objects */
  403|  2.07k|	for (i = index; i < MAX_CAC_SLOTS; i++) {
  ------------------
  |  |   70|  2.07k|#define MAX_CAC_SLOTS 16		/* Maximum number of slots is 16 now */
  ------------------
  |  Branch (403:18): [True: 1.92k, False: 148]
  ------------------
  404|  1.92k|		r = cac_select_pki_applet(card, i);
  405|  1.92k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.92k|#define SC_SUCCESS				0
  ------------------
  |  Branch (405:7): [True: 1.02k, False: 899]
  ------------------
  406|  1.02k|			pki_obj.name = get_cac_label(i);
  407|  1.02k|			sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  1.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  408|  1.02k|				"CAC: pki_object found, cert_next=%d (%s)",
  409|  1.02k|				i, pki_obj.name);
  410|  1.02k|			pki_obj.path.aid.value[pki_obj.path.aid.len-1] = i;
  411|  1.02k|			pki_obj.fd = i+1; /* don't use id of zero */
  412|  1.02k|			cac_add_object_to_list(&priv->pki_list, &pki_obj);
  413|  1.02k|		}
  414|  1.92k|	}
  415|       |
  416|       |	/*
  417|       |	 * create a cuid to simulate the cac 2 cuid.
  418|       |	 */
  419|    148|	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|    148|	r = cac_select_pki_applet(card, index);
  423|    148|	if (r < 0) {
  ------------------
  |  Branch (423:6): [True: 23, False: 125]
  ------------------
  424|     23|		return r; /* shouldn't happen unless the card has been removed or is malfunctioning */
  425|     23|	}
  426|    125|	val = buf;
  427|    125|	val_len = sizeof(buf);
  428|    125|	r = cac_cac1_get_certificate(card, &val, &val_len);
  429|    125|	if (r >= 0) {
  ------------------
  |  Branch (429:6): [True: 67, False: 58]
  ------------------
  430|     67|		priv->cac_id = malloc(20);
  431|     67|		if (priv->cac_id == NULL) {
  ------------------
  |  Branch (431:7): [True: 0, False: 67]
  ------------------
  432|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  433|      0|		}
  434|     67|#ifdef ENABLE_OPENSSL
  435|     67|		SHA1(val, val_len, priv->cac_id);
  436|     67|		priv->cac_id_len = 20;
  437|     67|		sc_debug_hex(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  127|     67|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  438|     67|			"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|     67|	}
  444|    125|	return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
  445|    125|}
card-cac1.c:cac_cac1_get_certificate:
   65|    436|{
   66|    436|	u8 buf[CAC_MAX_SIZE];
   67|    436|	u8 *out_ptr;
   68|    436|	size_t size = 0;
   69|    436|	size_t left = 0;
   70|    436|	size_t len;
   71|    436|	sc_apdu_t apdu;
   72|    436|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    436|#define SC_SUCCESS				0
  ------------------
   73|    436|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    436|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    436|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    436|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 436]
  |  |  ------------------
  ------------------
   74|       |	/* get the size */
   75|    436|	size = left = *out_buf ? *out_len : sizeof(buf);
  ------------------
  |  Branch (75:16): [True: 125, False: 311]
  ------------------
   76|    436|	out_ptr = *out_buf ? *out_buf : buf;
  ------------------
  |  Branch (76:12): [True: 125, False: 311]
  ------------------
   77|    436|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, CAC_INS_GET_CERTIFICATE, 0, 0 );
  ------------------
  |  |  292|    436|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
              	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, CAC_INS_GET_CERTIFICATE, 0, 0 );
  ------------------
  |  |   59|    436|#define CAC_INS_GET_CERTIFICATE       0x36  /* CAC1 command to read a certificate */
  ------------------
   78|    436|	len = MIN(left, 100);
  ------------------
  |  |   70|    436|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 436]
  |  |  ------------------
  ------------------
   79|    463|	while (left > 0) {
  ------------------
  |  Branch (79:9): [True: 456, False: 7]
  ------------------
   80|    456|		apdu.resp = out_ptr;
   81|    456|		apdu.le = len;
   82|    456|		apdu.resplen = left;
   83|    456|		r = sc_transmit_apdu(card, &apdu);
   84|    456|		if (r < 0) {
  ------------------
  |  Branch (84:7): [True: 53, False: 403]
  ------------------
   85|     53|			break;
   86|     53|		}
   87|    403|		if (apdu.resplen == 0) {
  ------------------
  |  Branch (87:7): [True: 57, False: 346]
  ------------------
   88|     57|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     57|#define SC_ERROR_INTERNAL			-1400
  ------------------
   89|     57|			break;
   90|     57|		}
   91|       |		/* in the old CAC-1, 0x63 means 'more data' in addition to 'pin failed' */
   92|    346|		if (apdu.sw1 != 0x63 || apdu.sw2 < 1)  {
  ------------------
  |  Branch (92:7): [True: 312, False: 34]
  |  Branch (92:27): [True: 7, False: 27]
  ------------------
   93|       |			/* we've either finished reading, or hit an error, break */
   94|    319|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   95|    319|			left -= apdu.resplen;
   96|    319|			break;
   97|    319|		}
   98|       |		/* Adjust the lengths */
   99|     27|		left -= apdu.resplen;
  100|     27|		out_ptr += apdu.resplen;
  101|     27|		len = MIN(left, apdu.sw2);
  ------------------
  |  |   70|     27|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 11, False: 16]
  |  |  ------------------
  ------------------
  102|     27|	}
  103|    436|	if (r < 0) {
  ------------------
  |  Branch (103:6): [True: 157, False: 279]
  ------------------
  104|    157|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    157|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    157|	int _ret = r; \
  |  |  155|    157|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 157, False: 0]
  |  |  ------------------
  |  |  156|    157|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  ------------------
  |  |  157|    157|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    157|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    157|	return _ret; \
  |  |  163|    157|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  105|    157|	}
  106|    279|	r = (int)(size - left);
  107|    279|	if (*out_buf == NULL) {
  ------------------
  |  Branch (107:6): [True: 212, False: 67]
  ------------------
  108|    212|		*out_buf = malloc(r);
  109|    212|		if (*out_buf == NULL) {
  ------------------
  |  Branch (109:7): [True: 0, False: 212]
  ------------------
  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|    212|		memcpy(*out_buf, buf, r);
  114|    212|	}
  115|    279|	*out_len = r;
  116|    279|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    279|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    279|	int _ret = r; \
  |  |  155|    279|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 279]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"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|    279|	return _ret; \
  |  |  163|    279|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  117|    279|}
card-cac1.c:cac_init:
  499|    155|{
  500|    155|	int r;
  501|    155|	unsigned long flags;
  502|       |
  503|    155|	SC_FUNC_CALLED(card->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]
  |  |  ------------------
  ------------------
  504|       |
  505|    155|	r = cac_find_and_initialize(card, 1);
  506|    155|	if (r < 0) {
  ------------------
  |  Branch (506:6): [True: 30, False: 125]
  ------------------
  507|     30|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|     30|	}
  509|    125|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    125|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  510|       |
  511|    125|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
  512|    125|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
  513|    125|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
  514|       |
  515|    125|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    125|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    125|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  516|       |
  517|    125|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  518|    125|}
card-cac1.c:cac_finish:
  342|    125|{
  343|    125|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|    125|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  344|       |
  345|    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]
  |  |  ------------------
  ------------------
  346|    125|	if (priv) {
  ------------------
  |  Branch (346:6): [True: 125, False: 0]
  ------------------
  347|    125|		cac_free_private_data(priv);
  348|    125|	}
  349|    125|	return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
  350|    125|}
card-cac1.c:cac_select_file:
  337|  1.35k|{
  338|  1.35k|	return cac_select_file_by_type(card, in_path, file_out);
  339|  1.35k|}
card-cac1.c:cac_read_binary:
  126|  1.46k|{
  127|  1.46k|	cac_private_data_t * priv = CAC_DATA(card);
  ------------------
  |  |   61|  1.46k|#define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
  ------------------
  128|  1.46k|	int r = 0;
  129|  1.46k|	u8 *val = NULL;
  130|  1.46k|	u8 *cert_ptr;
  131|  1.46k|	size_t val_len = 0;
  132|  1.46k|	size_t len, cert_len;
  133|  1.46k|	u8 cert_type;
  134|       |
  135|  1.46k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.46k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.46k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.46k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.46k]
  |  |  ------------------
  ------------------
  136|       |
  137|       |	/* if we didn't return it all last time, return the remainder */
  138|  1.46k|	if (priv->cached) {
  ------------------
  |  Branch (138:6): [True: 1.15k, False: 311]
  ------------------
  139|  1.15k|		sc_log(card->ctx, "returning cached value idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
  140|  1.15k|		if (idx > priv->cache_buf_len) {
  ------------------
  |  Branch (140:7): [True: 0, False: 1.15k]
  ------------------
  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.15k|		len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   70|  1.15k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 907, False: 247]
  |  |  ------------------
  ------------------
  144|  1.15k|		memcpy(buf, &priv->cache_buf[idx], len);
  145|  1.15k|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  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: 157, False: 997]
  |  |  |  |  ------------------
  |  |  |  |  156|    157|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 157]
  |  |  |  |  ------------------
  |  |  |  |  157|    157|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    997|	} else { \
  |  |  |  |  159|    997|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    997|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    997|	} \
  |  |  |  |  162|  1.15k|	return _ret; \
  |  |  |  |  163|  1.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|  1.15k|	}
  147|       |
  148|    311|	sc_log(card->ctx, "clearing cache idx=%d count=%zu", idx, count);
  ------------------
  |  |   71|    311|#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|    311|	free(priv->cache_buf);
  150|    311|	priv->cache_buf = NULL;
  151|    311|	priv->cache_buf_len = 0;
  152|       |
  153|    311|	r = cac_cac1_get_certificate(card, &val, &val_len);
  154|    311|	if (r < 0)
  ------------------
  |  Branch (154:6): [True: 99, False: 212]
  ------------------
  155|     99|		goto done;
  156|    212|	if (val_len < 1) {
  ------------------
  |  Branch (156:6): [True: 0, False: 212]
  ------------------
  157|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  158|      0|		goto done;
  159|      0|	}
  160|       |
  161|    212|	cert_type = val[0];
  162|    212|	cert_ptr = val + 1;
  163|    212|	cert_len = val_len - 1;
  164|       |
  165|       |	/* if the info byte is 1, then the cert is compressed, decompress it */
  166|    212|	if ((cert_type & 0x3) == 1) {
  ------------------
  |  Branch (166:6): [True: 88, False: 124]
  ------------------
  167|     88|		if (flags)
  ------------------
  |  Branch (167:7): [True: 88, False: 0]
  ------------------
  168|     88|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     88|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  169|     88|	}
  170|    212|	if (cert_len > 0) {
  ------------------
  |  Branch (170:6): [True: 211, False: 1]
  ------------------
  171|    211|		priv->cache_buf = malloc(cert_len);
  172|    211|		if (priv->cache_buf == NULL) {
  ------------------
  |  Branch (172:7): [True: 0, False: 211]
  ------------------
  173|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  174|      0|			goto done;
  175|      0|		}
  176|    211|		priv->cache_buf_len = cert_len;
  177|    211|		memcpy(priv->cache_buf, cert_ptr, cert_len);
  178|    211|	}
  179|       |
  180|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
  181|    212|	priv->cached = 1;
  182|    212|	len = MIN(count, priv->cache_buf_len-idx);
  ------------------
  |  |   70|    212|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 90, False: 122]
  |  |  ------------------
  ------------------
  183|    212|	if (len && priv->cache_buf)
  ------------------
  |  Branch (183:6): [True: 211, False: 1]
  |  Branch (183:13): [True: 211, False: 0]
  ------------------
  184|    211|		memcpy(buf, &priv->cache_buf[idx], len);
  185|    212|	r = (int)len;
  186|    311|done:
  187|    311|	if (val)
  ------------------
  |  Branch (187:6): [True: 212, False: 99]
  ------------------
  188|    212|		free(val);
  189|    311|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 100, False: 211]
  |  |  |  |  ------------------
  |  |  |  |  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|     99|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 99, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|    100|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    211|	} else { \
  |  |  |  |  159|    211|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    211|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    211|	} \
  |  |  |  |  162|    311|	return _ret; \
  |  |  |  |  163|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  190|    311|}

sc_get_cardos_driver:
 1566|  8.50k|{
 1567|  8.50k|	return sc_get_driver();
 1568|  8.50k|}
card-cardos.c:sc_get_driver:
 1541|  8.50k|{
 1542|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1542:6): [True: 1, False: 8.49k]
  ------------------
 1543|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1544|  8.50k|	cardos_ops = *iso_ops;
 1545|  8.50k|	cardos_ops.match_card = cardos_match_card;
 1546|  8.50k|	cardos_ops.init = cardos_init;
 1547|  8.50k|	cardos_ops.finish = cardos_finish;
 1548|  8.50k|	cardos_ops.select_file = cardos_select_file;
 1549|  8.50k|	cardos_ops.create_file = cardos_create_file;
 1550|  8.50k|	cardos_ops.set_security_env = cardos_set_security_env;
 1551|  8.50k|	cardos_ops.restore_security_env = cardos_restore_security_env;
 1552|  8.50k|	cardos_ops.compute_signature = cardos_compute_signature;
 1553|  8.50k|	cardos_ops.decipher = cardos_decipher;
 1554|       |
 1555|  8.50k|	cardos_ops.list_files = cardos_list_files;
 1556|  8.50k|	cardos_ops.check_sw = cardos_check_sw;
 1557|  8.50k|	cardos_ops.card_ctl = cardos_card_ctl;
 1558|  8.50k|	cardos_ops.pin_cmd = cardos_pin_cmd;
 1559|  8.50k|	cardos_ops.logout  = cardos_logout;
 1560|       |
 1561|  8.50k|	return &cardos_drv;
 1562|  8.50k|}
card-cardos.c:cardos_match_card:
   76|  8.10k|{
   77|  8.10k|	unsigned char atr[SC_MAX_ATR_SIZE] = {0};
   78|  8.10k|	int i;
   79|       |
   80|  8.10k|	i = _sc_match_atr(card, cardos_atrs, &card->type);
   81|  8.10k|	if (i < 0)
  ------------------
  |  Branch (81:6): [True: 7.68k, False: 419]
  ------------------
   82|  7.68k|		return 0;
   83|       |
   84|    419|	memcpy(atr, card->atr.value, card->atr.len);
   85|       |
   86|       |	/* Do not change card type for CIE! */
   87|    419|	if (card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (87:6): [True: 0, False: 419]
  ------------------
   88|      0|		return 1;
   89|    419|	if (card->type == SC_CARD_TYPE_CARDOS_M4_4)
  ------------------
  |  Branch (89:6): [True: 0, False: 419]
  ------------------
   90|      0|		return 1;
   91|    419|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0)
  ------------------
  |  Branch (91:6): [True: 0, False: 419]
  ------------------
   92|      0|		return 1;
   93|    419|	if (card->type == SC_CARD_TYPE_CARDOS_V5_3)
  ------------------
  |  Branch (93:6): [True: 403, False: 16]
  ------------------
   94|    403|		return 1;
   95|     16|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (95:6): [True: 16, False: 0]
  ------------------
   96|     16|		int rv;
   97|     16|		sc_apdu_t apdu = {0};
   98|     16|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = {0};
   99|       |		/* first check some additional ATR bytes */
  100|     16|		if ((atr[4] != 0xff && atr[4] != 0x02) ||
  ------------------
  |  Branch (100:8): [True: 15, False: 1]
  |  Branch (100:26): [True: 7, False: 8]
  ------------------
  101|      9|		    (atr[6] != 0x10 && atr[6] != 0x0a) ||
  ------------------
  |  Branch (101:8): [True: 6, False: 3]
  |  Branch (101:26): [True: 3, False: 3]
  ------------------
  102|      6|		    (atr[9] != 0x55 && atr[9] != 0x58))
  ------------------
  |  Branch (102:8): [True: 5, False: 1]
  |  Branch (102:26): [True: 4, False: 1]
  ------------------
  103|     14|			return 0;
  104|       |		/* get the os version using GET DATA and compare it with
  105|       |		 * version in the ATR */
  106|      2|		sc_log(card->ctx,  "checking cardos version ...");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  107|      2|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x82);
  ------------------
  |  |  292|      2|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  108|      2|		apdu.resp = rbuf;
  109|      2|		apdu.resplen = sizeof(rbuf);
  110|      2|		apdu.le = 256;
  111|      2|		apdu.lc = 0;
  112|      2|		rv = sc_transmit_apdu(card, &apdu);
  113|      2|		LOG_TEST_RET(card->ctx, rv, "APDU transmit 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|      2|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || apdu.resplen < 2)
  ------------------
  |  Branch (114:7): [True: 2, False: 0]
  |  Branch (114:27): [True: 0, False: 0]
  |  Branch (114:47): [True: 0, False: 0]
  ------------------
  115|      2|			return 0;
  116|      0|		if (apdu.resp[0] != atr[10] ||
  ------------------
  |  Branch (116:7): [True: 0, False: 0]
  ------------------
  117|      0|		    apdu.resp[1] != atr[11])
  ------------------
  |  Branch (117:7): [True: 0, False: 0]
  ------------------
  118|       |			/* version mismatch */
  119|      0|			return 0;
  120|      0|		if (atr[11] <= 0x04) {
  ------------------
  |  Branch (120:7): [True: 0, False: 0]
  ------------------
  121|      0|			sc_log(card->ctx,  "found cardos m4.01");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  122|      0|			card->type = SC_CARD_TYPE_CARDOS_M4_01;
  123|      0|		} else if (atr[11] == 0x08) {
  ------------------
  |  Branch (123:14): [True: 0, False: 0]
  ------------------
  124|      0|			sc_log(card->ctx,  "found cardos v4.3b");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  125|      0|			card->type = SC_CARD_TYPE_CARDOS_M4_3;
  126|      0|		} else if (atr[11] == 0x09) {
  ------------------
  |  Branch (126:14): [True: 0, False: 0]
  ------------------
  127|      0|			sc_log(card->ctx,  "found cardos v4.2b");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  128|      0|			card->type = SC_CARD_TYPE_CARDOS_M4_2B;
  129|      0|		} else if (atr[11] >= 0x0B) {
  ------------------
  |  Branch (129:14): [True: 0, False: 0]
  ------------------
  130|      0|			sc_log(card->ctx,  "found cardos v4.2c or higher");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  131|      0|			card->type = SC_CARD_TYPE_CARDOS_M4_2C;
  132|      0|		} else {
  133|      0|			sc_log(card->ctx,  "found cardos m4.2");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  134|      0|		}
  135|      0|	}
  136|      0|	return 1;
  137|     16|}
card-cardos.c:cardos_init:
  212|    403|{
  213|    403|	cardos_data_t * priv = NULL;
  214|    403|	unsigned long flags = 0;
  215|    403|	size_t data_field_length;
  216|    403|	sc_apdu_t apdu;
  217|    403|	u8 rbuf[2];
  218|    403|	int r;
  219|       |
  220|    403|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    403|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    403|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    403|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 403]
  |  |  ------------------
  ------------------
  221|       |
  222|    403|	priv = calloc(1, sizeof(cardos_data_t));
  223|    403|	if (!priv)
  ------------------
  |  Branch (223:6): [True: 0, False: 403]
  ------------------
  224|    403|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  225|    403|	card->drv_data = priv;
  226|       |
  227|    403|	card->name = "Atos CardOS";
  228|    403|	card->cla = 0x00;
  229|       |
  230|       |	/* let user override flags and type from opensc.conf */
  231|       |	/* user can override card->type too.*/
  232|    403|	if (card->flags) {
  ------------------
  |  Branch (232:6): [True: 0, False: 403]
  ------------------
  233|      0|	    flags = card->flags;
  234|    403|	} else {
  235|       |
  236|       |		/* Set up algorithm info. */
  237|    403|		flags = 0;
  238|    403|		if (card->type == SC_CARD_TYPE_CARDOS_V5_0) {
  ------------------
  |  Branch (238:7): [True: 0, False: 403]
  ------------------
  239|      0|			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 */
  |  |  ------------------
  ------------------
  240|    403|		} else if(card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (240:13): [True: 403, False: 0]
  ------------------
  241|    403|			flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    403|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  242|    403|				| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|    403|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    403|				| SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    403|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|    403|		} else {
  245|      0|			flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  246|      0|				| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  247|      0|				| SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|      0|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  248|      0|				| SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  249|      0|		}
  250|    403|	}
  251|       |
  252|    403|	priv->flags = flags;
  253|       |
  254|    403|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (254:6): [True: 0, False: 403]
  ------------------
  255|      0|		r = cardos_have_2048bit_package(card);
  256|      0|		if (r < 0) {
  ------------------
  |  Branch (256:7): [True: 0, False: 0]
  ------------------
  257|      0|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  258|      0|			goto err;
  259|      0|		}
  260|      0|		if (r == 1)
  ------------------
  |  Branch (260:7): [True: 0, False: 0]
  ------------------
  261|      0|			priv->rsa_2048 = 1;
  262|      0|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      0|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  263|    403|	} else if (card->type == SC_CARD_TYPE_CARDOS_M4_3
  ------------------
  |  Branch (263:13): [True: 0, False: 403]
  ------------------
  264|    403|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2B
  ------------------
  |  Branch (264:6): [True: 0, False: 403]
  ------------------
  265|    403|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2C
  ------------------
  |  Branch (265:6): [True: 0, False: 403]
  ------------------
  266|    403|		|| card->type == SC_CARD_TYPE_CARDOS_M4_4
  ------------------
  |  Branch (266:6): [True: 0, False: 403]
  ------------------
  267|    403|		|| card->type == SC_CARD_TYPE_CARDOS_V5_0
  ------------------
  |  Branch (267:6): [True: 0, False: 403]
  ------------------
  268|    403|		|| card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (268:6): [True: 403, False: 0]
  ------------------
  269|    403|		priv->rsa_2048 = 1;
  270|    403|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    403|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  271|       |		/* TODO check this. EC only if in supported_algo */
  272|    403|		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    403|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    403|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  273|    403|	}
  274|       |
  275|       |	/* probe DATA FIELD LENGTH with GET DATA */
  276|    403|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x8D);
  ------------------
  |  |  292|    403|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  277|    403|	apdu.le = sizeof rbuf;
  278|    403|	apdu.resp = rbuf;
  279|    403|	apdu.resplen = sizeof(rbuf);
  280|       |
  281|    403|	r = sc_transmit_apdu(card, &apdu);
  282|    403|	if (r < 0)
  ------------------
  |  Branch (282:6): [True: 1, False: 402]
  ------------------
  283|    403|		LOG_TEST_GOTO_ERR(card->ctx,
  ------------------
  |  |  184|      1|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      1|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      1|	int _ret = (r); \
  |  |  |  |  178|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      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
  |  |  |  |  ------------------
  |  |  |  |  180|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      1|		goto err; \
  |  |  |  |  182|      1|	} \
  |  |  |  |  183|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  284|    402|				SC_ERROR_INVALID_CARD,
  285|    402|				"APDU transmit failed");
  286|    402|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  287|    402|	if (r < 0)
  ------------------
  |  Branch (287:6): [True: 20, False: 382]
  ------------------
  288|    402|		LOG_TEST_GOTO_ERR(card->ctx,
  ------------------
  |  |  184|     20|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     20|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     20|	int _ret = (r); \
  |  |  |  |  178|     20|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  289|    382|				SC_ERROR_INVALID_CARD,
  290|    382|				"GET DATA command returned error");
  291|    382|	if (apdu.resplen != 2) {
  ------------------
  |  Branch (291:6): [True: 2, False: 380]
  ------------------
  292|      2|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      2|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  293|      2|		goto err;
  294|      2|	}
  295|    380|	data_field_length = ((rbuf[0] << 8) | rbuf[1]);
  296|       |
  297|       |	/* TODO is this really needed? strip the length of possible Lc and Le bytes */
  298|       |
  299|       |	/* Use Min card sizes and reader too. for V5_3 at least*/
  300|       |
  301|    380|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (301:6): [True: 0, False: 380]
  |  Branch (301:48): [True: 380, False: 0]
  ------------------
  302|    380|		sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|    380|#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)
  |  |  ------------------
  |  |  |  |  305|    380|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  |  |  |  |  306|    380|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  |  |  |  |  ------------------
  |  |  |  |  |  |  547|    380|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|    380|				"data_field_length:%zu card->reader->max_send_size:%zu "
  304|    380|				"card->reader->max_recv_size:%zu %s",
  305|    380|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  306|    380|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  307|       |
  308|    380|		if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  547|    380|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (308:7): [True: 380, False: 0]
  ------------------
  309|    380|			card->max_send_size  = data_field_length - 6;
  310|       |#ifdef _WIN32
  311|       |			/* Windows does not support PCSC PART_10 and may have forced reader to 255/256
  312|       |			 * https://github.com/OpenSC/OpenSC/commit/eddea6f3c2d3dafc2c09eba6695c745a61b5186f
  313|       |			 * may have reset this. if so, will override and force extended
  314|       |			 * Most, if not all, cardos cards do extended, but not chaining
  315|       |			 */
  316|       |			if (card->reader->max_send_size == 255 && card->reader->max_recv_size == 256) {
  317|       |				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "resetting reader to use data_field_length");
  318|       |				card->reader->max_send_size = data_field_length - 6;
  319|       |				card->reader->max_recv_size = data_field_length - 3;
  320|       |			}
  321|       |#endif
  322|    380|		} else
  323|      0|			card->max_send_size = data_field_length - 3;
  324|       |
  325|    380|		card->max_send_size = sc_get_max_send_size(card); /* include reader sizes and protocol */
  326|    380|		card->max_recv_size = data_field_length - 2;
  327|    380|		card->max_recv_size = sc_get_max_recv_size(card);
  328|    380|	} else {
  329|       |		/* old way, disregards reader capabilities */
  330|      0|		if (card->caps & SC_CARD_CAP_APDU_EXT)
  ------------------
  |  |  547|      0|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (330:7): [True: 0, False: 0]
  ------------------
  331|      0|			card->max_send_size = data_field_length - 6;
  332|      0|		else
  333|      0|			card->max_send_size = data_field_length - 3;
  334|       |		/* strip the length of SW bytes */
  335|      0|		card->max_recv_size = data_field_length - 2;
  336|      0|	}
  337|       |
  338|       |	/*for new cards, wait till after sc_pkcs15_bind_internal reads tokeninfo */
  339|    380|	if (card->type != SC_CARD_TYPE_CARDOS_V5_0 && card->type != SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (339:6): [True: 380, False: 0]
  |  Branch (339:48): [True: 0, False: 380]
  ------------------
  340|      0|		r = cardos_add_algs(card, flags, 0, 0);
  341|      0|	}
  342|       |
  343|    403|err:
  344|    403|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    403|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:6): [True: 23, False: 380]
  ------------------
  345|     23|		free(priv);
  346|     23|		card->drv_data = NULL;
  347|     23|	}
  348|       |
  349|    403|	return r;
  350|    380|}
card-cardos.c:cardos_add_algs:
  179|      4|{
  180|       |
  181|      4|	cardos_data_t * priv = (cardos_data_t *)card->drv_data;
  182|       |
  183|      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]
  |  |  ------------------
  ------------------
  184|       |
  185|      4|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  186|      4|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  187|      4|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|      4|	if (priv->rsa_2048 == 1) {
  ------------------
  |  Branch (188:6): [True: 4, False: 0]
  ------------------
  189|      4|		_sc_card_add_rsa_alg(card, 1280, flags, 0);
  190|      4|		_sc_card_add_rsa_alg(card, 1536, flags, 0);
  191|      4|		_sc_card_add_rsa_alg(card, 1792, flags, 0);
  192|      4|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  193|      4|	}
  194|       |
  195|      4|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (195:6): [True: 0, False: 4]
  |  Branch (195:48): [True: 4, False: 0]
  ------------------
  196|       |		/* Starting with CardOS 5, the card supports PIN query commands */
  197|      4|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|      4|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  198|      4|		_sc_card_add_rsa_alg(card, 3072, flags, 0);
  199|      4|		_sc_card_add_rsa_alg(card, 4096, flags, 0);
  200|      4|	}
  201|       |
  202|       |	/* TODO need to get sizes from supported_algos too */
  203|      4|	if (ec_flags != 0) {
  ------------------
  |  Branch (203:6): [True: 0, False: 4]
  ------------------
  204|      0|		 _sc_card_add_ec_alg(card, 256, ec_flags, priv->ext_flags, NULL);
  205|      0|		 _sc_card_add_ec_alg(card, 384, ec_flags, priv->ext_flags, NULL);
  206|      0|	}
  207|       |
  208|      4|	return 0;
  209|      4|}
card-cardos.c:cardos_finish:
  377|    380|{
  378|    380|	int r = 0;
  379|       |
  380|    380|	if (card == NULL )
  ------------------
  |  Branch (380:6): [True: 0, False: 380]
  ------------------
  381|      0|		return 0;
  382|       |
  383|    380|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    380|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    380|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    380|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 380]
  |  |  ------------------
  ------------------
  384|       |
  385|       |	/* free priv data */
  386|    380|	if (card->drv_data) { /* priv */
  ------------------
  |  Branch (386:6): [True: 380, False: 0]
  ------------------
  387|    380|		free(card->drv_data);
  388|    380|		card->drv_data = NULL;
  389|    380|	}
  390|       |
  391|    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: 380, False: 0]
  |  |  ------------------
  |  |  156|    380|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 380]
  |  |  ------------------
  |  |  157|    380|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    380|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    380|	return _ret; \
  |  |  163|    380|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  392|    380|}
card-cardos.c:cardos_select_file:
  634|  2.38k|{
  635|  2.38k|	int r;
  636|       |
  637|  2.38k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.38k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.38k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.38k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.38k]
  |  |  ------------------
  ------------------
  638|  2.38k|	r = iso_ops->select_file(card, in_path, file);
  639|  2.38k|	if (r >= 0 && file)
  ------------------
  |  Branch (639:6): [True: 586, False: 1.79k]
  |  Branch (639:16): [True: 281, False: 305]
  ------------------
  640|    281|		parse_sec_attr((*file), (*file)->sec_attr, (*file)->sec_attr_len);
  641|  2.38k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.38k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.38k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.38k|	int _ret = r; \
  |  |  |  |  155|  2.38k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.79k, False: 586]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.38k|	return _ret; \
  |  |  |  |  163|  2.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|  2.38k|}
card-cardos.c:parse_sec_attr:
  619|    281|{
  620|    281|	size_t i;
  621|    281|	const int *idx;
  622|       |
  623|    281|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    281|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (623:8): [True: 2, False: 279]
  ------------------
  624|       |
  625|       |	/* acl defaults to 0xFF if unspecified */
  626|  2.81k|	for (i = 0; i < 9; i++)
  ------------------
  |  Branch (626:14): [True: 2.52k, False: 281]
  ------------------
  627|  2.52k|		if (idx[i] != -1)
  ------------------
  |  Branch (627:7): [True: 1.96k, False: 564]
  ------------------
  628|  1.96k|			add_acl_entry(file, idx[i], (u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (628:37): [True: 214, False: 1.75k]
  ------------------
  629|    281|}
card-cardos.c:add_acl_entry:
  546|  1.96k|{
  547|  1.96k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.96k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  548|       |
  549|  1.96k|	switch (byte) {
  550|     37|	case 0x00:
  ------------------
  |  Branch (550:2): [True: 37, False: 1.92k]
  ------------------
  551|     37|		method = SC_AC_NONE;
  ------------------
  |  |  150|     37|#define SC_AC_NONE			0x00000000
  ------------------
  552|     37|		break;
  553|  1.78k|	case 0xFF:
  ------------------
  |  Branch (553:2): [True: 1.78k, False: 180]
  ------------------
  554|  1.78k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.78k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  555|  1.78k|		break;
  556|    143|	default:
  ------------------
  |  Branch (556:2): [True: 143, False: 1.82k]
  ------------------
  557|    143|		if (byte > 0x7F) {
  ------------------
  |  Branch (557:7): [True: 48, False: 95]
  ------------------
  558|     48|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     48|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  559|     95|		} else {
  560|     95|			method = SC_AC_CHV;
  ------------------
  |  |  151|     95|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  561|     95|			key_ref = byte;
  562|     95|		}
  563|    143|		break;
  564|  1.96k|	}
  565|  1.96k|	sc_file_add_acl_entry(file, op, method, key_ref);
  566|  1.96k|}
card-cardos.c:cardos_check_sw:
  458|  4.51k|{
  459|  4.51k|	const int err_count = sizeof(cardos_errors)/sizeof(cardos_errors[0]);
  460|  4.51k|	int i;
  461|       |
  462|   115k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (462:14): [True: 114k, False: 381]
  ------------------
  463|   114k|		if (cardos_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (463:7): [True: 4.13k, False: 110k]
  ------------------
  464|  4.13k|			if ( cardos_errors[i].errorstr )
  ------------------
  |  Branch (464:9): [True: 1.69k, False: 2.43k]
  ------------------
  465|  1.69k|				sc_log(card->ctx,  "%s\n",
  ------------------
  |  |   71|  1.69k|#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|  4.13k|				 	cardos_errors[i].errorstr);
  467|  4.13k|			return cardos_errors[i].errorno;
  468|  4.13k|		}
  469|   114k|	}
  470|       |
  471|    381|        sc_log(card->ctx,  "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
  ------------------
  |  |   71|    381|#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|    381|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    381|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  473|  4.51k|}
card-cardos.c:cardos_card_ctl:
 1447|     74|{
 1448|     74|	switch (cmd) {
  ------------------
  |  Branch (1448:10): [True: 74, False: 0]
  ------------------
 1449|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_FCI:
  ------------------
  |  Branch (1449:2): [True: 0, False: 74]
  ------------------
 1450|      0|		break;
 1451|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_OCI:
  ------------------
  |  Branch (1451:2): [True: 0, False: 74]
  ------------------
 1452|      0|		return cardos_put_data_oci(card,
 1453|      0|			(struct sc_cardctl_cardos_obj_info *) ptr);
 1454|      0|		break;
 1455|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_SECI:
  ------------------
  |  Branch (1455:2): [True: 0, False: 74]
  ------------------
 1456|      0|		return cardos_put_data_seci(card,
 1457|      0|			(struct sc_cardctl_cardos_obj_info *) ptr);
 1458|      0|		break;
 1459|      0|	case SC_CARDCTL_CARDOS_GENERATE_KEY:
  ------------------
  |  Branch (1459:2): [True: 0, False: 74]
  ------------------
 1460|      0|		return cardos_generate_key(card,
 1461|      0|			(struct sc_cardctl_cardos_genkey_info *) ptr);
 1462|      8|	case  SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS:
  ------------------
  |  Branch (1462:2): [True: 8, False: 66]
  ------------------
 1463|      8|		return cardos_pass_algo_flags(card,
 1464|      8|			(struct sc_cardctl_cardos_pass_algo_flags *) ptr);
 1465|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1465:2): [True: 0, False: 74]
  ------------------
 1466|      0|		return cardos_lifecycle_get(card, (int *) ptr);
 1467|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1467:2): [True: 0, False: 74]
  ------------------
 1468|      0|		return cardos_lifecycle_set(card, (int *) ptr);
 1469|     66|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1469:2): [True: 66, False: 8]
  ------------------
 1470|     66|		return cardos_get_serialnr(card, (sc_serial_number_t *)ptr);
 1471|     74|	}
 1472|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1473|     74|}
card-cardos.c:cardos_pass_algo_flags:
  353|      8|{
  354|      8|	cardos_data_t * priv = (cardos_data_t *)card->drv_data;
  355|      8|	int r = 0;
  356|       |
  357|      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]
  |  |  ------------------
  ------------------
  358|      8|	switch (ptr->pass) {
  359|      4|		case 1:
  ------------------
  |  Branch (359:3): [True: 4, False: 4]
  ------------------
  360|      4|			ptr->card_flags = card->flags;
  361|      4|			ptr->used_flags = priv->flags;
  362|      4|			ptr->ec_flags = priv->ec_flags;
  363|      4|			ptr->ext_flags = priv->ext_flags;
  364|      4|			break;
  365|      4|		case 2:
  ------------------
  |  Branch (365:3): [True: 4, False: 4]
  ------------------
  366|      4|			r = cardos_add_algs(card,ptr->new_flags, ptr->ec_flags, ptr->ext_flags);
  367|      4|			break;
  368|      0|		default:
  ------------------
  |  Branch (368:3): [True: 0, False: 8]
  ------------------
  369|      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__
  |  |  ------------------
  ------------------
  370|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  371|      8|	}
  372|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|      8|}
card-cardos.c:cardos_get_serialnr:
 1414|     66|{
 1415|     66|	int r;
 1416|     66|	sc_apdu_t apdu;
 1417|     66|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1418|       |
 1419|     66|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     66|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1420|     66|	apdu.resp = rbuf;
 1421|     66|	apdu.resplen = sizeof(rbuf);
 1422|     66|	apdu.le   = 256;
 1423|     66|	r = sc_transmit_apdu(card, &apdu);
 1424|     66|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     66|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     66|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     66|	int _ret = (r); \
  |  |  |  |  168|     66|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  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|     66|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|     65|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1425:6): [True: 44, False: 21]
  |  Branch (1425:26): [True: 1, False: 20]
  ------------------
 1426|     45|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     45|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1427|     20|	if ((apdu.resplen == 8) && (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3)) {
  ------------------
  |  Branch (1427:6): [True: 2, False: 18]
  |  Branch (1427:30): [True: 0, False: 2]
  |  Branch (1427:72): [True: 2, False: 0]
  ------------------
 1428|       |		/* cache serial number */
 1429|      2|		memcpy(card->serialnr.value, rbuf, 8);
 1430|      2|		card->serialnr.len = 8;
 1431|     18|	} else if (apdu.resplen == 32) {
  ------------------
  |  Branch (1431:13): [True: 1, False: 17]
  ------------------
 1432|       |		/* cache serial number */
 1433|      1|		memcpy(card->serialnr.value, &rbuf[10], 6);
 1434|      1|		card->serialnr.len = 6;
 1435|     17|	} else {
 1436|     17|		sc_log(card->ctx,  "unexpected response to GET DATA serial"
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1437|     17|				" number\n");
 1438|     17|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     17|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1439|     17|	}
 1440|       |	/* copy and return serial number */
 1441|      3|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1442|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1443|     20|}
card-cardos.c:cardos_pin_cmd:
 1482|     66|{
 1483|     66|	struct sc_context *ctx = card->ctx;
 1484|     66|	int rv;
 1485|       |
 1486|     66|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     66|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     66|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     66|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     66|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 66]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|       |
 1488|     66|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     66|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1489|     66|	data->pin_reference |= 0x80;
 1490|       |
 1491|     66|	sc_log(ctx, "PIN_CMD(cmd:%i, ref:%i)", data->cmd, data->pin_reference);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1492|     66|	sc_log(ctx, "PIN1(max:%zu, min:%zu)", data->pin1.max_length, data->pin1.min_length);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1493|     66|	sc_log(ctx, "PIN2(max:%zu, min:%zu)", data->pin2.max_length, data->pin2.min_length);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1494|       |
 1495|       |	/* FIXME: the following values depend on what pin length was
 1496|       |	 * used when creating the BS objects */
 1497|     66|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (1497:6): [True: 66, False: 0]
  ------------------
 1498|     66|		data->pin1.max_length = 8;
 1499|     66|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (1499:6): [True: 66, False: 0]
  ------------------
 1500|     66|		data->pin2.max_length = 8;
 1501|       |
 1502|     66|	rv = iso_ops->pin_cmd(card, data);
 1503|     66|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     66|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     66|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     66|	int _ret = r; \
  |  |  |  |  155|     66|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 66, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     66|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     66|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 66, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     66|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     66|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     66|	return _ret; \
  |  |  |  |  163|     66|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1504|     66|}

sc_get_cedulauy_driver:
  292|  8.50k|{
  293|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  294|       |
  295|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (295:6): [True: 1, False: 8.49k]
  ------------------
  296|      1|		iso_ops = iso_drv->ops;
  297|       |
  298|  8.50k|	cedulauy_ops = *iso_ops;
  299|  8.50k|	cedulauy_ops.match_card = cedulauy_match_card;
  300|  8.50k|	cedulauy_ops.init = cedulauy_init;
  301|  8.50k|	cedulauy_ops.select_file = cedulauy_select_file;
  302|  8.50k|	cedulauy_ops.set_security_env = cedulauy_set_security_env;
  303|  8.50k|	cedulauy_ops.compute_signature = cedulauy_compute_signature;
  304|  8.50k|	cedulauy_ops.decipher = NULL; /* the signing key is sign-only */
  305|  8.50k|	cedulauy_ops.get_challenge = cedulauy_get_challenge;
  306|  8.50k|	cedulauy_ops.logout = cedulauy_logout;
  307|  8.50k|	cedulauy_ops.card_reader_lock_obtained = cedulauy_card_reader_lock_obtained;
  308|       |
  309|  8.50k|	return &cedulauy_drv;
  310|  8.50k|}
card-cedulauy.c:cedulauy_match_card:
  112|  5.28k|{
  113|  5.28k|	int i = _sc_match_atr(card, cedulauy_atrs, &card->type);
  114|       |
  115|  5.28k|	if (i < 0)
  ------------------
  |  Branch (115:6): [True: 5.08k, False: 208]
  ------------------
  116|  5.08k|		return 0;
  117|    208|	card->name = cedulauy_atrs[i].name;
  118|    208|	return 1;
  119|  5.28k|}
card-cedulauy.c:cedulauy_init:
  123|    208|{
  124|    208|	unsigned long flags;
  125|    208|	int r;
  126|       |
  127|    208|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    208|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    208|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    208|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    208|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 208]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|    208|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    208|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  130|       |
  131|    208|	r = cedulauy_select_app(card);
  132|    208|	LOG_TEST_RET(card->ctx, r, "Cannot select the eID application");
  ------------------
  |  |  174|    208|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    208|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    208|	int _ret = (r); \
  |  |  |  |  168|    208|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  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|    208|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 194]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    194|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  111|    194|#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|    194|#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|    194|#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|    194|#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|    194|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  138|    194|	r = _sc_card_add_rsa_alg(card, 2048, flags, 0);
  139|       |
  140|    194|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    194|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    194|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    194|	int _ret = r; \
  |  |  |  |  155|    194|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 194, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    194|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  157|    194|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    194|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    194|	return _ret; \
  |  |  |  |  163|    194|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|    194|}
card-cedulauy.c:cedulauy_select_app:
   97|    208|{
   98|    208|	struct sc_apdu apdu;
   99|    208|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  100|       |
  101|    208|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    208|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    208|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    208|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    208|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 208]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  102|       |
  103|    208|	sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x04, 0x00,
  104|    208|			cedulauy_aid, sizeof cedulauy_aid, resp, sizeof resp);
  105|    208|	SC_TRANSMIT_TEST_RET(card, apdu, "Cannot select the eID application");
  ------------------
  |  |   90|    208|	do { \
  |  |   91|    208|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|    208|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|    208|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|    208|	int _ret = (r); \
  |  |  |  |  |  |  168|    208|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 5, False: 203]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|    208|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 203]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   92|    208|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  174|    203|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|    203|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|    203|	int _ret = (r); \
  |  |  |  |  |  |  168|    203|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 9, False: 194]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|    203|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 194]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   93|    203|	} while (0)
  |  |  ------------------
  |  |  |  Branch (93:11): [Folded, False: 194]
  |  |  ------------------
  ------------------
  106|       |
  107|    194|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    194|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    194|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    194|	int _ret = r; \
  |  |  |  |  155|    194|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 194, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    194|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  157|    194|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    194|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    194|	return _ret; \
  |  |  |  |  163|    194|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  108|    194|}
card-cedulauy.c:cedulauy_select_file:
  170|    464|{
  171|    464|	struct sc_path path = *in_path;
  172|       |
  173|    464|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    464|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    464|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    464|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    464|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 464]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|    464|	if (path.aid.len == sizeof cedulauy_aid && 0 == memcmp(path.aid.value, cedulauy_aid, sizeof cedulauy_aid)) {
  ------------------
  |  Branch (175:6): [True: 235, False: 229]
  |  Branch (175:45): [True: 235, False: 0]
  ------------------
  176|       |		/* swallow cedula AID, it is always selected via init() */
  177|    235|		path.aid.len = 0;
  178|    235|	}
  179|    464|	if (path.type == SC_PATH_TYPE_PATH && path.len >= 2 && path.value[0] == 0x3F && path.value[1] == 0x00) {
  ------------------
  |  |  119|    928|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (179:6): [True: 229, False: 235]
  |  Branch (179:40): [True: 229, False: 0]
  |  Branch (179:57): [True: 229, False: 0]
  |  Branch (179:82): [True: 229, False: 0]
  ------------------
  180|       |		/* swallow MF, everything resides within the Application DF */
  181|    229|		memmove(path.value, path.value + 2, path.len - 2);
  182|    229|		path.len -= 2;
  183|    229|	}
  184|    464|	if (path.type == SC_PATH_TYPE_PATH && path.len == 0) {
  ------------------
  |  |  119|    928|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:6): [True: 229, False: 235]
  |  Branch (184:40): [True: 0, False: 229]
  ------------------
  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|    464|	LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, &path, file_out));
  ------------------
  |  |  164|    464|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    464|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    464|	int _ret = r; \
  |  |  |  |  155|    464|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 464, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    464|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    252|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 252, False: 212]
  |  |  |  |  ------------------
  |  |  |  |  157|    464|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    464|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    464|	return _ret; \
  |  |  |  |  163|    464|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  191|    464|}
card-cedulauy.c:cedulauy_card_reader_lock_obtained:
  145|    699|{
  146|    699|	if (was_reset)
  ------------------
  |  Branch (146:6): [True: 0, False: 699]
  ------------------
  147|    699|		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|    699|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    699|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    699|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    699|	int _ret = r; \
  |  |  |  |  155|    699|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 699, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    699|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 699]
  |  |  |  |  ------------------
  |  |  |  |  157|    699|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    699|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    699|	return _ret; \
  |  |  |  |  163|    699|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  149|    699|}

coolkey_compare_id:
  757|  2.92k|{
  758|  2.92k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 2.92k]
  |  Branch (758:19): [True: 0, False: 2.92k]
  ------------------
  759|      0|		return 1;
  760|  2.92k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|  2.92k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|  2.92k|}
coolkey_list_meter:
  765|    445|size_t coolkey_list_meter(const void *el) {
  766|    445|	return sizeof(sc_cardctl_coolkey_object_t);
  767|    445|}
sc_get_coolkey_driver:
 2467|  8.50k|{
 2468|  8.50k|	return sc_get_driver();
 2469|  8.50k|}
card-coolkey.c:coolkey_apdu_io:
  912|  7.25k|{
  913|  7.25k|	int r;
  914|  7.25k|	sc_apdu_t apdu;
  915|  7.25k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  7.25k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  7.25k|	u8 *rbuf;
  918|  7.25k|	size_t rbuflen;
  919|  7.25k|	int cse = 0;
  920|       |
  921|       |
  922|  7.25k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.25k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.25k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.25k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.25k]
  |  |  ------------------
  ------------------
  923|       |
  924|  7.25k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  925|  7.25k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  926|       |
  927|  7.25k|	rbuf = rbufinitbuf;
  928|  7.25k|	rbuflen = sizeof(rbufinitbuf);
  929|       |
  930|       |	/* if caller provided a buffer and length */
  931|  7.25k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (931:6): [True: 1.92k, False: 5.33k]
  |  Branch (931:17): [True: 1.92k, False: 0]
  |  Branch (931:29): [True: 1.92k, False: 0]
  |  Branch (931:43): [True: 1.92k, False: 0]
  ------------------
  932|  1.92k|		rbuf = *recvbuf;
  933|  1.92k|		rbuflen = *recvbuflen;
  934|  1.92k|	}
  935|       |
  936|  7.25k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (936:6): [True: 5.33k, False: 1.91k]
  |  Branch (936:17): [True: 0, False: 1.91k]
  ------------------
  937|  5.33k|		if (recvbuf) {
  ------------------
  |  Branch (937:7): [True: 2, False: 5.33k]
  ------------------
  938|      2|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|      2|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  939|  5.33k|		} else {
  940|  5.33k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  5.33k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  941|  5.33k|		}
  942|  5.33k|	} else {
  943|  1.91k|		if (recvbuf) {
  ------------------
  |  Branch (943:7): [True: 1.91k, False: 0]
  ------------------
  944|  1.91k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  1.91k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  945|  1.91k|		} else {
  946|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  947|      0|		}
  948|  1.91k|	}
  949|       |
  950|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  951|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  952|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  953|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  954|       |	 * and we should be fine */
  955|  7.25k|	if (nonce) {
  ------------------
  |  Branch (955:6): [True: 0, False: 7.25k]
  ------------------
  956|      0|		u8 *buf = rsendbuf;
  957|      0|		if (sendbuf) {
  ------------------
  |  Branch (957:7): [True: 0, False: 0]
  ------------------
  958|      0|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  959|      0|			memcpy(rsendbuf, sendbuf, sendbuflen);
  960|      0|			buf += sendbuflen;
  961|      0|		}
  962|      0|		memcpy(buf, nonce, nonce_len);
  963|      0|		sendbuflen += nonce_len;
  964|      0|		sendbuf =rsendbuf;
  965|      0|	}
  966|       |
  967|  7.25k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  968|       |
  969|  7.25k|	apdu.lc = sendbuflen;
  970|  7.25k|	apdu.datalen = sendbuflen;
  971|  7.25k|	apdu.data = sendbuf;
  972|       |
  973|       |
  974|       |	/* coolkey uses non-standard classes */
  975|  7.25k|	apdu.cla = cla;
  976|       |
  977|  7.25k|	if (recvbuf) {
  ------------------
  |  Branch (977:6): [True: 1.92k, False: 5.33k]
  ------------------
  978|  1.92k|		apdu.resp = rbuf;
  979|  1.92k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (979:13): [True: 0, False: 1.92k]
  ------------------
  980|  1.92k|		apdu.resplen = rbuflen;
  981|  5.33k|	} else {
  982|  5.33k|		 apdu.resp =  rbuf;
  983|  5.33k|		 apdu.le = 0;
  984|  5.33k|		 apdu.resplen = 0;
  985|  5.33k|	}
  986|       |
  987|  7.25k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  988|  7.25k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  989|       |
  990|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  991|  7.25k|	r = sc_transmit_apdu(card, &apdu);
  992|       |
  993|  7.25k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  994|  7.25k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  995|       |
  996|  7.25k|	if (r < 0) {
  ------------------
  |  Branch (996:6): [True: 54, False: 7.20k]
  ------------------
  997|     54|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  998|     54|		goto err;
  999|     54|	}
 1000|  7.20k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1001|  7.20k|	if (r < 0) {
  ------------------
  |  Branch (1001:6): [True: 5.04k, False: 2.15k]
  ------------------
 1002|  5.04k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1003|  5.04k|		goto err;
 1004|  5.04k|	}
 1005|       |
 1006|  2.15k|	if (recvbuflen) {
  ------------------
  |  Branch (1006:6): [True: 1.64k, False: 511]
  ------------------
 1007|  1.64k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1007:7): [True: 1.64k, False: 0]
  |  Branch (1007:18): [True: 0, False: 1.64k]
  ------------------
 1008|      0|			*recvbuf =  malloc(apdu.resplen);
 1009|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1009:8): [True: 0, False: 0]
  ------------------
 1010|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1011|      0|				goto err;
 1012|      0|			}
 1013|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1014|      0|		}
 1015|  1.64k|		*recvbuflen =  apdu.resplen;
 1016|  1.64k|		r = (int)*recvbuflen;
 1017|  1.64k|	}
 1018|       |
 1019|  7.25k|err:
 1020|  7.25k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.25k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.25k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.25k|	int _ret = r; \
  |  |  |  |  155|  7.25k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.68k, False: 1.57k]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  5.10k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.10k, False: 586]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.68k|	} else { \
  |  |  |  |  159|  1.57k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.57k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.57k|	} \
  |  |  |  |  162|  7.25k|	return _ret; \
  |  |  |  |  163|  7.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1021|  7.25k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  1.27k|{
  826|  1.27k|	int pos;
  827|  1.27k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  1.27k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  1.27k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  1.27k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  1.27k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  1.27k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  1.27k|	}, 0, 0, NULL};
  831|       |
  832|  1.27k|	cmp.id = object_id;
  833|  1.27k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 454, False: 820]
  ------------------
  834|    454|		return NULL;
  835|       |
  836|    820|	return list_get_at(list, pos);
  837|  1.27k|}
card-coolkey.c:sc_get_driver:
 2440|  8.50k|{
 2441|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2442|       |
 2443|  8.50k|	coolkey_ops = *iso_drv->ops;
 2444|  8.50k|	coolkey_ops.match_card = coolkey_match_card;
 2445|  8.50k|	coolkey_ops.init = coolkey_init;
 2446|  8.50k|	coolkey_ops.finish = coolkey_finish;
 2447|       |
 2448|  8.50k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2449|  8.50k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2450|  8.50k|	coolkey_ops.read_binary = coolkey_read_binary;
 2451|  8.50k|	coolkey_ops.write_binary = coolkey_write_binary;
 2452|  8.50k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2453|  8.50k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2454|  8.50k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2455|  8.50k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2456|  8.50k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2457|  8.50k|	coolkey_ops.check_sw = coolkey_check_sw;
 2458|  8.50k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2459|  8.50k|	coolkey_ops.logout = coolkey_logout;
 2460|  8.50k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2461|       |
 2462|  8.50k|	return &coolkey_drv;
 2463|  8.50k|}
card-coolkey.c:coolkey_match_card:
 2279|  5.08k|{
 2280|  5.08k|	int r;
 2281|       |
 2282|  5.08k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.08k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.08k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.08k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.08k]
  |  |  ------------------
  ------------------
 2283|       |
 2284|  5.08k|	r = coolkey_select_applet(card);
 2285|  5.08k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  5.08k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2285:6): [True: 321, False: 4.76k]
  ------------------
 2286|    321|		sc_apdu_t apdu;
 2287|       |
 2288|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2289|       |		 * on Coolkey applet (reserved for GetMemory function),
 2290|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2291|       |		 */
 2292|    321|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|    321|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|    321|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2293|    321|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|    321|#define COOLKEY_CLASS           0xb0
  ------------------
 2294|    321|		apdu.le = 0x00;
 2295|    321|		apdu.resplen = 0;
 2296|    321|		apdu.resp = NULL;
 2297|    321|		r = sc_transmit_apdu(card, &apdu);
 2298|    321|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|    642|#define SC_SUCCESS				0
  ------------------
  |  Branch (2298:7): [True: 319, False: 2]
  |  Branch (2298:26): [True: 259, False: 60]
  |  Branch (2298:46): [True: 258, False: 1]
  ------------------
 2299|    258|			return 1;
 2300|    258|		}
 2301|     63|		return 0;
 2302|    321|	}
 2303|  4.76k|	return 0;
 2304|  5.08k|}
card-coolkey.c:coolkey_select_applet:
 1070|  5.33k|{
 1071|  5.33k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1072|  5.33k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  5.33k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  5.33k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1073|  5.33k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1074|  5.33k|}
card-coolkey.c:coolkey_init:
 2308|    258|{
 2309|    258|	int r;
 2310|    258|	unsigned long flags;
 2311|    258|	unsigned long ext_flags;
 2312|    258|	coolkey_private_data_t * priv;
 2313|       |
 2314|    258|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    258|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    258|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    258|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 258]
  |  |  ------------------
  ------------------
 2315|       |
 2316|    258|	r = coolkey_initialize(card);
 2317|    258|	if (r < 0) {
  ------------------
  |  Branch (2317:6): [True: 234, False: 24]
  ------------------
 2318|    234|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    234|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    234|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    234|	int _ret = r; \
  |  |  |  |  155|    234|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 234, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    234|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    234|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 234, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    234|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    234|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    234|	return _ret; \
  |  |  |  |  163|    234|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2319|    234|	}
 2320|       |
 2321|     24|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2322|       |
 2323|       |	/* set Token Major/minor version */
 2324|     24|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|     24|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2325|       |
 2326|     24|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2327|     24|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2328|     24|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2329|       |
 2330|     24|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|     24|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|     24|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|     24|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     24|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2331|     24|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|     24|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|     24|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2332|       |
 2333|     24|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2334|     24|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2335|     24|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2336|       |
 2337|       |
 2338|     24|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     24|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2339|     24|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2339:6): [True: 10, False: 14]
  ------------------
 2340|     10|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|     10|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2341|     10|	}
 2342|       |
 2343|     24|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2344|     24|}
card-coolkey.c:coolkey_initialize:
 2148|    258|{
 2149|    258|	int r;
 2150|    258|	coolkey_private_data_t *priv = NULL;
 2151|    258|	coolkey_life_cycle_t life_cycle;
 2152|    258|	coolkey_object_info_t object_info;
 2153|    258|	int combined_processed = 0;
 2154|       |
 2155|       |	/* already found? */
 2156|    258|	if (card->drv_data) {
  ------------------
  |  Branch (2156:6): [True: 0, False: 258]
  ------------------
 2157|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2158|      0|	}
 2159|    258|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|    258|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2160|       |
 2161|    258|	priv = coolkey_new_private_data();
 2162|    258|	if (priv == NULL) {
  ------------------
  |  Branch (2162:6): [True: 0, False: 258]
  ------------------
 2163|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2164|      0|		goto cleanup;
 2165|      0|	}
 2166|    258|	r = coolkey_get_life_cycle(card, &life_cycle);
 2167|    258|	if (r < 0) {
  ------------------
  |  Branch (2167:6): [True: 70, False: 188]
  ------------------
 2168|     70|		goto cleanup;
 2169|     70|	}
 2170|       |
 2171|       |	/* Select a coolkey read the coolkey objects out */
 2172|    188|	r = coolkey_select_applet(card);
 2173|    188|	if (r < 0) {
  ------------------
  |  Branch (2173:6): [True: 7, False: 181]
  ------------------
 2174|      7|		goto cleanup;
 2175|      7|	}
 2176|       |
 2177|    181|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2178|    181|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2179|    181|	priv->pin_count = life_cycle.pin_count;
 2180|    181|	priv->life_cycle = life_cycle.life_cycle;
 2181|       |
 2182|       |	/* walk down the list of objects and read them off the token */
 2183|    181|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|    181|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2184|  1.44k|	while (r >= 0) {
  ------------------
  |  Branch (2184:9): [True: 1.30k, False: 145]
  ------------------
 2185|  1.30k|		unsigned long object_id;
 2186|  1.30k|		unsigned long object_len;
 2187|       |
 2188|       |		/* The card did not return what we expected: Lets try other objects */
 2189|  1.30k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2189:7): [True: 2, False: 1.29k]
  ------------------
 2190|      2|			break;
 2191|       |
 2192|       |		/* TODO also look at the ACL... */
 2193|       |
 2194|  1.29k|		object_id = bebytes2ulong(object_info.object_id);
 2195|  1.29k|		object_len = bebytes2ulong(object_info.object_length);
 2196|       |		/* Avoid insanely large data */
 2197|  1.29k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  1.29k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2197:7): [True: 34, False: 1.26k]
  ------------------
 2198|     34|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     34|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2199|     34|			goto cleanup;
 2200|     34|		}
 2201|       |
 2202|       |		/* the combined object is a single object that can store the other objects.
 2203|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2204|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2205|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2206|       |		 * process it separately so that we can have both combined objects managed
 2207|       |		 * by TPS and user managed certs on the same token */
 2208|  1.26k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  1.26k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2208:7): [True: 0, False: 1.26k]
  ------------------
 2209|      0|			u8 *object = malloc(object_len);
 2210|      0|			if (object == NULL) {
  ------------------
  |  Branch (2210:8): [True: 0, False: 0]
  ------------------
 2211|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2212|      0|				break;
 2213|      0|			}
 2214|      0|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|      0|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2215|      0|				priv->nonce, sizeof(priv->nonce));
 2216|      0|			if (r < 0) {
  ------------------
  |  Branch (2216:8): [True: 0, False: 0]
  ------------------
 2217|      0|				free(object);
 2218|      0|				break;
 2219|      0|			}
 2220|      0|			r = coolkey_process_combined_object(card, priv, object, r);
 2221|      0|			free(object);
 2222|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2222:8): [True: 0, False: 0]
  ------------------
 2223|      0|				break;
 2224|      0|			}
 2225|      0|			combined_processed = 1;
 2226|  1.26k|		} else {
 2227|  1.26k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  1.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2228|  1.26k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2229|  1.26k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.26k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2229:8): [True: 820, False: 445]
  ------------------
 2230|    820|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|    820|#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|  1.26k|		}
 2232|       |
 2233|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2234|  1.26k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  1.26k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2235|  1.26k|	}
 2236|    147|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    147|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2236:6): [True: 115, False: 32]
  ------------------
 2237|       |		/* This means the card does not cooperate at all: bail out */
 2238|    115|		if (r >= 0) {
  ------------------
  |  Branch (2238:7): [True: 2, False: 113]
  ------------------
 2239|      2|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      2|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2240|      2|		}
 2241|    115|		goto cleanup;
 2242|    115|	}
 2243|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2244|     32|	if (!combined_processed) {
  ------------------
  |  Branch (2244:6): [True: 32, False: 0]
  ------------------
 2245|     32|		global_platform_cplc_data_t cplc_data;
 2246|       |		/* select the card manager, because a card with applet only will have
 2247|       |		   already selected the coolkey applet */
 2248|       |
 2249|     32|		r = gp_select_card_manager(card);
 2250|     32|		if (r < 0) {
  ------------------
  |  Branch (2250:7): [True: 2, False: 30]
  ------------------
 2251|      2|			goto cleanup;
 2252|      2|		}
 2253|       |
 2254|     30|		r = gp_get_cplc_data(card, &cplc_data);
 2255|     30|		if (r < 0) {
  ------------------
  |  Branch (2255:7): [True: 6, False: 24]
  ------------------
 2256|      6|			goto cleanup;
 2257|      6|		}
 2258|     24|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2259|     24|		priv->token_name = (u8 *)strdup("COOLKEY");
 2260|     24|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2260:7): [True: 0, False: 24]
  ------------------
 2261|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2262|      0|			goto cleanup;
 2263|      0|		}
 2264|     24|		priv->token_name_length = sizeof("COOLKEY")-1;
 2265|     24|	}
 2266|     24|	card->drv_data = priv;
 2267|     24|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2268|       |
 2269|    234|cleanup:
 2270|    234|	if (priv) {
  ------------------
  |  Branch (2270:6): [True: 234, False: 0]
  ------------------
 2271|    234|		coolkey_free_private_data(priv);
 2272|    234|	}
 2273|    234|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    234|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    234|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    234|	int _ret = r; \
  |  |  |  |  155|    234|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 234, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    234|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    234|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 234, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    234|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    234|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    234|	return _ret; \
  |  |  |  |  163|    234|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2274|    234|}
card-coolkey.c:coolkey_new_private_data:
  772|    258|{
  773|    258|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|    258|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|    258|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 258]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|    258|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|    258|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|    258|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 258]
  ------------------
  783|    258|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 258]
  ------------------
  784|    258|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 258]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|    258|	return priv;
  790|    258|}
card-coolkey.c:coolkey_get_life_cycle:
 1028|    258|{
 1029|    258|	coolkey_status_t status;
 1030|    258|	u8 *receive_buf;
 1031|    258|	size_t receive_len;
 1032|    258|	int len;
 1033|       |
 1034|    258|	receive_len = sizeof(*life_cycle);
 1035|    258|	receive_buf = (u8 *)life_cycle;
 1036|    258|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|    258|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|    258|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1037|    258|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1038|    258|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1038:6): [True: 122, False: 136]
  ------------------
 1039|    122|		return SC_SUCCESS;
  ------------------
  |  |   28|    122|#define SC_SUCCESS				0
  ------------------
 1040|    122|	}
 1041|       |
 1042|    136|	receive_len = 1;
 1043|    136|	receive_buf = &life_cycle->life_cycle;
 1044|    136|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|    136|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|    136|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1045|    136|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1046|    136|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1046:6): [True: 56, False: 80]
  ------------------
 1047|     56|		return len;
 1048|     56|	}
 1049|     80|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1049:6): [True: 1, False: 79]
  ------------------
 1050|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1051|      1|	}
 1052|     79|	receive_len = sizeof(status);
 1053|     79|	receive_buf = (u8 *)&status;
 1054|     79|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|     79|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|     79|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1055|     79|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1056|     79|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1056:6): [True: 8, False: 71]
  ------------------
 1057|      8|		return len;
 1058|      8|	}
 1059|     71|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1059:6): [True: 5, False: 66]
  ------------------
 1060|      5|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1061|      5|	}
 1062|     66|	life_cycle->protocol_version_major = status.protocol_version_major;
 1063|     66|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1064|     66|	life_cycle->pin_count = status.pin_count;
 1065|     66|	return SC_SUCCESS;
  ------------------
  |  |   28|     66|#define SC_SUCCESS				0
  ------------------
 1066|     71|}
card-coolkey.c:coolkey_list_object:
 2135|  1.44k|{
 2136|  1.44k|	u8 *rbuf = (u8 *) object_info;
 2137|  1.44k|	size_t rbuflen = sizeof(*object_info);
 2138|       |
 2139|  1.44k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  1.44k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  1.44k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2140|  1.44k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2141|       |
 2142|  1.44k|}
card-coolkey.c:coolkey_add_object:
 1959|  1.26k|{
 1960|  1.26k|	sc_cardctl_coolkey_object_t new_object;
 1961|  1.26k|	int r;
 1962|       |
 1963|  1.26k|	memset(&new_object, 0, sizeof(new_object));
 1964|  1.26k|	new_object.path = coolkey_template_path;
 1965|  1.26k|	new_object.path.len = 4;
 1966|  1.26k|	ulong2bebytes(new_object.path.value, object_id);
 1967|  1.26k|	new_object.id = object_id;
 1968|  1.26k|	new_object.length = object_length;
 1969|       |
 1970|       |	/* The object ID needs to be unique */
 1971|  1.26k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1971:6): [True: 820, False: 445]
  ------------------
 1972|    820|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    820|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1973|    820|	}
 1974|       |
 1975|    445|	if (object_data) {
  ------------------
  |  Branch (1975:6): [True: 0, False: 445]
  ------------------
 1976|      0|		new_object.data = malloc(object_length + add_v1_record);
 1977|      0|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1977:7): [True: 0, False: 0]
  ------------------
 1978|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1979|      0|		}
 1980|      0|		if (add_v1_record) {
  ------------------
  |  Branch (1980:7): [True: 0, False: 0]
  ------------------
 1981|      0|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|      0|#define COOLKEY_V1_OBJECT 1
  ------------------
 1982|      0|			new_object.length++;
 1983|      0|		}
 1984|      0|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1985|      0|	}
 1986|       |
 1987|    445|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 1988|    445|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    445|#define SC_SUCCESS				0
  ------------------
  |  Branch (1988:6): [True: 0, False: 445]
  ------------------
 1989|       |		/* if we didn't successfully put the object on the list,
 1990|       |		 * the data space didn't get adopted. free it before we return */
 1991|      0|		free(new_object.data);
 1992|       |		new_object.data = NULL;
 1993|      0|	}
 1994|    445|	return r;
 1995|    445|}
card-coolkey.c:coolkey_add_object_to_list:
  816|    445|{
  817|    445|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 445]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|    445|	return SC_SUCCESS;
  ------------------
  |  |   28|    445|#define SC_SUCCESS				0
  ------------------
  820|    445|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1078|     24|{
 1079|     24|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1080|     24|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1081|     24|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1082|     24|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1083|     24|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1084|     24|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1085|     24|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1086|     24|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1087|     24|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1088|     24|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1089|     24|}
card-coolkey.c:coolkey_free_private_data:
  793|    258|{
  794|    258|	list_t *l = &priv->objects_list;
  795|    258|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|    258|	list_iterator_start(l);
  799|    703|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 445, False: 258]
  ------------------
  800|    445|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|    445|		free(o->data);
  802|    445|		o->data = NULL;
  803|    445|	}
  804|    258|	list_iterator_stop(l);
  805|       |
  806|    258|	list_destroy(&priv->objects_list);
  807|    258|	free(priv->token_name);
  808|    258|	free(priv);
  809|    258|	return;
  810|    258|}
card-coolkey.c:coolkey_finish:
 1947|     24|{
 1948|     24|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     24|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1949|       |
 1950|     24|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     24|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  ------------------
  ------------------
 1951|     24|	if (priv) {
  ------------------
  |  Branch (1951:6): [True: 24, False: 0]
  ------------------
 1952|     24|		coolkey_free_private_data(priv);
 1953|     24|	}
 1954|     24|	return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
 1955|     24|}
card-coolkey.c:coolkey_select_file:
 1900|     68|{
 1901|     68|	int r;
 1902|     68|	struct sc_file *file = NULL;
 1903|     68|	coolkey_private_data_t *priv;
 1904|     68|	unsigned long object_id;
 1905|       |
 1906|     68|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1906:6): [True: 0, False: 68]
  |  Branch (1906:22): [True: 0, False: 68]
  ------------------
 1907|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1908|       |
 1909|     68|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     68|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     68|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     68|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 68]
  |  |  ------------------
  ------------------
 1910|       |
 1911|     68|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     68|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1912|       |
 1913|     68|	if (in_path->len != 4) {
  ------------------
  |  Branch (1913:6): [True: 0, False: 68]
  ------------------
 1914|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1915|      0|	}
 1916|     68|	r = coolkey_select_applet(card);
 1917|     68|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  |  Branch (1917:6): [True: 59, False: 9]
  ------------------
 1918|     59|		return r;
 1919|     59|	}
 1920|      9|	object_id = bebytes2ulong(in_path->value);
 1921|      9|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1922|      9|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1922:6): [True: 9, False: 0]
  ------------------
 1923|      9|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      9|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1924|      9|	}
 1925|       |
 1926|      0|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|      0|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1927|      0|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|      0|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1927:6): [True: 0, False: 0]
  ------------------
 1928|      0|		priv->key_id = coolkey_get_key_id(object_id);
 1929|      0|	}
 1930|      0|	if (file_out) {
  ------------------
  |  Branch (1930:6): [True: 0, False: 0]
  ------------------
 1931|      0|		file = sc_file_new();
 1932|      0|		if (file == NULL)
  ------------------
  |  Branch (1932:7): [True: 0, False: 0]
  ------------------
 1933|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1934|      0|		file->path = *in_path;
 1935|       |		/* this could be like the FCI */
 1936|      0|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1937|      0|		file->shareable = 0;
 1938|      0|		file->ef_structure = 0;
 1939|      0|		file->size = priv->obj->length;
 1940|      0|		*file_out = file;
 1941|      0|	}
 1942|       |
 1943|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1944|      0|}
card-coolkey.c:coolkey_card_ctl:
 1581|     72|{
 1582|     72|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     72|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1583|       |
 1584|     72|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     72|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     72|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     72|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     72|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1585|     72|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|     72|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1586|       |
 1587|     72|	if (priv == NULL) {
  ------------------
  |  Branch (1587:6): [True: 0, False: 72]
  ------------------
 1588|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1589|      0|	}
 1590|     72|	switch(cmd) {
  ------------------
  |  Branch (1590:9): [True: 72, False: 0]
  ------------------
 1591|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1591:3): [True: 0, False: 72]
  ------------------
 1592|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1593|     24|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1593:3): [True: 24, False: 48]
  ------------------
 1594|     24|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1595|      0|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1595:3): [True: 0, False: 72]
  ------------------
 1596|      0|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1597|     24|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1597:3): [True: 24, False: 48]
  ------------------
 1598|     24|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1599|      0|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1599:3): [True: 0, False: 72]
  ------------------
 1600|      0|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1601|     24|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1601:3): [True: 24, False: 48]
  ------------------
 1602|     24|			return coolkey_final_iterator(&priv->objects_list);
 1603|      0|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1603:3): [True: 0, False: 72]
  ------------------
 1604|      0|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1605|     72|	}
 1606|       |
 1607|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1608|      0|}
card-coolkey.c:coolkey_get_token_info:
 1326|     24|{
 1327|     24|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     24|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1328|     24|	char *label = NULL;
 1329|     24|	char *manufacturer_id = NULL;
 1330|     24|	char *serial_number = NULL;
 1331|       |
 1332|     24|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     24|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     24|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1333|     24|	label = strdup((char *)priv->token_name);
 1334|     24|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1335|     24|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1336|       |
 1337|     24|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1337:6): [True: 24, False: 0]
  |  Branch (1337:15): [True: 24, False: 0]
  |  Branch (1337:34): [True: 24, False: 0]
  ------------------
 1338|     24|		free(token_info->label);
 1339|     24|		token_info->label = label;
 1340|     24|		free(token_info->manufacturer_id);
 1341|     24|		token_info->manufacturer_id = manufacturer_id;
 1342|     24|		free(token_info->serial_number);
 1343|     24|		token_info->serial_number = serial_number;
 1344|     24|		return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
 1345|     24|	}
 1346|      0|	free(label);
 1347|      0|	free(manufacturer_id);
 1348|      0|	free(serial_number);
 1349|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1350|     24|}
card-coolkey.c:coolkey_get_manufacturer:
 1297|     24|{
 1298|     24|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1299|     24|	int i;
 1300|     24|	char *buf;
 1301|     24|	const char *manufacturer_string = "%04x Unknown";
 1302|     24|	size_t len;
 1303|     24|	int r;
 1304|       |
 1305|    140|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1305:12): [True: 117, False: 23]
  ------------------
 1306|    117|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1306:7): [True: 1, False: 116]
  ------------------
 1307|      1|			manufacturer_string = manufacturer_list[i].string;
 1308|      1|			break;
 1309|      1|		}
 1310|    117|	}
 1311|     24|	len = strlen(manufacturer_string)+1;
 1312|     24|	buf= malloc(len);
 1313|     24|	if (buf == NULL) {
  ------------------
  |  Branch (1313:6): [True: 0, False: 24]
  ------------------
 1314|      0|		return NULL;
 1315|      0|	}
 1316|     24|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1317|     24|	if (r < 0) {
  ------------------
  |  Branch (1317:6): [True: 0, False: 24]
  ------------------
 1318|      0|		free(buf);
 1319|      0|		return NULL;
 1320|      0|	}
 1321|     24|	return buf;
 1322|     24|}
card-coolkey.c:coolkey_cuid_to_string:
 1272|     24|{
 1273|     24|	char *buf;
 1274|     24|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1275|     24|	buf = malloc(len);
 1276|     24|	if (buf == NULL) {
  ------------------
  |  Branch (1276:6): [True: 0, False: 24]
  ------------------
 1277|      0|		return NULL;
 1278|      0|	}
 1279|     24|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1280|     24|	return buf;
 1281|     24|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1245|     24|{
 1246|     24|	*countp = list_size(list);
 1247|     24|	list_iterator_start(list);
 1248|     24|	return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
 1249|     24|}
card-coolkey.c:coolkey_final_iterator:
 1266|     24|{
 1267|     24|	list_iterator_stop(list);
 1268|     24|	return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
 1269|     24|}
card-coolkey.c:coolkey_check_sw:
  876|  7.29k|{
  877|  7.29k|	sc_log(card->ctx,
  ------------------
  |  |   71|  7.29k|#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|  7.29k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  7.29k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 2.23k, False: 5.06k]
  |  Branch (880:21): [True: 2.21k, False: 23]
  ------------------
  881|  2.21k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.21k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  5.08k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 37, False: 5.04k]
  ------------------
  884|     37|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 5, False: 32]
  ------------------
  885|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  886|      5|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
  887|      5|		}
  888|     32|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 19, False: 13]
  ------------------
  889|     19|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     19|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     19|		}
  891|     13|		return coolkey_error_codes[sw2].sc_error;
  892|     32|	}
  893|       |
  894|       |	/* iso error */
  895|  5.04k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  5.08k|}
card-coolkey.c:coolkey_pin_cmd:
 2349|      5|{
 2350|      5|	int r;
 2351|      5|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|      5|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2352|      5|	size_t rbuflen;
 2353|      5|	u8 *rbuf;
 2354|       |
 2355|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2356|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2357|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2358|       |	 * maintain separate per application login states without the application
 2359|       |	 * having to cache the pin */
 2360|      5|	switch (data->cmd) {
 2361|      2|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|      2|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2361:2): [True: 2, False: 3]
  ------------------
 2362|      2|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2362:7): [True: 0, False: 2]
  ------------------
 2363|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2364|      2|		} else {
 2365|      2|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      2|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2366|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2367|       |			 * instead, coolkey slows down the login command exponentially
 2368|       |			 */
 2369|      2|			data->pin1.tries_left = 0xf;
 2370|      2|		}
 2371|      2|		r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 2372|      2|		break;
 2373|       |
 2374|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2374:2): [True: 0, False: 5]
  ------------------
 2375|      1|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      1|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2375:2): [True: 1, False: 4]
  ------------------
 2376|       |		/* these 2 commands are currently reserved for TPS */
 2377|      1|	default:
  ------------------
  |  Branch (2377:2): [True: 0, False: 5]
  ------------------
 2378|      1|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2379|      1|		break;
 2380|      2|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      2|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2380:2): [True: 2, False: 3]
  ------------------
 2381|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2382|       |		 * just support the one pin for now (we need an array of nonces to handle
 2383|       |		 * multiple pins) */
 2384|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2385|      2|		rbuflen = sizeof(priv->nonce);
 2386|      2|		rbuf = &priv->nonce[0];
 2387|      2|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   72|      2|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   80|      2|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2388|      2|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2389|      2|			&rbuf, &rbuflen, NULL, 0);
 2390|      2|		if (r < 0) {
  ------------------
  |  Branch (2390:7): [True: 1, False: 1]
  ------------------
 2391|      1|			break;
 2392|      1|		}
 2393|      1|		priv->nonce_valid = 1;
 2394|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2395|      5|	}
 2396|      5|	return r;
 2397|      5|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2418|  7.60k|{
 2419|  7.60k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  7.60k|#define SC_SUCCESS				0
  ------------------
 2420|       |
 2421|  7.60k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.60k]
  |  |  ------------------
  ------------------
 2422|       |
 2423|  7.60k|	if (was_reset > 0) {
  ------------------
  |  Branch (2423:6): [True: 0, False: 7.60k]
  ------------------
 2424|      0|		r = coolkey_select_applet(card);
 2425|      0|	}
 2426|       |
 2427|  7.60k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.60k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.60k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.60k|	int _ret = r; \
  |  |  |  |  155|  7.60k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.60k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.60k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.60k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.60k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.60k|	} else { \
  |  |  |  |  159|      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.60k|	return _ret; \
  |  |  |  |  163|  7.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2428|  7.60k|}

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

dnie_match_card:
  738|  10.2k|{
  739|  10.2k|	int result = 0;
  740|  10.2k|	int matched = -1;
  741|  10.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  10.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|  10.2k|	matched = _sc_match_atr(card, dnie_atrs, &card->type);
  743|  10.2k|	result = (matched >= 0) ? 1 : 0;
  ------------------
  |  Branch (743:11): [True: 857, False: 9.41k]
  ------------------
  744|  10.2k|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|  10.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.2k|	int _ret = r; \
  |  |  |  |  155|  10.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.41k, False: 857]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9.41k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.41k|	} else { \
  |  |  |  |  159|    857|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    857|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    857|	} \
  |  |  |  |  162|  10.2k|	return _ret; \
  |  |  |  |  163|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  745|  10.2k|}
sc_get_dnie_driver:
 2301|  8.50k|{
 2302|  8.50k|	return get_dnie_driver();
 2303|  8.50k|}
card-dnie.c:get_dnie_driver:
 2238|  8.50k|{
 2239|  8.50k|	sc_card_driver_t *iso_drv = sc_get_iso7816_driver();
 2240|       |
 2241|       |	/* memcpy() from standard iso7816 declared operations */
 2242|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2242:6): [True: 1, False: 8.49k]
  ------------------
 2243|      1|		iso_ops = iso_drv->ops;
 2244|  8.50k|	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|  8.50k|	dnie_ops.match_card	= dnie_match_card;
 2252|  8.50k|	dnie_ops.init		= dnie_init;
 2253|  8.50k|	dnie_ops.finish		= dnie_finish;
 2254|       |
 2255|       |	/* iso7816-4 functions */
 2256|  8.50k|	dnie_ops.read_binary	= dnie_read_binary;
 2257|  8.50k|	dnie_ops.write_binary	= NULL;
 2258|  8.50k|	dnie_ops.update_binary	= NULL;
 2259|  8.50k|	dnie_ops.erase_binary	= NULL;
 2260|  8.50k|	dnie_ops.read_record	= NULL;
 2261|  8.50k|	dnie_ops.write_record	= NULL;
 2262|  8.50k|	dnie_ops.append_record	= NULL;
 2263|  8.50k|	dnie_ops.update_record	= NULL;
 2264|  8.50k|	dnie_ops.select_file	= dnie_select_file;
 2265|  8.50k|	dnie_ops.get_challenge	= dnie_get_challenge;
 2266|       |
 2267|       |	/* iso7816-8 functions */
 2268|  8.50k|	dnie_ops.verify		= NULL;
 2269|  8.50k|	dnie_ops.logout		= dnie_logout;
 2270|       |	/* dnie_ops.restore_security_env */
 2271|  8.50k|	dnie_ops.set_security_env = dnie_set_security_env;
 2272|  8.50k|	dnie_ops.decipher	= dnie_decipher;
 2273|  8.50k|	dnie_ops.compute_signature = dnie_compute_signature;
 2274|  8.50k|	dnie_ops.change_reference_data = NULL;
 2275|  8.50k|	dnie_ops.reset_retry_counter = NULL;
 2276|       |
 2277|       |	/* iso7816-9 functions */
 2278|  8.50k|	dnie_ops.create_file	= NULL;
 2279|  8.50k|	dnie_ops.delete_file	= NULL;
 2280|  8.50k|	dnie_ops.list_files	= dnie_list_files;
 2281|  8.50k|	dnie_ops.check_sw	= dnie_check_sw;
 2282|  8.50k|	dnie_ops.card_ctl	= dnie_card_ctl;
 2283|  8.50k|	dnie_ops.process_fci	= dnie_process_fci;
 2284|       |	/* dnie_ops.construct_fci */
 2285|  8.50k|	dnie_ops.pin_cmd	= dnie_pin_cmd;
 2286|  8.50k|	dnie_ops.get_data	= NULL;
 2287|  8.50k|	dnie_ops.put_data	= NULL;
 2288|  8.50k|	dnie_ops.delete_record	= NULL;
 2289|       |
 2290|  8.50k|	return &dnie_driver;
 2291|  8.50k|}
card-dnie.c:dnie_init:
  829|    308|{
  830|    308|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    308|#define SC_SUCCESS				0
  ------------------
  831|    308|	sc_context_t *ctx = card->ctx;
  832|    308|	cwa_provider_t *provider = NULL;
  833|       |
  834|    308|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|       |
  836|       |	/* if recognized as terminated DNIe card, return error */
  837|    308|	if (card->type == SC_CARD_TYPE_DNIE_TERMINATED)
  ------------------
  |  Branch (837:6): [True: 2, False: 306]
  ------------------
  838|    308|	    LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "DNIe card is terminated.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|       |	/* create and initialize cwa-dnie provider*/
  841|    306|	provider = dnie_get_cwa_provider(card);
  842|    306|	if (!provider)
  ------------------
  |  Branch (842:6): [True: 0, False: 306]
  ------------------
  843|    306|	    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|    306|	memset(&(card->sm_ctx), 0, sizeof(sm_context_t));
  847|    306|	card->sm_ctx.ops.get_sm_apdu = dnie_sm_get_wrapped_apdu;
  848|    306|	card->sm_ctx.ops.free_sm_apdu = dnie_sm_free_wrapped_apdu;
  849|    306|	card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    306|#define SM_MODE_NONE		0x0
  ------------------
  850|       |
  851|    306|	res = cwa_create_secure_channel(card, provider, CWA_SM_OFF);
  ------------------
  |  |   31|    306|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  852|    306|	if (res < 0)
  ------------------
  |  Branch (852:6): [True: 26, False: 280]
  ------------------
  853|     26|		free(provider);
  854|    306|	LOG_TEST_RET(card->ctx, res, "Failure resetting CWA secure channel.");
  ------------------
  |  |  174|    306|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    306|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    306|	int _ret = (r); \
  |  |  |  |  168|    306|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 280]
  |  |  |  |  ------------------
  |  |  |  |  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|    306|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 280]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  855|       |
  856|       |	/* initialize private data */
  857|    280|	card->drv_data = calloc(1, sizeof(dnie_private_data_t));
  858|    280|	if (card->drv_data == NULL) {
  ------------------
  |  Branch (858:6): [True: 0, False: 280]
  ------------------
  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|    280|	init_flags(card);
  874|       |
  875|    280|	GET_DNIE_PRIV_DATA(card)->cwa_provider = provider;
  ------------------
  |  |   97|    280|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  876|       |
  877|    280|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    280|}
card-dnie.c:init_flags:
  705|    280|{
  706|    280|	unsigned long algoflags;
  707|       |	/* set up flags according documentation */
  708|    280|	card->name = DNIE_CHIP_SHORTNAME;
  ------------------
  |  |   68|    280|#define DNIE_CHIP_SHORTNAME "dnie"
  ------------------
  709|    280|	card->cla = 0x00;	/* default APDU class (interindustry) */
  710|    280|	card->caps |= SC_CARD_CAP_RNG;	/* we have a random number generator */
  ------------------
  |  |  550|    280|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  711|    280|	card->max_send_size = (255 - 12);	/* manual says 255, but we need 12 extra bytes when encoding */
  712|    280|	card->max_recv_size = 255;
  713|       |
  714|       |	/* RSA Support with PKCS1.5 padding */
  715|    280|	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  133|    280|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    280|#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|    280|#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|    280|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  716|    280|	_sc_card_add_rsa_alg(card, 1024, algoflags, 0);
  717|    280|	_sc_card_add_rsa_alg(card, 1920, algoflags, 0);
  718|    280|	_sc_card_add_rsa_alg(card, 2048, algoflags, 0);
  719|    280|}
card-dnie.c:dnie_finish:
  890|    280|{
  891|    280|	int result = SC_SUCCESS;
  ------------------
  |  |   28|    280|#define SC_SUCCESS				0
  ------------------
  892|    280|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    280|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    280|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    280|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    280|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 280]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  893|    280|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|    280|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  894|       |	/* disable sm channel if established */
  895|    280|	result = cwa_create_secure_channel(card, GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_OFF);
  ------------------
  |  |   97|    280|#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|    280|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  896|    280|	free(GET_DNIE_PRIV_DATA(card)->cwa_provider);
  ------------------
  |  |   97|    280|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  897|    280|	free(card->drv_data);
  898|    280|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  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|    267|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 267, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  899|    280|}
card-dnie.c:dnie_clear_cache:
  689|  1.46k|{
  690|  1.46k|	if (data == NULL) return;
  ------------------
  |  Branch (690:6): [True: 274, False: 1.18k]
  ------------------
  691|  1.18k|	if (data->cache != NULL)
  ------------------
  |  Branch (691:6): [True: 123, False: 1.06k]
  ------------------
  692|    123|		free(data->cache);
  693|       |	data->cache = NULL;
  694|  1.18k|	data->cachelen = 0;
  695|  1.18k|}
card-dnie.c:dnie_read_binary:
 1091|  1.89k|{
 1092|  1.89k|	size_t res = 0;
 1093|  1.89k|	int rc;
 1094|  1.89k|	sc_context_t *ctx = NULL;
 1095|       |	/* preliminary checks */
 1096|  1.89k|	if (!card || !card->ctx || !buf || (count <= 0))
  ------------------
  |  Branch (1096:6): [True: 0, False: 1.89k]
  |  Branch (1096:15): [True: 0, False: 1.89k]
  |  Branch (1096:29): [True: 0, False: 1.89k]
  |  Branch (1096:37): [True: 0, False: 1.89k]
  ------------------
 1097|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1098|  1.89k|	ctx = card->ctx;
 1099|       |
 1100|  1.89k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.89k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.89k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.89k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.89k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.89k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|  1.89k|	if (idx == 0 || GET_DNIE_PRIV_DATA(card)->cache == NULL) {
  ------------------
  |  |   97|  1.73k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1101:6): [True: 164, False: 1.73k]
  |  Branch (1101:18): [True: 142, False: 1.58k]
  ------------------
 1102|       |		/* on first block or no cache, try to fill */
 1103|    306|		rc = dnie_fill_cache(card, flags);
 1104|    306|		if (rc < 0) {
  ------------------
  |  Branch (1104:7): [True: 178, False: 128]
  ------------------
 1105|    178|			sc_log(ctx, "Cannot fill cache. using iso_read_binary()");
  ------------------
  |  |   71|    178|#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|    178|			return iso_ops->read_binary(card, idx, buf, count, flags);
 1107|    178|		}
 1108|    306|	}
 1109|  1.71k|	if (idx >= GET_DNIE_PRIV_DATA(card)->cachelen)
  ------------------
  |  |   97|  1.71k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1109:6): [True: 107, False: 1.60k]
  ------------------
 1110|    107|		return 0;	/* at eof */
 1111|  1.60k|	res = MIN(count, GET_DNIE_PRIV_DATA(card)->cachelen - idx);	/* eval how many bytes to read */
  ------------------
  |  |   70|  1.60k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1.51k, False: 96]
  |  |  ------------------
  ------------------
 1112|  1.60k|	memcpy(buf, GET_DNIE_PRIV_DATA(card)->cache + idx, res);	/* copy data from buffer */
  ------------------
  |  |   97|  1.60k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1113|  1.60k|	sc_log(ctx, "dnie_read_binary() '%zu' bytes", res);
  ------------------
  |  |   71|  1.60k|#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.60k|	LOG_FUNC_RETURN(ctx, (int)res);
  ------------------
  |  |  164|  1.60k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.60k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.60k|	int _ret = r; \
  |  |  |  |  155|  1.60k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.60k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.60k|	} else { \
  |  |  |  |  159|  1.60k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.60k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.60k|	} \
  |  |  |  |  162|  1.60k|	return _ret; \
  |  |  |  |  163|  1.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|  1.60k|}
card-dnie.c:dnie_fill_cache:
  966|    306|{
  967|    306|	u8 tmp[MAX_RESP_BUFFER_SIZE];
  968|    306|	sc_apdu_t apdu;
  969|    306|	size_t count = 0;
  970|    306|	size_t len = 0;
  971|    306|	u8 *buffer = NULL;
  972|    306|	u8 *p;
  973|    306|	sc_context_t *ctx = NULL;
  974|       |
  975|    306|	if (!card || !card->ctx)
  ------------------
  |  Branch (975:6): [True: 0, False: 306]
  |  Branch (975:15): [True: 0, False: 306]
  ------------------
  976|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  977|    306|	ctx = card->ctx;
  978|       |
  979|    306|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    306|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    306|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    306|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    306|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 306]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  980|       |
  981|       |	/* mark cache empty */
  982|    306|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|    306|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  983|       |
  984|       |	/* initialize apdu */
  985|    306|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00);
  ------------------
  |  |  292|    306|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  986|       |
  987|       |	/* try to read_binary while data available but never long than 32767 */
  988|    306|	count = card->max_recv_size;
  989|  2.38k|	for (len = 0; len < 0x7fff;) {
  ------------------
  |  Branch (989:16): [True: 2.38k, False: 2]
  ------------------
  990|  2.38k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.38k|#define SC_SUCCESS				0
  ------------------
  991|       |		/* fill apdu */
  992|  2.38k|		apdu.p1 = 0xff & (len >> 8);
  993|  2.38k|		apdu.p2 = 0xff & len;
  994|  2.38k|		apdu.le = count;
  995|  2.38k|		apdu.resplen = MAX_RESP_BUFFER_SIZE;
  ------------------
  |  |   56|  2.38k|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
  996|  2.38k|		apdu.resp = tmp;
  997|       |		/* transmit apdu */
  998|  2.38k|		r = sc_transmit_apdu(card, &apdu);
  999|  2.38k|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.38k|#define SC_SUCCESS				0
  ------------------
  |  Branch (999:7): [True: 39, False: 2.34k]
  ------------------
 1000|     39|			free(buffer);
 1001|     39|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1001:8): [True: 0, False: 39]
  ------------------
 1002|      0|				free(apdu.resp);
 1003|     39|			sc_log(ctx, "read_binary() APDU transmit failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1004|     39|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1005|     39|		}
 1006|  2.34k|		if (apdu.resplen == 0) {
  ------------------
  |  Branch (1006:7): [True: 151, False: 2.19k]
  ------------------
 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|    151|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1010|    151|			if (r == SC_ERROR_WRONG_LENGTH) {
  ------------------
  |  |   56|    151|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (1010:8): [True: 1, False: 150]
  ------------------
 1011|      1|				count = 0xff & apdu.sw2;
 1012|      1|				if (count != 0) {
  ------------------
  |  Branch (1012:9): [True: 0, False: 1]
  ------------------
 1013|      0|					if (apdu.resp != tmp)
  ------------------
  |  Branch (1013:10): [True: 0, False: 0]
  ------------------
 1014|      0|						free(apdu.resp);
 1015|      0|					continue;	/* read again with correct size */
 1016|      0|				}
 1017|      1|				goto read_done;	/* no more data to read */
 1018|      1|			}
 1019|    150|			if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    150|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1019:8): [True: 7, False: 143]
  ------------------
 1020|      7|				goto read_done;
 1021|    143|			free(buffer);
 1022|    143|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1022:8): [True: 0, False: 143]
  ------------------
 1023|      0|				free(apdu.resp);
 1024|    143|			LOG_FUNC_RETURN(ctx, r);	/* arriving here means response error */
  ------------------
  |  |  164|    143|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    143|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    143|	int _ret = r; \
  |  |  |  |  155|    143|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 143, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    139|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 139, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|    143|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    143|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    143|	return _ret; \
  |  |  |  |  163|    143|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|    143|		}
 1026|       |		/* copy received data into buffer. realloc() if not enough space */
 1027|  2.19k|		count = apdu.resplen;
 1028|  2.19k|		p = realloc(buffer, len + count);
 1029|  2.19k|		if (!p) {
  ------------------
  |  Branch (1029:7): [True: 0, False: 2.19k]
  ------------------
 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|  2.19k|		buffer = p;
 1037|  2.19k|		memcpy(buffer + len, apdu.resp, count);
 1038|  2.19k|		if (apdu.resp != tmp) {
  ------------------
  |  Branch (1038:7): [True: 0, False: 2.19k]
  ------------------
 1039|      0|			free(apdu.resp);
 1040|      0|			apdu.resp = tmp;
 1041|      0|		}
 1042|  2.19k|		len += count;
 1043|  2.19k|		if (count != card->max_recv_size)
  ------------------
  |  Branch (1043:7): [True: 114, False: 2.08k]
  ------------------
 1044|    114|			goto read_done;
 1045|  2.19k|	}
 1046|       |
 1047|    124| read_done:
 1048|    124| 	free((void *)apdu.data);
 1049|    124|	if (apdu.resp != tmp)
  ------------------
  |  Branch (1049:6): [True: 0, False: 124]
  ------------------
 1050|      0|		free(apdu.resp);
 1051|       |
 1052|    124|	if (dnie_is_compressed(card, buffer, len)) {
  ------------------
  |  Branch (1052:6): [True: 4, False: 120]
  ------------------
 1053|      4|		if (flags)
  ------------------
  |  Branch (1053:7): [True: 0, False: 4]
  ------------------
 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|      4|		len -= 8;
 1057|      4|		p = malloc(len);
 1058|      4|		if (!p) {
  ------------------
  |  Branch (1058:7): [True: 0, False: 4]
  ------------------
 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|      4|		memcpy(p, buffer + 8, len);
 1063|      4|		free(buffer);
 1064|      4|		buffer = p;
 1065|      4|	}
 1066|       |
 1067|       |
 1068|       |	/* ok: as final step, set correct cache data into dnie_priv structures */
 1069|    124|	GET_DNIE_PRIV_DATA(card)->cache = buffer;
  ------------------
  |  |   97|    124|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1070|    124|	GET_DNIE_PRIV_DATA(card)->cachelen = len;
  ------------------
  |  |   97|    124|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1071|    124|	sc_log(ctx, "fill_cache() done. length '%zu' bytes", len);
  ------------------
  |  |   71|    124|#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|    124|	LOG_FUNC_RETURN(ctx, (int)len);
  ------------------
  |  |  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: 2, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  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|    122|	} else { \
  |  |  |  |  159|    122|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    122|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    122|	} \
  |  |  |  |  162|    124|	return _ret; \
  |  |  |  |  163|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1073|    124|}
card-dnie.c:dnie_is_compressed:
  913|    124|{
  914|    124|#ifdef ENABLE_ZLIB
  915|    124|	size_t uncompressed = 0L;
  916|    124|	size_t compressed = 0L;
  917|       |
  918|    124|	if (!card || !card->ctx || !from || !len)
  ------------------
  |  Branch (918:6): [True: 0, False: 124]
  |  Branch (918:15): [True: 0, False: 124]
  |  Branch (918:29): [True: 1, False: 123]
  |  Branch (918:38): [True: 0, False: 123]
  ------------------
  919|      1|		return 0;
  920|    123|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    123|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    123|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    123|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    123|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  921|       |
  922|       |	/* if data size not enough for compression header assume uncompressed */
  923|    123|	if (len < 8)
  ------------------
  |  Branch (923:6): [True: 2, False: 121]
  ------------------
  924|      2|		goto compress_exit;
  925|       |	/* evaluate compressed an uncompressed sizes (little endian format) */
  926|    121|	uncompressed = lebytes2ulong(from);
  927|    121|	compressed = lebytes2ulong(from + 4);
  928|       |	/* if compressed size doesn't match data length assume not compressed */
  929|    121|	if (compressed != len - 8)
  ------------------
  |  Branch (929:6): [True: 113, False: 8]
  ------------------
  930|    113|		goto compress_exit;
  931|       |	/* if compressed size greater than uncompressed, assume uncompressed data */
  932|      8|	if (uncompressed < compressed)
  ------------------
  |  Branch (932:6): [True: 1, False: 7]
  ------------------
  933|      1|		goto compress_exit;
  934|       |	/* Do not try to allocate insane size if we receive bogus data */
  935|      7|	if (uncompressed > MAX_FILE_SIZE)
  ------------------
  |  |  220|      7|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (935:6): [True: 3, False: 4]
  ------------------
  936|      3|		goto compress_exit;
  937|       |
  938|      4|	sc_log(card->ctx, "Data seems to be compressed.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  939|      4|	return 1;
  940|    119|compress_exit:
  941|    119|#endif
  942|       |
  943|    119|	sc_log(card->ctx, "Data not compressed.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  944|    119|	return 0;
  945|      7|}
card-dnie.c:dnie_select_file:
 1215|  2.20k|{
 1216|  2.20k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  2.20k|#define SC_SUCCESS				0
  ------------------
 1217|  2.20k|	sc_context_t *ctx = NULL;
 1218|  2.20k|	unsigned char tmp_path[sizeof(DNIE_MF_NAME)];
 1219|  2.20k|	size_t reminder = 0;
 1220|       |
 1221|  2.20k|	if (!card || !card->ctx || !in_path)
  ------------------
  |  Branch (1221:6): [True: 0, False: 2.20k]
  |  Branch (1221:15): [True: 0, False: 2.20k]
  |  Branch (1221:29): [True: 0, False: 2.20k]
  ------------------
 1222|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1223|  2.20k|	ctx = card->ctx;
 1224|       |
 1225|  2.20k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.20k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.20k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1226|       |
 1227|  2.20k|	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: 2.20k]
  ------------------
 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|    377|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    377|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1243:2): [True: 377, False: 1.82k]
  ------------------
 1244|    377|		sc_log_hex(ctx, "select_file(NAME)", in_path->value, in_path->len);
  ------------------
  |  |  129|    377|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    377|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1245|    377|		res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 4, file_out);
 1246|    377|		break;
 1247|  1.82k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.82k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (1247:2): [True: 1.82k, False: 377]
  ------------------
 1248|  1.82k|		if ((in_path->len == 0) || ((in_path->len & 1) != 0)) /* not divisible by 2 */
  ------------------
  |  Branch (1248:7): [True: 0, False: 1.82k]
  |  Branch (1248:30): [True: 0, False: 1.82k]
  ------------------
 1249|  1.82k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1250|       |
 1251|  1.82k|		sc_log_hex(ctx, "select_file(PATH): requested", in_path->value, in_path->len);
  ------------------
  |  |  129|  1.82k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  1.82k|    _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|  1.82k|		res = sc_lock(card); /* lock to ensure path traversal */
 1255|  1.82k|		LOG_TEST_RET(ctx, res, "sc_lock() failed");
  ------------------
  |  |  174|  1.82k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.82k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.82k|	int _ret = (r); \
  |  |  |  |  168|  1.82k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.82k]
  |  |  |  |  ------------------
  |  |  |  |  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.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.82k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1256|  1.82k|		if (memcmp(in_path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (1256:7): [True: 1.64k, False: 184]
  ------------------
 1257|       |			/* if MF, use the name as path */
 1258|  1.64k|			strcpy((char *)tmp_path, DNIE_MF_NAME);
  ------------------
  |  |   69|  1.64k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1259|  1.64k|			sc_log_hex(ctx, "select_file(NAME): requested", tmp_path, sizeof(DNIE_MF_NAME) - 1);
  ------------------
  |  |  129|  1.64k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  1.64k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1260|  1.64k|			res = dnie_compose_and_send_apdu(card, tmp_path, sizeof(DNIE_MF_NAME) - 1, 4, file_out);
  ------------------
  |  |   69|  1.64k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1261|  1.64k|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  1.64k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1261:8): [True: 1.22k, False: 420]
  ------------------
 1262|  1.22k|				sc_unlock(card);
 1263|  1.22k|				LOG_TEST_RET(ctx, res, "select_file(NAME) failed");
  ------------------
  |  |  174|  1.22k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.22k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.22k|	int _ret = (r); \
  |  |  |  |  168|  1.22k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.22k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.22k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.22k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.22k|		return _ret; \
  |  |  |  |  172|  1.22k|	} \
  |  |  |  |  173|  1.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1264|  1.22k|			}
 1265|    420|			tmp_path[2] = 0;
 1266|    420|			reminder = in_path->len - 2;
 1267|    420|		} else {
 1268|    184|			tmp_path[2] = 0;
 1269|    184|			reminder = in_path->len;
 1270|    184|		}
 1271|    852|		while (reminder > 0) {
  ------------------
  |  Branch (1271:10): [True: 354, False: 498]
  ------------------
 1272|    354|			tmp_path[0] = in_path->value[in_path->len - reminder];
 1273|    354|			tmp_path[1] = in_path->value[1 + in_path->len - reminder];
 1274|    354|			sc_log(ctx, "select_file(PATH): requested:%s ", sc_dump_hex(tmp_path, 2));
  ------------------
  |  |   71|    354|#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|    354|			res = dnie_compose_and_send_apdu(card, tmp_path, 2, 0, file_out);
 1276|    354|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|    354|#define SC_SUCCESS				0
  ------------------
  |  Branch (1276:8): [True: 106, False: 248]
  ------------------
 1277|    106|				sc_unlock(card);
 1278|    106|				LOG_TEST_RET(ctx, res, "select_file(PATH) failed");
  ------------------
  |  |  174|    106|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    106|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    106|	int _ret = (r); \
  |  |  |  |  168|    106|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 106, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    106|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    106|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    106|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    106|		return _ret; \
  |  |  |  |  172|    106|	} \
  |  |  |  |  173|    106|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1279|    106|			}
 1280|    248|			reminder -= 2;
 1281|    248|		}
 1282|    498|		sc_unlock(card);
 1283|    498|		break;
 1284|      0|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (1284:2): [True: 0, False: 2.20k]
  ------------------
 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: 2.20k]
  ------------------
 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: 2.20k]
  ------------------
 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|  2.20k|	}
 1301|       |
 1302|       |	/* as last step clear data cache and return */
 1303|    875|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|    875|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1304|    875|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|    875|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    875|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    875|	int _ret = r; \
  |  |  |  |  155|    875|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 875, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    875|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    160|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 160, False: 715]
  |  |  |  |  ------------------
  |  |  |  |  157|    875|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    875|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    875|	return _ret; \
  |  |  |  |  163|    875|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1305|    875|}
card-dnie.c:dnie_compose_and_send_apdu:
 1129|  2.37k|{
 1130|  2.37k|	int res = 0;
 1131|  2.37k|	sc_apdu_t apdu;
 1132|  2.37k|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
 1133|  2.37k|	sc_context_t *ctx = NULL;
 1134|       |
 1135|  2.37k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1135:6): [True: 0, False: 2.37k]
  |  Branch (1135:15): [True: 0, False: 2.37k]
  ------------------
 1136|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1137|  2.37k|	ctx = card->ctx;
 1138|       |
 1139|  2.37k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.37k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.37k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.37k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.37k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1140|       |
 1141|  2.37k|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0,
  ------------------
  |  |  294|  2.37k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1142|  2.37k|					sc_get_max_recv_size(card), pathlen,
 1143|  2.37k|					rbuf, sizeof(rbuf), path, pathlen);
 1144|  2.37k|	if (p1 == 3)
  ------------------
  |  Branch (1144:6): [True: 0, False: 2.37k]
  ------------------
 1145|      0|		apdu.cse= SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1146|       |
 1147|  2.37k|	if (file_out == NULL)
  ------------------
  |  Branch (1147:6): [True: 1.24k, False: 1.12k]
  ------------------
 1148|  1.24k|		apdu.cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  1.24k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1149|       |
 1150|  2.37k|	res = sc_transmit_apdu(card, &apdu);
 1151|  2.37k|	if ((res != SC_SUCCESS) || (file_out == NULL))
  ------------------
  |  |   28|  2.37k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1151:6): [True: 70, False: 2.30k]
  |  Branch (1151:29): [True: 1.20k, False: 1.09k]
  ------------------
 1152|  2.37k|		LOG_TEST_RET(ctx, res, "SelectFile() APDU transmit 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: 70, False: 1.20k]
  |  |  |  |  ------------------
  |  |  |  |  169|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     70|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     70|		return _ret; \
  |  |  |  |  172|     70|	} \
  |  |  |  |  173|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1153|  2.30k|	if (file_out == NULL) {
  ------------------
  |  Branch (1153:6): [True: 1.20k, False: 1.09k]
  ------------------
 1154|  1.20k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1154:7): [True: 0, False: 1.20k]
  ------------------
 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|  1.20k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  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.20k, False: 0]
  |  |  ------------------
  |  |  156|  1.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    661|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 661, False: 545]
  |  |  ------------------
  |  |  157|  1.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.20k|	} else { \
  |  |  159|      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.20k|	return _ret; \
  |  |  163|  1.20k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1157|  1.20k|			       sc_check_sw(card, apdu.sw1, apdu.sw2));
 1158|  1.20k|	}
 1159|       |
 1160|       |	/* analyze response. if FCI, try to parse */
 1161|  1.09k|	res = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1162|  1.09k|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  1.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1162:6): [True: 591, False: 505]
  ------------------
 1163|    591|		LOG_TEST_RET(ctx, res, "SelectFile() check_sw failed");
  ------------------
  |  |  174|    591|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    591|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    591|	int _ret = (r); \
  |  |  |  |  168|    591|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 591, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    591|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    591|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    591|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    591|		return _ret; \
  |  |  |  |  172|    591|	} \
  |  |  |  |  173|    591|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|    591|	}
 1165|    505|	if ((apdu.resplen < 2) || (apdu.resp[0] == 0x00)) {
  ------------------
  |  Branch (1165:6): [True: 39, False: 466]
  |  Branch (1165:28): [True: 14, False: 452]
  ------------------
 1166|     53|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     53|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     53|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     53|	int _ret = r; \
  |  |  |  |  155|     53|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 53, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     53|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     53|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 53, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     53|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     53|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     53|	return _ret; \
  |  |  |  |  163|     53|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1167|     53|	}
 1168|       |
 1169|    452|	if (file_out) {
  ------------------
  |  Branch (1169:6): [True: 452, False: 0]
  ------------------
 1170|       |		/* finally process FCI response */
 1171|    452|		size_t len = apdu.resp[1];
 1172|    452|		sc_file_free(*file_out);
 1173|    452|		*file_out = sc_file_new();
 1174|    452|		if (*file_out == NULL) {
  ------------------
  |  Branch (1174:7): [True: 0, False: 452]
  ------------------
 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|    452|		if (apdu.resplen - 2 < len || len < 1) {
  ------------------
  |  Branch (1177:7): [True: 90, False: 362]
  |  Branch (1177:33): [True: 14, False: 348]
  ------------------
 1178|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1179|    104|		}
 1180|    348|		res = card->ops->process_fci(card, *file_out, apdu.resp + 2, len);
 1181|    348|	}
 1182|    348|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|    348|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    348|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    348|	int _ret = r; \
  |  |  |  |  155|    348|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 348, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    348|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 340]
  |  |  |  |  ------------------
  |  |  |  |  157|    348|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    348|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    348|	return _ret; \
  |  |  |  |  163|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1183|    348|}
card-dnie.c:dnie_check_sw:
 1750|  2.85k|{
 1751|  2.85k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  2.85k|#define SC_SUCCESS				0
  ------------------
 1752|  2.85k|	int n = 0;
 1753|  2.85k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1753:6): [True: 0, False: 2.85k]
  |  Branch (1753:15): [True: 0, False: 2.85k]
  ------------------
 1754|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1755|  2.85k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.85k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.85k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.85k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.85k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.85k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1756|       |
 1757|       |	/* check specific dnie errors */
 1758|  11.3k|	for (n = 0; dnie_errors[n].SWs != 0; n++) {
  ------------------
  |  Branch (1758:14): [True: 8.53k, False: 2.82k]
  ------------------
 1759|  8.53k|		if (dnie_errors[n].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (1759:7): [True: 29, False: 8.50k]
  ------------------
 1760|     29|			sc_log(card->ctx, "%s", dnie_errors[n].errorstr);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1761|     29|			return dnie_errors[n].errorno;
 1762|     29|		}
 1763|  8.53k|	}
 1764|       |
 1765|       |	/* arriving here means check for supported iso error codes */
 1766|  2.82k|	res = iso_ops->check_sw(card, sw1, sw2);
 1767|  2.82k|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|  2.82k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.82k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.82k|	int _ret = r; \
  |  |  |  |  155|  2.82k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.82k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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.51k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.51k, False: 1.30k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.82k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.82k|	return _ret; \
  |  |  |  |  163|  2.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1768|  2.82k|}
card-dnie.c:dnie_card_ctl:
 1787|     28|{
 1788|     28|	int result = SC_SUCCESS;
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
 1789|     28|	if ((card == NULL) || (card->ctx == NULL))
  ------------------
  |  Branch (1789:6): [True: 0, False: 28]
  |  Branch (1789:24): [True: 0, False: 28]
  ------------------
 1790|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1791|     28|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1792|     28|	if (data == NULL) {
  ------------------
  |  Branch (1792:6): [True: 0, False: 28]
  ------------------
 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|     28|	switch (request) {
 1796|       |		/* obtain lifecycle status by reading card->type */
 1797|     14|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1797:2): [True: 14, False: 14]
  ------------------
 1798|     14|		switch (card->type) {
  ------------------
  |  Branch (1798:11): [True: 14, False: 0]
  ------------------
 1799|      0|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (1799:3): [True: 0, False: 14]
  ------------------
 1800|      0|			result = SC_CARDCTRL_LIFECYCLE_ADMIN;
 1801|      0|			break;
 1802|     14|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (1802:3): [True: 14, False: 0]
  ------------------
 1803|     14|			result = SC_CARDCTRL_LIFECYCLE_USER;
 1804|     14|			break;
 1805|      0|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (1805:3): [True: 0, False: 14]
  ------------------
 1806|      0|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (1806:3): [True: 0, False: 14]
  ------------------
 1807|      0|			result = SC_CARDCTRL_LIFECYCLE_OTHER;
 1808|      0|			break;
 1809|     14|		}
 1810|     14|		*(int *)data = result;
 1811|     14|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|       |		/* call card to obtain serial number */
 1813|     14|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1813:2): [True: 14, False: 14]
  ------------------
 1814|     14|		result = dnie_get_serialnr(card, (sc_serial_number_t *) data);
 1815|     14|		LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  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|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1816|      0|	case SC_CARDCTL_DNIE_GENERATE_KEY:
  ------------------
  |  Branch (1816:2): [True: 0, False: 28]
  ------------------
 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: 28]
  ------------------
 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: 28]
  ------------------
 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|     28|	}
 1828|     28|}
card-dnie.c:dnie_get_serialnr:
  637|     14|{
  638|     14|	int result;
  639|     14|	sc_apdu_t apdu;
  640|     14|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
  641|     14|	if ((card == NULL) || (card->ctx == NULL) || (serial == NULL))
  ------------------
  |  Branch (641:6): [True: 0, False: 14]
  |  Branch (641:24): [True: 0, False: 14]
  |  Branch (641:47): [True: 0, False: 14]
  ------------------
  642|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  643|       |
  644|     14|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     14|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     14|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     14|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     14|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|     14|	if (card->type != SC_CARD_TYPE_DNIE_USER)
  ------------------
  |  Branch (645:6): [True: 0, False: 14]
  ------------------
  646|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  647|       |	/* if serial number is cached, use it */
  648|     14|	if (card->serialnr.len) {
  ------------------
  |  Branch (648:6): [True: 0, False: 14]
  ------------------
  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|     14|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xb8, 0x00, 0x00, 0x07, 0,
  ------------------
  |  |  292|     14|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  656|     14|					rbuf, sizeof(rbuf), NULL, 0);
  657|     14|	apdu.cla = 0x90;	/* proprietary cmd */
  658|       |	/* send apdu */
  659|     14|	result = sc_transmit_apdu(card, &apdu);
  660|     14|	if (result != SC_SUCCESS) {
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
  |  Branch (660:6): [True: 4, False: 10]
  ------------------
  661|      4|		LOG_TEST_RET(card->ctx, result, "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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  662|      4|	}
  663|     10|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (663:6): [True: 8, False: 2]
  |  Branch (663:26): [True: 1, False: 1]
  ------------------
  664|      9|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      9|#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|    348|{
 1926|    348|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    348|#define SC_SUCCESS				0
  ------------------
 1927|    348|	int *op = df_acl;
 1928|    348|	int n = 0;
 1929|    348|	sc_context_t *ctx = NULL;
 1930|    348|	if ((card == NULL) || (card->ctx == NULL) || (file == NULL) || buflen == 0)
  ------------------
  |  Branch (1930:6): [True: 0, False: 348]
  |  Branch (1930:24): [True: 0, False: 348]
  |  Branch (1930:47): [True: 0, False: 348]
  |  Branch (1930:65): [True: 0, False: 348]
  ------------------
 1931|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1932|    348|	ctx = card->ctx;
 1933|    348|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    348|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    348|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    348|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    348|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 348]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1934|       |	/* first of all, let iso do the hard work */
 1935|    348|	res = iso_ops->process_fci(card, file, buf, buflen);
 1936|    348|	LOG_TEST_RET(ctx, res, "iso7816_process_fci() failed");
  ------------------
  |  |  174|    348|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    348|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    348|	int _ret = (r); \
  |  |  |  |  168|    348|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 348]
  |  |  |  |  ------------------
  |  |  |  |  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|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 348]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    348|	if (file->prop_attr_len == 0) {	/* no proprietary tag (0x85) received */
  ------------------
  |  Branch (1940:6): [True: 315, False: 33]
  ------------------
 1941|    315|		res = SC_SUCCESS;
  ------------------
  |  |   28|    315|#define SC_SUCCESS				0
  ------------------
 1942|    315|		goto dnie_process_fci_end;
 1943|    315|	}
 1944|       |	/* at least 10 bytes should be received */
 1945|     33|	if (file->prop_attr_len < 10) {
  ------------------
  |  Branch (1945:6): [True: 6, False: 27]
  ------------------
 1946|      6|		res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      6|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1947|      6|		goto dnie_process_fci_end;
 1948|      6|	}
 1949|       |	/* byte 0 denotes file type */
 1950|     27|	switch (file->prop_attr[0]) {
 1951|     16|	case 0x01:		/* EF for plain files */
  ------------------
  |  Branch (1951:2): [True: 16, False: 11]
  ------------------
 1952|     16|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     16|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1953|     16|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     16|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1954|     16|		break;
 1955|      8|	case 0x15:		/* EF for keys: linear variable simple TLV */
  ------------------
  |  Branch (1955:2): [True: 8, False: 19]
  ------------------
 1956|      8|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      8|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1957|       |		/* pin file 3F000000 has also this EF type */
 1958|      8|		if ( ( file->prop_attr[2] == 0x00 ) && (file->prop_attr[3] == 0x00 ) ) {
  ------------------
  |  Branch (1958:8): [True: 3, False: 5]
  |  Branch (1958:42): [True: 2, False: 1]
  ------------------
 1959|      2|			sc_log(ctx,"Processing pin EF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1960|      2|			break;
 1961|      2|		}
 1962|       |		/* FCI response for Keys EF returns 3 additional bytes */
 1963|      6|		if (file->prop_attr_len < 13) {
  ------------------
  |  Branch (1963:7): [True: 1, False: 5]
  ------------------
 1964|      1|			sc_log(ctx, "FCI response len for Keys EF should be 13 bytes");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1965|      1|			res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      1|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1966|      1|			goto dnie_process_fci_end;
 1967|      1|		}
 1968|      5|		break;
 1969|      5|	case 0x24:		/* EF for compressed certificates */
  ------------------
  |  Branch (1969:2): [True: 1, False: 26]
  ------------------
 1970|      1|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      1|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1971|      1|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|      1|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1972|       |		/* evaluate real length by reading first 8 bytes from file */
 1973|      1|		res = dnie_read_header(card);
 1974|       |		/* Hey!, we need pin to read certificates... */
 1975|      1|		if (res == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|      1|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (1975:7): [True: 0, False: 1]
  ------------------
 1976|      0|			goto dnie_process_fci_end;
 1977|      1|		if (res <= 0) {
  ------------------
  |  Branch (1977:7): [True: 1, False: 0]
  ------------------
 1978|      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__
  |  |  ------------------
  ------------------
 1979|      1|			       "Cannot evaluate uncompressed size. use fci length");
 1980|      1|		} else {
 1981|      0|			sc_log(ctx, "Storing uncompressed size '%d' into fci",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1982|      0|			       res);
 1983|      0|			file->prop_attr[3] = (u8) ((res >> 8) & 0xff);
 1984|      0|			file->prop_attr[4] = (u8) (res & 0xff);
 1985|      0|		}
 1986|      1|		break;
 1987|      1|	case 0x38:		/* Errata: manual page 35 says wrong 0x34 */
  ------------------
  |  Branch (1987:2): [True: 1, False: 26]
  ------------------
 1988|      1|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      1|#define SC_FILE_TYPE_DF			0x04
  ------------------
 1989|      1|		break;
 1990|      1|	default:
  ------------------
  |  Branch (1990:2): [True: 1, False: 26]
  ------------------
 1991|      1|		res = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      1|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 1992|      1|		goto dnie_process_fci_end;
 1993|     27|	}
 1994|       |
 1995|       |	/* bytes 1 and 2 stores file ID */
 1996|     25|	file->id = ( ( 0xff & (int)file->prop_attr[1] ) << 8 ) |
 1997|     25|			( 0xff & (int)file->prop_attr[2] ) ;
 1998|       |
 1999|       |	/* bytes 3 and 4 states file length */
 2000|     25|	file->size = ( ( 0xff & (int)file->prop_attr[3] ) << 8 ) |
 2001|     25|			( 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|     25|	op = (file->type == SC_FILE_TYPE_DF) ? df_acl : ef_acl;
  ------------------
  |  |  214|     25|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (2010:7): [True: 1, False: 24]
  ------------------
 2011|    150|	for (n = 0; n < 5; n++) {
  ------------------
  |  Branch (2011:14): [True: 125, False: 25]
  ------------------
 2012|    125|		int key_ref = 0;
 2013|    125|		if (*(op + n) == -1)
  ------------------
  |  Branch (2013:7): [True: 25, False: 100]
  ------------------
 2014|     25|			continue;	/* unused entry: skip */
 2015|    100|		key_ref = file->prop_attr[5 + n] & 0x0F;
 2016|    100|		switch (0xF0 & file->prop_attr[5 + n]) {
 2017|     31|		case 0x00:
  ------------------
  |  Branch (2017:3): [True: 31, False: 69]
  ------------------
 2018|     31|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NONE,
  ------------------
  |  |  150|     31|#define SC_AC_NONE			0x00000000
  ------------------
 2019|     31|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     31|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2020|     31|			break;
 2021|     14|		case 0x10:
  ------------------
  |  Branch (2021:3): [True: 14, False: 86]
  ------------------
 2022|       |			/* this tag is omitted in official code
 2023|       |			   case 0x20:
 2024|       |			 */
 2025|     25|		case 0x30:
  ------------------
  |  Branch (2025:3): [True: 11, False: 89]
  ------------------
 2026|     25|			sc_file_add_acl_entry(file, *(op + n), SC_AC_CHV,
  ------------------
  |  |  151|     25|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2027|     25|					      key_ref);
 2028|     25|			break;
 2029|     12|		case 0x40:
  ------------------
  |  Branch (2029:3): [True: 12, False: 88]
  ------------------
 2030|     12|			sc_file_add_acl_entry(file, *(op + n), SC_AC_TERM,
  ------------------
  |  |  152|     12|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
 2031|     12|					      key_ref);
 2032|     12|			break;
 2033|     11|		case 0xF0:
  ------------------
  |  Branch (2033:3): [True: 11, False: 89]
  ------------------
 2034|     11|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NEVER,
  ------------------
  |  |  163|     11|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 2035|     11|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     11|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2036|     11|			break;
 2037|     21|		default:
  ------------------
  |  Branch (2037:3): [True: 21, False: 79]
  ------------------
 2038|     21|			sc_file_add_acl_entry(file, *(op + n), SC_AC_UNKNOWN,
  ------------------
  |  |  162|     21|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
 2039|     21|					      SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     21|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2040|     21|			break;
 2041|    100|		}
 2042|    100|	}
 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|     25|	if (file->prop_attr[0] == 0x15) {
  ------------------
  |  Branch (2050:6): [True: 7, False: 18]
  ------------------
 2051|      7|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2052|      7|		       "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|      7|	}
 2058|     25|	res = SC_SUCCESS;	/* arriving here means success */
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
 2059|    348| dnie_process_fci_end:
 2060|    348|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|    348|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    348|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    348|	int _ret = r; \
  |  |  |  |  155|    348|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 348, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    348|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 340]
  |  |  |  |  ------------------
  |  |  |  |  157|    348|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    348|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    348|	return _ret; \
  |  |  |  |  163|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2061|    348|}
card-dnie.c:dnie_read_header:
 1848|      1|{
 1849|      1|	sc_apdu_t apdu;
 1850|      1|	int r;
 1851|      1|	u8 buf[MAX_RESP_BUFFER_SIZE];
 1852|      1|	unsigned long uncompressed = 0L;
 1853|      1|	unsigned long compressed = 0L;
 1854|      1|	sc_context_t *ctx = NULL;
 1855|       |
 1856|      1|	if (!card || !card->ctx)
  ------------------
  |  Branch (1856:6): [True: 0, False: 1]
  |  Branch (1856:15): [True: 0, False: 1]
  ------------------
 1857|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1858|      1|	ctx = card->ctx;
 1859|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1860|       |
 1861|       |	/* initialize apdu */
 1862|      1|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00, 8, 0,
  ------------------
  |  |  292|      1|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1863|      1|					buf, MAX_RESP_BUFFER_SIZE, NULL, 0);
  ------------------
  |  |   56|      1|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
 1864|       |	/* transmit apdu */
 1865|      1|	r = sc_transmit_apdu(card, &apdu);
 1866|      1|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (1866:6): [True: 0, False: 1]
  ------------------
 1867|      0|		sc_log(ctx, "read_header() APDU transmit 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__
  |  |  ------------------
  ------------------
 1868|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1869|      0|	}
 1870|       |	/* check response */
 1871|      1|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1871:6): [True: 1, False: 0]
  ------------------
 1872|      1|		goto header_notcompressed;
 1873|      0|	uncompressed = lebytes2ulong(apdu.resp);
 1874|      0|	compressed = lebytes2ulong(apdu.resp + 4);
 1875|      0|	if (uncompressed < compressed)
  ------------------
  |  Branch (1875:6): [True: 0, False: 0]
  ------------------
 1876|      0|		goto header_notcompressed;
 1877|      0|	if (uncompressed > 32767)
  ------------------
  |  Branch (1877:6): [True: 0, False: 0]
  ------------------
 1878|      0|		goto header_notcompressed;
 1879|       |	/* ok: assume data is correct */
 1880|      0|	sc_log(ctx, "read_header: uncompressed file size is %lu", uncompressed);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1881|      0|	return (int)(0x7FFF & uncompressed);
 1882|       |
 1883|      1| header_notcompressed:
 1884|      1|	sc_log(ctx, "response doesn't match compressed file header");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1885|      1|	return 0;
 1886|      0|}
card-dnie.c:dnie_pin_cmd:
 2174|     14|{
 2175|     14|	int res = SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
 2176|     14|	int lc = SC_CARDCTRL_LIFECYCLE_USER;
 2177|       |
 2178|     14|	if ((card == NULL) || (card->ctx == NULL) || (data == NULL))
  ------------------
  |  Branch (2178:6): [True: 0, False: 14]
  |  Branch (2178:24): [True: 0, False: 14]
  |  Branch (2178:47): [True: 0, False: 14]
  ------------------
 2179|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2180|     14|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     14|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     14|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     14|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     14|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2181|       |
 2182|       |	/*
 2183|       |	* some flags and settings from documentation
 2184|       |	* No (easy) way to handle pinpad through SM, so disable it
 2185|       |	*/
 2186|     14|	data->flags &= ~SC_PIN_CMD_NEED_PADDING; /* no pin padding */
  ------------------
  |  |  422|     14|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2187|     14|	data->flags &= ~SC_PIN_CMD_USE_PINPAD;	 /* cannot handle pinpad */
  ------------------
  |  |  421|     14|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 2188|       |
 2189|       |	/* ensure that card is in USER Lifecycle */
 2190|     14|	res = dnie_card_ctl(card, SC_CARDCTL_LIFECYCLE_GET, &lc);
 2191|     14|	LOG_TEST_RET(card->ctx, res, "Cannot get card LC status");
  ------------------
  |  |  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: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2192|     14|	if (lc != SC_CARDCTRL_LIFECYCLE_USER) {
  ------------------
  |  Branch (2192:6): [True: 0, False: 14]
  ------------------
 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|     14|	switch (data->pin_type) {
 2198|     14|	case SC_AC_CHV:	/* Card Holder Verifier */
  ------------------
  |  |  151|     14|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2198:2): [True: 14, False: 0]
  ------------------
 2199|     14|		break;
 2200|      0|	case SC_AC_TERM:	/* Terminal auth */
  ------------------
  |  |  152|      0|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  |  Branch (2200:2): [True: 0, False: 14]
  ------------------
 2201|      0|	case SC_AC_PRO:	/* SM auth */
  ------------------
  |  |  153|      0|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  |  Branch (2201:2): [True: 0, False: 14]
  ------------------
 2202|      0|	case SC_AC_AUT:	/* Key auth */
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2202:2): [True: 0, False: 14]
  ------------------
 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: 14]
  ------------------
 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|     14|	}
 2207|       |	/* This DNIe driver only supports VERIFY operation */
 2208|     14|	switch (data->cmd) {
 2209|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2209:2): [True: 0, False: 14]
  ------------------
 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: 14]
  ------------------
 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: 14]
  ------------------
 2216|     14|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|     14|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2216:2): [True: 14, False: 0]
  ------------------
 2217|     14|		res= SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     14|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2218|     14|		break;
 2219|      0|	default:
  ------------------
  |  Branch (2219:2): [True: 0, False: 14]
  ------------------
 2220|      0|		res= SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2221|      0|		break;
 2222|     14|	}
 2223|       |	/* return result */
 2224|     14|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2225|     14|}

sc_get_dtrust_driver:
 1056|  8.50k|{
 1057|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1057:6): [True: 1, False: 8.49k]
  ------------------
 1058|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1059|       |
 1060|  8.50k|	dtrust_ops = *iso_ops;
 1061|  8.50k|	dtrust_ops.match_card = dtrust_match_card;
 1062|  8.50k|	dtrust_ops.init = dtrust_init;
 1063|  8.50k|	dtrust_ops.finish = dtrust_finish;
 1064|  8.50k|	dtrust_ops.pin_cmd = dtrust_pin_cmd;
 1065|  8.50k|	dtrust_ops.set_security_env = dtrust_set_security_env;
 1066|  8.50k|	dtrust_ops.compute_signature = dtrust_compute_signature;
 1067|  8.50k|	dtrust_ops.decipher = dtrust_decipher;
 1068|  8.50k|	dtrust_ops.logout = dtrust_logout;
 1069|       |
 1070|  8.50k|	return &dtrust_drv;
 1071|  8.50k|}
card-dtrust.c:dtrust_match_card:
  234|  8.10k|{
  235|  8.10k|	if (_sc_match_atr(card, dtrust_atrs, &card->type) < 0)
  ------------------
  |  Branch (235:6): [True: 8.07k, False: 28]
  ------------------
  236|  8.07k|		return 0;
  237|       |
  238|     28|	if (_dtrust_match_cardos(card) != SC_SUCCESS)
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  |  Branch (238:6): [True: 28, False: 0]
  ------------------
  239|     28|		return 0;
  240|       |
  241|      0|	if (_dtrust_match_profile(card) != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (241:6): [True: 0, False: 0]
  ------------------
  242|      0|		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|      0|}
card-dtrust.c:_dtrust_match_cardos:
  114|     28|{
  115|     28|	int r;
  116|     28|	size_t prodlen;
  117|     28|	u8 buf[32];
  118|       |
  119|       |	/* check OS version */
  120|     28|	r = sc_get_data(card, 0x0182, buf, 32);
  121|     28|	LOG_TEST_RET(card->ctx, r, "OS version check 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: 7, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  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|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 21]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     21|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (123:6): [True: 1, False: 20]
  ------------------
  124|      1|		if (r != 2 || buf[0] != 0xc9 || buf[1] != 0x04)
  ------------------
  |  Branch (124:7): [True: 1, False: 0]
  |  Branch (124:17): [True: 0, False: 0]
  |  Branch (124:35): [True: 0, False: 0]
  ------------------
  125|      1|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      1|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  126|     20|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (126:13): [True: 20, False: 0]
  ------------------
  127|     20|		if (r != 2 || buf[0] != 0xcb || buf[1] != 0x01)
  ------------------
  |  Branch (127:7): [True: 4, False: 16]
  |  Branch (127:17): [True: 2, False: 14]
  |  Branch (127:35): [True: 2, False: 12]
  ------------------
  128|      8|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      8|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  129|     20|	}
  130|       |
  131|       |	/* check product name */
  132|     12|	r = sc_get_data(card, 0x0180, buf, 32);
  133|     12|	LOG_TEST_RET(card->ctx, r, "Product name check 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: 4, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|       |
  135|      8|	prodlen = (size_t)r;
  136|      8|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (136:6): [True: 0, False: 8]
  ------------------
  137|      0|		if (prodlen != strlen("CardOS V5.4     2019") + 1 || memcmp(buf, "CardOS V5.4     2019", prodlen))
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  |  Branch (137:56): [True: 0, False: 0]
  ------------------
  138|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  139|      8|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (139:13): [True: 8, False: 0]
  ------------------
  140|      8|		if (prodlen != strlen("CardOS V6.0 2021") + 1 || memcmp(buf, "CardOS V6.0 2021", prodlen))
  ------------------
  |  Branch (140:7): [True: 3, False: 5]
  |  Branch (140:52): [True: 5, False: 0]
  ------------------
  141|      8|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      8|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|      8|	}
  143|       |
  144|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  145|      8|}

sc_get_edo_driver:
  306|  8.50k|struct sc_card_driver* sc_get_edo_driver(void) {
  307|  8.50k|	edo_ops = *sc_get_iso7816_driver()->ops;
  308|  8.50k|	edo_ops.match_card = edo_match_card;
  309|  8.50k|	edo_ops.init = edo_init;
  310|  8.50k|	edo_ops.select_file = edo_select_file;
  311|  8.50k|	edo_ops.set_security_env = edo_set_security_env;
  312|  8.50k|	edo_ops.compute_signature = edo_compute_signature;
  313|  8.50k|	edo_ops.logout = edo_logout;
  314|       |
  315|  8.50k|	return &edo_drv;
  316|  8.50k|}
card-edo.c:edo_match_card:
   62|  5.08k|static int edo_match_card(sc_card_t* card) {
   63|  5.08k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.08k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.08k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.08k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.08k]
  |  |  ------------------
  ------------------
   64|  5.08k|	if (_sc_match_atr(card, edo_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (64:6): [True: 0, False: 5.08k]
  ------------------
   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|  5.08k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  5.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.08k|	int _ret = r; \
  |  |  |  |  155|  5.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.08k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.08k|	return _ret; \
  |  |  |  |  163|  5.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   69|  5.08k|}

sc_get_entersafe_driver:
 1579|  8.50k|{
 1580|  8.50k|	return sc_get_driver();
 1581|  8.50k|}
card-entersafe.c:sc_get_driver:
 1553|  8.50k|{
 1554|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1555|       |
 1556|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1556:6): [True: 1, False: 8.49k]
  ------------------
 1557|      1|		iso_ops = iso_drv->ops;
 1558|       |
 1559|  8.50k|	entersafe_ops = *iso_drv->ops;
 1560|  8.50k|	entersafe_ops.match_card = entersafe_match_card;
 1561|  8.50k|	entersafe_ops.init = entersafe_init;
 1562|  8.50k|	entersafe_ops.read_binary = entersafe_read_binary;
 1563|  8.50k|	entersafe_ops.write_binary = NULL;
 1564|  8.50k|	entersafe_ops.update_binary = entersafe_update_binary;
 1565|  8.50k|	entersafe_ops.select_file = entersafe_select_file;
 1566|  8.50k|	entersafe_ops.restore_security_env = entersafe_restore_security_env;
 1567|  8.50k|	entersafe_ops.set_security_env = entersafe_set_security_env;
 1568|  8.50k|	entersafe_ops.decipher = entersafe_decipher;
 1569|  8.50k|	entersafe_ops.compute_signature = entersafe_compute_signature;
 1570|  8.50k|	entersafe_ops.create_file = entersafe_create_file;
 1571|       |	entersafe_ops.delete_file = NULL;
 1572|  8.50k|	entersafe_ops.pin_cmd = entersafe_pin_cmd;
 1573|  8.50k|	entersafe_ops.card_ctl = entersafe_card_ctl_2048;
 1574|  8.50k|	entersafe_ops.process_fci = entersafe_process_fci;
 1575|  8.50k|	return &entersafe_drv;
 1576|  8.50k|}
card-entersafe.c:entersafe_match_card:
  135|  7.00k|{
  136|  7.00k|	int i;
  137|  7.00k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.00k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.00k]
  |  |  ------------------
  ------------------
  138|       |
  139|  7.00k|	i = _sc_match_atr(card, entersafe_atrs, &card->type);
  140|  7.00k|	if (i < 0)
  ------------------
  |  Branch (140:6): [True: 6.90k, False: 100]
  ------------------
  141|  6.90k|		return 0;
  142|       |
  143|    100|	return 1;
  144|  7.00k|}
card-entersafe.c:entersafe_init:
  147|    100|{
  148|    100|	unsigned int flags;
  149|       |
  150|    100|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    100|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    100|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    100|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 100]
  |  |  ------------------
  ------------------
  151|       |
  152|    100|	card->name = "entersafe";
  153|    100|	card->cla  = 0x00;
  154|    100|	card->drv_data = NULL;
  155|       |
  156|    100|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    100|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    100|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    100|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  157|       |
  158|    100|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  159|    100|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  160|    100|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  161|    100|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  162|       |
  163|    100|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    100|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  164|       |
  165|       |	/* we need read_binary&friends with max 224 bytes per read */
  166|    100|	card->max_send_size = 224;
  167|    100|	card->max_recv_size = 224;
  168|    100|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 100]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  169|    100|}
card-entersafe.c:entersafe_read_binary:
  427|    759|{
  428|    759|	sc_apdu_t apdu;
  429|    759|	u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  430|    759|	int r;
  431|       |
  432|    759|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    759|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    759|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    759|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 759]
  |  |  ------------------
  ------------------
  433|       |
  434|    759|	if (count > card->max_recv_size)
  ------------------
  |  Branch (434:6): [True: 0, False: 759]
  ------------------
  435|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  436|    759|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0xFF, idx & 0xFF);
  ------------------
  |  |  292|    759|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  437|       |
  438|    759|	apdu.cla = idx > 0x7fff ? 0x80 : 0x00;
  ------------------
  |  Branch (438:13): [True: 0, False: 759]
  ------------------
  439|    759|	apdu.le = count;
  440|    759|	apdu.resplen = count;
  441|    759|	apdu.resp = recvbuf;
  442|       |
  443|    759|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  444|    759|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    759|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    759|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    759|	int _ret = (r); \
  |  |  |  |  168|    759|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 744]
  |  |  |  |  ------------------
  |  |  |  |  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|    759|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 744]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  445|    744|	if (apdu.resplen == 0)
  ------------------
  |  Branch (445:6): [True: 43, False: 701]
  ------------------
  446|     43|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     43|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     43|	int _ret = r; \
  |  |  155|     43|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 43, False: 0]
  |  |  ------------------
  |  |  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|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 34, False: 9]
  |  |  ------------------
  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     43|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     43|	return _ret; \
  |  |  163|     43|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  447|    701|	memcpy(buf, recvbuf, apdu.resplen);
  448|       |
  449|    701|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)apdu.resplen);
  ------------------
  |  |  153|    701|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    701|	int _ret = r; \
  |  |  155|    701|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 701]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    701|	} else { \
  |  |  159|    701|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    701|			"returning with: %d\n", _ret); \
  |  |  161|    701|	} \
  |  |  162|    701|	return _ret; \
  |  |  163|    701|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  450|    701|}
card-entersafe.c:entersafe_transmit_apdu:
  370|    860|{
  371|    860|	u8 *cipher_data = NULL, *mac_data = NULL;
  372|    860|	size_t cipher_data_size, mac_data_size, blocks;
  373|    860|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    860|#define SC_SUCCESS				0
  ------------------
  374|    860|	u8 *sbuf = NULL;
  375|    860|	size_t ssize = 0;
  376|       |
  377|    860|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (377:6): [True: 0, False: 860]
  |  Branch (377:22): [True: 0, False: 860]
  ------------------
  378|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  379|       |
  380|    860|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    860|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    860|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    860|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 860]
  |  |  ------------------
  ------------------
  381|       |
  382|    860|	if ((cipher || mac) && (!key || (keylen != 8 && keylen != 16)))
  ------------------
  |  Branch (382:7): [True: 0, False: 860]
  |  Branch (382:17): [True: 0, False: 860]
  |  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|    860|	r = sc_apdu_get_octets(card->ctx, apdu, &sbuf, &ssize, SC_PROTO_RAW);
  ------------------
  |  |  354|    860|#define SC_PROTO_RAW		0x00001000
  ------------------
  386|    860|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    860|#define SC_SUCCESS				0
  ------------------
  |  Branch (386:6): [True: 860, False: 0]
  ------------------
  387|    860|		sc_apdu_log(card->ctx, sbuf, ssize, 1);
  ------------------
  |  |  292|    860|	sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
  |  |  ------------------
  |  |  |  |  127|  1.72k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (127:65): [True: 860, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|    860|	if (sbuf)
  ------------------
  |  Branch (388:6): [True: 860, False: 0]
  ------------------
  389|    860|		free(sbuf);
  390|       |
  391|    860|	if (cipher) {
  ------------------
  |  Branch (391:6): [True: 0, False: 860]
  ------------------
  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|    860|	if (mac) {
  ------------------
  |  Branch (403:6): [True: 0, False: 860]
  ------------------
  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|    860|	r = sc_transmit_apdu(card, apdu);
  416|       |
  417|    860|out:
  418|    860|	free(cipher_data);
  419|    860|	free(mac_data);
  420|       |
  421|    860|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    860|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    860|	int _ret = r; \
  |  |  155|    860|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 860, False: 0]
  |  |  ------------------
  |  |  156|    860|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 19, False: 841]
  |  |  ------------------
  |  |  157|    860|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    860|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    860|	return _ret; \
  |  |  163|    860|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  422|    860|}
card-entersafe.c:entersafe_select_file:
  590|    476|{
  591|    476|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (591:6): [True: 0, False: 476]
  |  Branch (591:22): [True: 0, False: 476]
  ------------------
  592|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  593|    476|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  594|       |
  595|    476|	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: 476]
  ------------------
  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|    180|		case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    180|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (600:3): [True: 180, False: 296]
  ------------------
  601|    180|			return entersafe_select_aid(card, in_path, file_out);
  602|    296|		case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    296|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (602:3): [True: 296, False: 180]
  ------------------
  603|    296|			return entersafe_select_path(card, in_path->value, in_path->len, file_out);
  604|      0|		default:
  ------------------
  |  Branch (604:3): [True: 0, False: 476]
  ------------------
  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|    476|	}
  607|    476|}
card-entersafe.c:entersafe_select_fid:
  503|    425|{
  504|    425|	int r;
  505|    425|	sc_file_t *file = NULL;
  506|    425|	sc_path_t path;
  507|       |
  508|    425|	memset(&path, 0, sizeof(sc_path_t));
  509|       |
  510|    425|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    425|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  511|    425|	path.value[0] = id_hi;
  512|    425|	path.value[1] = id_lo;
  513|    425|	path.len = 2;
  514|       |
  515|    425|	r = iso_ops->select_file(card, &path, &file);
  516|    425|	if (r < 0)
  ------------------
  |  Branch (516:6): [True: 205, False: 220]
  ------------------
  517|    205|		sc_file_free(file);
  518|    425|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    425|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    425|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    425|	int _ret = (r); \
  |  |  |  |  168|    425|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 205, False: 220]
  |  |  |  |  ------------------
  |  |  |  |  169|    205|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    205|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    205|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    205|		return _ret; \
  |  |  |  |  172|    205|	} \
  |  |  |  |  173|    425|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 220]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|       |
  520|    220|	if (file_out)
  ------------------
  |  Branch (520:6): [True: 79, False: 141]
  ------------------
  521|     79|		*file_out = file;
  522|    141|	else
  523|    141|		sc_file_free(file);
  524|       |
  525|    220|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    220|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    220|	int _ret = r; \
  |  |  155|    220|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 220, False: 0]
  |  |  ------------------
  |  |  156|    220|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 220]
  |  |  ------------------
  |  |  157|    220|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    220|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    220|	return _ret; \
  |  |  163|    220|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  526|    220|}
card-entersafe.c:entersafe_select_aid:
  531|    180|{
  532|    180|	int r;
  533|       |
  534|    180|	r = iso_ops->select_file(card, in_path, file_out);
  535|    180|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    180|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    180|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    180|	int _ret = (r); \
  |  |  |  |  168|    180|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 158, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  169|    158|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    158|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    158|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    158|		return _ret; \
  |  |  |  |  172|    158|	} \
  |  |  |  |  173|    180|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|       |
  537|     22|	if (file_out) {
  ------------------
  |  Branch (537:6): [True: 0, False: 22]
  ------------------
  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|     22|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 22]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  552|     22|}
card-entersafe.c:entersafe_select_path:
  557|    296|{
  558|    296|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
  559|    296|	const u8 *path = pathbuf;
  560|    296|	size_t pathlen = len;
  561|    296|	unsigned int i;
  562|    296|	int r;
  563|       |
  564|    296|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (564:6): [True: 0, False: 296]
  |  Branch (564:26): [True: 0, False: 296]
  |  Branch (564:41): [True: 0, False: 296]
  ------------------
  565|      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]
  |  |  ------------------
  ------------------
  566|       |
  567|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  568|    296|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (568:6): [True: 19, False: 277]
  |  Branch (568:23): [True: 0, False: 19]
  |  Branch (568:42): [True: 0, False: 19]
  ------------------
  569|      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]
  |  |  ------------------
  ------------------
  570|       |
  571|       |	/* unify path (the first FID should be MF) */
  572|    296|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (572:6): [True: 12, False: 284]
  |  Branch (572:25): [True: 0, False: 284]
  ------------------
  573|     12|		n_pathbuf[0] = 0x3f;
  574|     12|		n_pathbuf[1] = 0x00;
  575|     12|		memcpy(n_pathbuf + 2, path, pathlen);
  576|     12|		path = n_pathbuf;
  577|     12|		pathlen += 2;
  578|     12|	}
  579|       |
  580|    425|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (580:14): [True: 311, False: 114]
  ------------------
  581|    311|		r = entersafe_select_fid(card, path[i], path[i + 1], NULL);
  582|    311|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    311|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    311|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    311|	int _ret = (r); \
  |  |  |  |  168|    311|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 182, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  169|    182|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    182|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    182|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    182|		return _ret; \
  |  |  |  |  172|    182|	} \
  |  |  |  |  173|    311|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|    311|	}
  584|    114|	return entersafe_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  585|    296|}
card-entersafe.c:entersafe_pin_cmd:
  880|      4|{
  881|      4|	int r;
  882|      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]
  |  |  ------------------
  ------------------
  883|      4|	entersafe_init_pin_info(&data->pin1, 0);
  884|      4|	entersafe_init_pin_info(&data->pin2, 1);
  885|      4|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      4|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  886|       |
  887|      4|	if (data->cmd != SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|      4|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (887:6): [True: 4, False: 0]
  ------------------
  888|      4|		r = iso_ops->pin_cmd(card, data);
  889|      4|		sc_log(card->ctx, "Verify rv:%i", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  890|      4|	} 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|      4|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  929|      4|}
card-entersafe.c:entersafe_init_pin_info:
  870|      8|{
  871|      8|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      8|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  872|      8|	pin->min_length = 4;
  873|      8|	pin->max_length = 16;
  874|      8|	pin->pad_length = 16;
  875|      8|	pin->offset     = 5 + num * 16;
  876|      8|	pin->pad_char   = 0x00;
  877|      8|}
card-entersafe.c:entersafe_card_ctl_2048:
 1522|    101|{
 1523|    101|	sc_entersafe_create_data *tmp = (sc_entersafe_create_data *)ptr;
 1524|       |
 1525|    101|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1526|       |
 1527|    101|	switch (cmd) {
 1528|      0|		case SC_CARDCTL_ENTERSAFE_CREATE_FILE:
  ------------------
  |  Branch (1528:3): [True: 0, False: 101]
  ------------------
 1529|      0|			if (tmp->type == SC_ENTERSAFE_MF_DATA)
  ------------------
  |  |  665|      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)
  ------------------
  |  |  666|      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)
  ------------------
  |  |  667|      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: 101]
  ------------------
 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: 101]
  ------------------
 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: 101]
  ------------------
 1542|      0|			return entersafe_erase_card(card);
 1543|    101|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1543:3): [True: 101, False: 0]
  ------------------
 1544|    101|			return entersafe_get_serialnr(card, (sc_serial_number_t *)ptr);
 1545|      0|		case SC_CARDCTL_ENTERSAFE_PREINSTALL_KEYS:
  ------------------
  |  Branch (1545:3): [True: 0, False: 101]
  ------------------
 1546|      0|			return entersafe_preinstall_keys(card, entersafe_preinstall_rsa_2048);
 1547|      0|		default:
  ------------------
  |  Branch (1547:3): [True: 0, False: 101]
  ------------------
 1548|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1549|    101|	}
 1550|    101|}
card-entersafe.c:entersafe_get_serialnr:
 1347|    101|{
 1348|    101|	int	r;
 1349|    101|	sc_apdu_t apdu;
 1350|    101|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1351|       |
 1352|    101|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1353|    101|	if (serial == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 101]
  ------------------
 1354|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1355|       |
 1356|    101|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xEA, 0x00, 0x00);
  ------------------
  |  |  292|    101|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1357|    101|	apdu.cla = 0x80;
 1358|    101|	apdu.resp = rbuf;
 1359|    101|	apdu.resplen = sizeof(rbuf);
 1360|    101|	apdu.le = 0x08;
 1361|       |
 1362|    101|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
 1363|    101|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 4, False: 97]
  |  |  |  |  ------------------
  |  |  |  |  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|    101|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1364|     97|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "EnterSafe get SN 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: 82, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|     82|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     82|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     82|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     82|		return _ret; \
  |  |  |  |  172|     82|	} \
  |  |  |  |  173|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1365|     15|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1365:6): [True: 14, False: 1]
  ------------------
 1366|     15|		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|      1|	card->serialnr.len = serial->len = 8;
 1369|      1|	memcpy(card->serialnr.value, rbuf, 8);
 1370|      1|	memcpy(serial->value, rbuf, 8);
 1371|       |
 1372|      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]
  |  |  ------------------
  ------------------
 1373|      1|}
card-entersafe.c:entersafe_process_fci:
  479|    126|{
  480|    126|	int r;
  481|       |
  482|    126|	if (file == NULL)
  ------------------
  |  Branch (482:6): [True: 0, False: 126]
  ------------------
  483|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  484|    126|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  485|       |
  486|    126|	r = iso_ops->process_fci(card, file, buf, buflen);
  487|    126|	LOG_TEST_RET(card->ctx, r, "Process fci failed");
  ------------------
  |  |  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: 0, False: 126]
  |  |  |  |  ------------------
  |  |  |  |  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|    126|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 126]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  488|       |
  489|    126|	if (file->namelen) {
  ------------------
  |  Branch (489:6): [True: 8, False: 118]
  ------------------
  490|      8|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      8|#define SC_FILE_TYPE_DF			0x04
  ------------------
  491|      8|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      8|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  492|    118|	} else {
  493|    118|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    118|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  494|    118|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    118|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  495|    118|	}
  496|       |
  497|    126|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    126|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    126|	int _ret = r; \
  |  |  155|    126|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 126, False: 0]
  |  |  ------------------
  |  |  156|    126|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 126]
  |  |  ------------------
  |  |  157|    126|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    126|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    126|	return _ret; \
  |  |  163|    126|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  498|    126|}

sc_get_eoi_driver:
  566|  8.50k|{
  567|  8.50k|	eoi_ops = *sc_get_iso7816_driver()->ops;
  568|       |
  569|  8.50k|	eoi_ops.match_card = eoi_match_card;
  570|  8.50k|	eoi_ops.init = eoi_init;
  571|  8.50k|	eoi_ops.finish = eoi_finish;
  572|  8.50k|	eoi_ops.select_file = eoi_select_file;
  573|  8.50k|	eoi_ops.logout = eoi_logout;
  574|  8.50k|	eoi_ops.pin_cmd = eoi_pin_cmd;
  575|  8.50k|	eoi_ops.card_ctl = eoi_card_ctl;
  576|  8.50k|	eoi_ops.set_security_env = eoi_set_security_env;
  577|  8.50k|	eoi_ops.compute_signature = eoi_compute_signature;
  578|       |
  579|  8.50k|	return &eoi_drv;
  580|  8.50k|}
card-eoi.c:eoi_match_card:
  236|  1.93k|static int eoi_match_card(sc_card_t* card) {
  237|  1.93k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  238|  1.93k|	if (_sc_match_atr(card, eoi_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (238:6): [True: 0, False: 1.93k]
  ------------------
  239|      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__
  |  |  ------------------
  ------------------
  240|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  241|      0|	}
  242|  1.93k|	LOG_FUNC_RETURN(card->ctx, !ATR_MATCH);
  ------------------
  |  |  164|  1.93k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.93k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.93k|	int _ret = r; \
  |  |  |  |  155|  1.93k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.93k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.93k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.93k|	} else { \
  |  |  |  |  159|      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.93k|	return _ret; \
  |  |  |  |  163|  1.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|  1.93k|}

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

sc_get_esteid2018_driver:
  303|  8.50k|struct sc_card_driver *sc_get_esteid2018_driver(void) {
  304|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  305|       |
  306|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (306:6): [True: 1, False: 8.49k]
  ------------------
  307|      1|		iso_ops = iso_drv->ops;
  308|       |
  309|  8.50k|	esteid_ops = *iso_drv->ops;
  310|  8.50k|	esteid_ops.match_card = esteid_match_card;
  311|  8.50k|	esteid_ops.init = esteid_init;
  312|  8.50k|	esteid_ops.finish = esteid_finish;
  313|       |
  314|  8.50k|	esteid_ops.select_file = esteid_select_file;
  315|       |
  316|  8.50k|	esteid_ops.set_security_env = esteid_set_security_env;
  317|  8.50k|	esteid_ops.compute_signature = esteid_compute_signature;
  318|  8.50k|	esteid_ops.pin_cmd = esteid_pin_cmd;
  319|  8.50k|	esteid_ops.logout = esteid_logout;
  320|       |
  321|  8.50k|	return &esteid2018_driver;
  322|  8.50k|}
card-esteid2018.c:esteid_match_card:
   83|  5.08k|static int esteid_match_card(sc_card_t *card) {
   84|  5.08k|	int i = _sc_match_atr(card, esteid_atrs, &card->type);
   85|       |
   86|  5.08k|	if (i >= 0 && gp_select_aid(card, &IASECC_AID) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (86:6): [True: 0, False: 5.08k]
  |  Branch (86:16): [True: 0, False: 0]
  ------------------
   87|      0|		card->name = esteid_atrs[i].name;
   88|      0|		return 1;
   89|      0|	}
   90|  5.08k|	return 0;
   91|  5.08k|}

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

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

sc_get_gemsafeV1_driver:
  591|  8.50k|{
  592|  8.50k|	return sc_get_driver();
  593|  8.50k|}
card-gemsafeV1.c:sc_get_driver:
  566|  8.50k|{
  567|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  568|  8.50k|	if (!iso_ops)
  ------------------
  |  Branch (568:6): [True: 1, False: 8.49k]
  ------------------
  569|      1|		iso_ops = iso_drv->ops;
  570|       |	/* use the standard iso operations as default */
  571|  8.50k|	gemsafe_ops = *iso_drv->ops;
  572|       |	/* gemsafe specific functions */
  573|  8.50k|	gemsafe_ops.match_card	= gemsafe_match_card;
  574|  8.50k|	gemsafe_ops.init	= gemsafe_init;
  575|  8.50k|	gemsafe_ops.finish	= gemsafe_finish;
  576|  8.50k|	gemsafe_ops.select_file	= gemsafe_select_file;
  577|  8.50k|	gemsafe_ops.restore_security_env = gemsafe_restore_security_env;
  578|  8.50k|	gemsafe_ops.set_security_env     = gemsafe_set_security_env;
  579|  8.50k|	gemsafe_ops.decipher             = gemsafe_decipher;
  580|  8.50k|	gemsafe_ops.compute_signature    = gemsafe_compute_signature;
  581|  8.50k|	gemsafe_ops.get_challenge 		 = gemsafe_get_challenge;
  582|  8.50k|	gemsafe_ops.process_fci	= gemsafe_process_fci;
  583|  8.50k|	gemsafe_ops.pin_cmd		 = iso_ops->pin_cmd;
  584|  8.50k|	gemsafe_ops.card_reader_lock_obtained = gemsafe_card_reader_lock_obtained;
  585|  8.50k|	gemsafe_ops.logout = gemsafe_logout;
  586|       |
  587|  8.50k|	return &gemsafe_drv;
  588|  8.50k|}
card-gemsafeV1.c:gemsafe_match_card:
  124|  7.70k|{
  125|  7.70k|	int i;
  126|       |
  127|  7.70k|	i = _sc_match_atr(card, gemsafe_atrs, &card->type);
  128|  7.70k|	if (i < 0)
  ------------------
  |  Branch (128:6): [True: 7.70k, False: 0]
  ------------------
  129|  7.70k|		return 0;
  130|       |
  131|      0|	return 1;
  132|  7.70k|}

sc_get_gids_driver:
 2185|  8.50k|{
 2186|  8.50k|	return sc_get_driver();
 2187|  8.50k|}
card-gids.c:sc_get_driver:
 2140|  8.50k|{
 2141|       |
 2142|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2142:6): [True: 1, False: 8.49k]
  ------------------
 2143|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2144|       |
 2145|  8.50k|	gids_ops.match_card = gids_match_card;
 2146|  8.50k|	gids_ops.init = gids_init;
 2147|  8.50k|	gids_ops.finish = gids_finish;
 2148|  8.50k|	gids_ops.read_binary = gids_read_binary;
 2149|  8.50k|	gids_ops.write_binary = NULL;
 2150|  8.50k|	gids_ops.update_binary = NULL;
 2151|  8.50k|	gids_ops.erase_binary = NULL;
 2152|  8.50k|	gids_ops.read_record = NULL;
 2153|  8.50k|	gids_ops.write_record = NULL;
 2154|  8.50k|	gids_ops.append_record = NULL;
 2155|  8.50k|	gids_ops.update_record = NULL;
 2156|  8.50k|	gids_ops.select_file = gids_select_file;
 2157|  8.50k|	gids_ops.get_response = iso_ops->get_response;
 2158|  8.50k|	gids_ops.get_challenge = NULL;
 2159|  8.50k|	gids_ops.verify = NULL; // see pin_cmd
 2160|  8.50k|	gids_ops.logout = gids_logout;
 2161|  8.50k|	gids_ops.restore_security_env = NULL;
 2162|  8.50k|	gids_ops.set_security_env = gids_set_security_env;
 2163|  8.50k|	gids_ops.decipher = gids_decipher;
 2164|  8.50k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2165|  8.50k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2166|  8.50k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2167|  8.50k|	gids_ops.create_file = iso_ops->create_file;
 2168|  8.50k|	gids_ops.delete_file = NULL;
 2169|  8.50k|	gids_ops.list_files = NULL;
 2170|  8.50k|	gids_ops.check_sw = iso_ops->check_sw;
 2171|  8.50k|	gids_ops.card_ctl = gids_card_ctl;
 2172|  8.50k|	gids_ops.process_fci = iso_ops->process_fci;
 2173|  8.50k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2174|  8.50k|	gids_ops.pin_cmd = gids_pin_cmd;
 2175|  8.50k|	gids_ops.get_data = NULL;
 2176|  8.50k|	gids_ops.put_data = NULL;
 2177|  8.50k|	gids_ops.delete_record = NULL;
 2178|  8.50k|	gids_ops.read_public_key = gids_read_public_key;
 2179|  8.50k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2180|       |
 2181|  8.50k|	return &gids_drv;
 2182|  8.50k|}
card-gids.c:gids_match_card:
  563|  2.60k|{
  564|  2.60k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  565|  2.60k|	int r,i;
  566|  2.60k|	size_t resplen = sizeof(rbuf);
  567|  2.60k|	const u8 *tag;
  568|  2.60k|	size_t taglen;
  569|  2.60k|	const u8 *aid;
  570|  2.60k|	size_t aidlen;
  571|       |
  572|  2.60k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.60k]
  |  |  ------------------
  ------------------
  573|       |
  574|       |	/* Detect by selecting applet */
  575|  2.60k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  576|  2.60k|	if (r<0) return 0;
  ------------------
  |  Branch (576:6): [True: 2.56k, False: 41]
  ------------------
  577|       |
  578|     41|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  579|     41|	if (resplen > 2) {
  ------------------
  |  Branch (579:6): [True: 21, False: 20]
  ------------------
  580|     21|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     21|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  581|     21|		if (tag != NULL) {
  ------------------
  |  Branch (581:7): [True: 9, False: 12]
  ------------------
  582|      9|			aid = sc_asn1_find_tag(card->ctx, tag, taglen, GIDS_APPLICATION_AID_TAG, &aidlen);
  ------------------
  |  |  106|      9|#define GIDS_APPLICATION_AID_TAG 0x4F
  ------------------
  583|      9|			if (aid != NULL ) {
  ------------------
  |  Branch (583:8): [True: 7, False: 2]
  ------------------
  584|      7|				sc_log(card->ctx, "found AID");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  585|     18|				for (i = 0; gids_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (585:17): [True: 13, False: 5]
  ------------------
  586|     13|					if ( aidlen > gids_aids[i].len_long && memcmp(aid, gids_aids[i].value,
  ------------------
  |  Branch (586:11): [True: 11, False: 2]
  |  Branch (586:45): [True: 2, False: 9]
  ------------------
  587|     11|									gids_aids[i].len_long) == 0) {
  588|      2|						card->type = gids_aids[i].enumtag;
  589|      2|						break;
  590|      2|					}
  591|     13|				}
  592|      7|			}
  593|      9|		}
  594|     21|	}
  595|       |
  596|     41|	return 1;
  597|  2.60k|}
card-gids.c:gids_select_aid:
  280|  2.60k|{
  281|  2.60k|	sc_apdu_t apdu;
  282|  2.60k|	int r;
  283|       |
  284|  2.60k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.60k]
  |  |  ------------------
  ------------------
  285|  2.60k|	sc_log(card->ctx, "Got args: aid=%p, aidlen=%zu, response=%p, responselen=%zu",
  ------------------
  |  |   71|  5.21k|#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: 2.60k, False: 0]
  |  |  ------------------
  ------------------
  286|  2.60k|			aid, aidlen, response, responselen ? *responselen : 0);
  287|       |
  288|  2.60k|	sc_format_apdu(card, &apdu,
  289|  2.60k|		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|  2.60k|#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|  2.60k|#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|  2.60k|#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|  2.60k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (289:3): [True: 0, False: 2.60k]
  ------------------
  290|  2.60k|	apdu.lc = aidlen;
  291|  2.60k|	apdu.data = aid;
  292|  2.60k|	apdu.datalen = aidlen;
  293|  2.60k|	apdu.resp = response;
  294|  2.60k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (294:17): [True: 2.60k, False: 0]
  ------------------
  295|  2.60k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (295:12): [True: 0, False: 2.60k]
  ------------------
  296|       |
  297|  2.60k|	r = sc_transmit_apdu(card, &apdu);
  298|  2.60k|	if (responselen)
  ------------------
  |  Branch (298:6): [True: 2.60k, False: 0]
  ------------------
  299|  2.60k|		*responselen = apdu.resplen;
  300|  2.60k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  2.60k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.60k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.60k|	int _ret = (r); \
  |  |  |  |  168|  2.60k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 236, False: 2.37k]
  |  |  |  |  ------------------
  |  |  |  |  169|    236|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    236|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    236|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    236|		return _ret; \
  |  |  |  |  172|    236|	} \
  |  |  |  |  173|  2.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|  2.37k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|  2.33k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.33k, False: 41]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  302|  2.37k|}
card-gids.c:gids_init:
  631|     41|{
  632|     41|	unsigned long flags;
  633|     41|	struct gids_private_data *data;
  634|     41|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     41|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     41|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     41|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 41]
  |  |  ------------------
  ------------------
  635|       |
  636|       |	// cache some data in memory
  637|     41|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  638|     41|	if (!data) {
  ------------------
  |  Branch (638:6): [True: 0, False: 41]
  ------------------
  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|     41|	memset(data, 0, sizeof(struct gids_private_data));
  642|     41|	card->drv_data = data;
  643|       |	// invalidate the master file and cmap file cache
  644|     41|	data->cmapfilesize = sizeof(data->cmapfile);
  645|     41|	data->masterfilesize = sizeof(data->masterfile);
  646|       |
  647|       |	/* supported RSA keys and how padding is done */
  648|     41|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|     41|#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|     41|#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|     41|#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|     41|#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|     41|#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|     41|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  652|     41|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  653|     41|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  654|     41|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  655|       |
  656|     41|	return SC_SUCCESS;
  ------------------
  |  |   28|     41|#define SC_SUCCESS				0
  ------------------
  657|     41|}
card-gids.c:gids_finish:
  661|     41|{
  662|     41|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     41|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     41|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     41|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 41]
  |  |  ------------------
  ------------------
  663|       |	/* free the private data */
  664|     41|	if (card->drv_data) {
  ------------------
  |  Branch (664:6): [True: 41, False: 0]
  ------------------
  665|     41|		free(card->drv_data);
  666|       |		card->drv_data = NULL;
  667|     41|	}
  668|     41|	return 0;
  669|     41|}
card-gids.c:gids_read_binary:
 1032|      9|		unsigned char *buf, size_t count, unsigned long *flags) {
 1033|      9|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
 1034|      9|	struct sc_context *ctx = card->ctx;
 1035|      9|	int r;
 1036|      9|	int size;
 1037|       |
 1038|      9|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      9|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      9|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1039|       |
 1040|      9|	if (! data->currentDO || ! data->currentEFID) {
  ------------------
  |  Branch (1040:6): [True: 9, False: 0]
  |  Branch (1040:27): [True: 0, False: 0]
  ------------------
 1041|      9|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1042|      9|	}
 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);
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70: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|     43|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|     43|	sc_apdu_t apdu;
  212|     43|	int r;
  213|     43|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|     43|	size_t datasize = 0;
  215|     43|	const u8* p;
  216|     43|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|     43|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|     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]
  |  |  ------------------
  ------------------
  220|     43|	sc_log(card->ctx, "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 43, False: 0]
  |  |  ------------------
  ------------------
  221|     43|			fileIdentifier, dataObjectIdentifier, response, responselen ? *responselen : 0);
  222|       |
  223|     43|	sc_format_apdu(card, &apdu,
  224|     43|		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|     43|#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|     43|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (224:3): [True: 0, False: 43]
  ------------------
  225|     43|	apdu.lc = 04;
  226|     43|	apdu.data = data;
  227|     43|	apdu.datalen = 04;
  228|     43|	apdu.resp = buffer;
  229|     43|	apdu.resplen = buffer_len;
  230|     43|	apdu.le = 256;
  231|       |
  232|     43|	r = sc_transmit_apdu(card, &apdu);
  233|     43|	LOG_TEST_RET(card->ctx, r, "gids get data failed");
  ------------------
  |  |  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: 8, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  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|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     35|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  174|     35|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     35|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     35|	int _ret = (r); \
  |  |  |  |  168|     35|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|     29|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     29|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     29|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     29|		return _ret; \
  |  |  |  |  172|     29|	} \
  |  |  |  |  173|     35|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|      6|	buffer_len = apdu.resplen;
  236|       |
  237|      6|	p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize);
  238|      6|	if (!p) {
  ------------------
  |  Branch (238:6): [True: 6, False: 0]
  ------------------
  239|      6|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|      6|	}
  241|      0|	if (response && responselen) {
  ------------------
  |  Branch (241:6): [True: 0, False: 0]
  |  Branch (241:18): [True: 0, False: 0]
  ------------------
  242|      0|		if (datasize > *responselen) {
  ------------------
  |  Branch (242:7): [True: 0, False: 0]
  ------------------
  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|      0|		memcpy(response, p, datasize);
  246|      0|		*responselen = datasize;
  247|      0|	}
  248|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  249|      0|}
card-gids.c:gids_select_file:
  964|    198|			   struct sc_file **file_out) {
  965|    198|	struct sc_file *file = NULL;
  966|    198|	struct sc_context *ctx = card->ctx;
  967|    198|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  968|       |
  969|    198|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|       |
  971|    198|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    198|#define GIDS_STATE_NONE 0
  ------------------
  972|    198|	data->currentDO = 0;
  973|    198|	data->currentEFID = 0;
  974|    198|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (974:6): [True: 106, False: 92]
  |  Branch (974:27): [True: 0, False: 106]
  ------------------
  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|    198|	} 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: 106, False: 92]
  |  Branch (991:34): [True: 106, False: 0]
  |  Branch (991:63): [True: 0, False: 106]
  |  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|    198|	} else {
 1002|    198|		return iso_ops->select_file(card, in_path, file_out);
 1003|    198|	}
 1004|    198|}
card-gids.c:gids_card_ctl:
 2089|     43|{
 2090|     43|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     43|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2091|     43|	switch (cmd) {
 2092|      3|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2092:3): [True: 3, False: 40]
  ------------------
 2093|      3|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2094|     40|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2094:3): [True: 40, False: 3]
  ------------------
 2095|     40|			return gids_get_all_containers(card, (size_t*) ptr);
 2096|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2096:3): [True: 0, False: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 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: 43]
  ------------------
 2116|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2117|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2117:3): [True: 0, False: 43]
  ------------------
 2118|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2119|      0|		default:
  ------------------
  |  Branch (2119:3): [True: 0, False: 43]
  ------------------
 2120|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2121|     43|	}
 2122|     43|}
card-gids.c:gids_get_serialnr:
  602|      3|{
  603|      3|	int r;
  604|      3|	u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  605|      3|	size_t buffersize;
  606|       |
  607|      3|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  608|       |
  609|      3|	buffersize = sizeof(buffer);
  610|      3|	r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
  611|      3|	LOG_TEST_RET(card->ctx, r, "unable to read cardid");
  ------------------
  |  |  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: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      3|} 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|      3|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  386|      3|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  387|      3|	int r;
  388|      3|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  389|      3|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (389:6): [True: 3, False: 0]
  ------------------
  390|      3|		r = gids_read_masterfile(card);
  391|      3|		LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
  ------------------
  |  |  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: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|      3|	}
  393|      0|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  394|      0|		directory, filename, response, responselen);
  395|      0|	LOG_TEST_RET(card->ctx, r, "unable to read the 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     43|static int gids_read_masterfile(sc_card_t* card) {
  341|     43|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  342|     43|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     43|#define SC_SUCCESS				0
  ------------------
  343|       |
  344|     43|	data->masterfilesize = sizeof(data->masterfile);
  345|     43|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|     43|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|     43|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|     43|#define MF_DO 0xDF1F
  ------------------
  346|     43|	if (r<0) {
  ------------------
  |  Branch (346:6): [True: 43, False: 0]
  ------------------
  347|     43|		data->masterfilesize = sizeof(data->masterfile);
  348|     43|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     43|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     43|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     43|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     43|	return _ret; \
  |  |  |  |  163|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|     43|	}
  350|      0|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (350:6): [True: 0, False: 0]
  |  Branch (350:34): [True: 0, False: 0]
  ------------------
  351|      0|		data->masterfilesize = sizeof(data->masterfile);
  352|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      0|	}
  354|      0|	return r;
  355|      0|}
card-gids.c:gids_get_all_containers:
 1074|     40|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1075|     40|	int r;
 1076|     40|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1077|     40|	r = gids_read_masterfile(card);
 1078|     40|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|      0|	r = gids_read_cmapfile(card);
 1080|      0|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1081|      0|	*recordsnum = (privatedata ->cmapfilesize / sizeof(CONTAINER_MAP_RECORD));
 1082|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1083|      0|}
card-gids.c:gids_pin_cmd:
 1022|      3|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1023|      3|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      3|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1023:6): [True: 3, False: 0]
  ------------------
 1024|      3|		return gids_get_pin_policy(card, data);
 1025|      3|	} else {
 1026|      0|		return iso_ops->pin_cmd(card, data);
 1027|      0|	}
 1028|      3|}
card-gids.c:gids_get_pin_policy:
 1006|      3|static int gids_get_pin_policy(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1007|      3|	int r;
 1008|      3|	if (data->pin_type != SC_AC_CHV) {
  ------------------
  |  |  151|      3|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1008:6): [True: 0, False: 3]
  ------------------
 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|      3|	r = gids_get_pin_status(card, data->pin_reference, &(data->pin1.tries_left), &(data->pin1.max_tries));
 1012|      3|	LOG_TEST_RET(card->ctx, r, "gids_get_pin_status 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: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      3|} 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|      3|}
card-gids.c:gids_get_pin_status:
  516|      3|static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_left, int *max_tries) {
  517|      3|	int dataObjectIdentifier, r;
  518|      3|	u8 buffer[100];
  519|      3|	const u8* p;
  520|      3|	size_t buffersize = sizeof(buffer);
  521|      3|	size_t datasize;
  522|       |
  523|      3|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  524|      3|	if (tries_left) *tries_left = -1;
  ------------------
  |  Branch (524:6): [True: 3, False: 0]
  ------------------
  525|      3|	if (max_tries) *max_tries = -1;
  ------------------
  |  Branch (525:6): [True: 3, False: 0]
  ------------------
  526|      3|	switch(pinreference) {
  527|      0|	case GIDS_PIN_IDENTIFIER:
  ------------------
  |  |  100|      0|#define GIDS_PIN_IDENTIFIER 0x80
  ------------------
  |  Branch (527:2): [True: 0, False: 3]
  ------------------
  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: 3]
  ------------------
  531|      0|		dataObjectIdentifier = GIDS_PUK_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   81|      0|#define GIDS_PUK_STATUS_OBJECT_IDENTIFIER 0x7F73
  ------------------
  532|      0|		break;
  533|      3|	default:
  ------------------
  |  Branch (533:2): [True: 3, False: 0]
  ------------------
  534|      3|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|      3|	}
  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|  2.65k|{
 2126|  2.65k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.65k|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|  2.65k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.65k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.65k]
  |  |  ------------------
  ------------------
 2129|       |
 2130|  2.65k|	if (was_reset > 0) {
  ------------------
  |  Branch (2130:6): [True: 0, False: 2.65k]
  ------------------
 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|  2.65k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.65k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.65k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.65k|	int _ret = r; \
  |  |  |  |  155|  2.65k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.65k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.65k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.65k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.65k|	} else { \
  |  |  |  |  159|      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.65k|	return _ret; \
  |  |  |  |  163|  2.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2137|  2.65k|}

sc_invalidate_cache:
  164|    405|{
  165|    405|	if (card) {
  ------------------
  |  Branch (165:6): [True: 405, False: 0]
  ------------------
  166|    405|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|    405|		sc_file_free(prv->cache.current_ef);
  168|    405|		sc_file_free(prv->cache.current_df);
  169|    405|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|    405|		prv->cache.valid = 0;
  171|    405|	}
  172|    405|}
sc_get_iasecc_driver:
 3638|  8.50k|{
 3639|  8.50k|	return sc_get_driver();
 3640|  8.50k|}
card-iasecc.c:iasecc_is_cpx:
  586|    561|{
  587|    561|	switch(card->type) {
  588|      8|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (588:3): [True: 8, False: 553]
  ------------------
  589|    164|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (589:3): [True: 156, False: 405]
  ------------------
  590|    164|			return 1;
  591|    397|		default:
  ------------------
  |  Branch (591:3): [True: 397, False: 164]
  ------------------
  592|    397|			return 0;
  593|    561|	}
  594|       |
  595|      0|	return 0;
  596|    561|}
card-iasecc.c:iasecc_select_mf:
  283|    325|{
  284|    325|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|    325|	struct sc_context *ctx = card->ctx;
  286|    325|	struct sc_file *mf_file = NULL;
  287|    325|	struct sc_path path;
  288|    325|	int rv;
  289|       |
  290|    325|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    325|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    325|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    325|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    325|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 325]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|    325|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 173, False: 152]
  ------------------
  293|    173|		*file_out = NULL;
  294|       |
  295|    325|	memset(&path, 0, sizeof(struct sc_path));
  296|    325|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 152, False: 173]
  |  Branch (296:23): [True: 0, False: 173]
  ------------------
  297|    152|		struct sc_apdu apdu;
  298|    152|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|    152|		sc_format_path("3F00", &path);
  302|    152|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    152|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|    152|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    152|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|    152|		apdu.lc = path.len;
  306|    152|		apdu.data = path.value;
  307|    152|		apdu.datalen = path.len;
  308|    152|		apdu.resplen = sizeof(apdu_resp);
  309|    152|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|    152|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 0, False: 152]
  ------------------
  313|      0|			apdu.p2 = 0x04;
  314|       |
  315|    152|		rv = sc_transmit_apdu(card, &apdu);
  316|    152|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    152|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    152|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    152|	int _ret = (r); \
  |  |  |  |  168|    152|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 151]
  |  |  |  |  ------------------
  |  |  |  |  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|    152|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 151]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|    151|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|    151|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|    151|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    151|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    151|	int _ret = (r); \
  |  |  |  |  168|    151|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  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|    151|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|    151|	}
  320|    173|	else   {
  321|    173|		memset(&path, 0, sizeof(path));
  322|    173|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    173|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  323|    173|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  324|    173|		path.len = card->ef_atr->aid.len;
  325|    173|		rv = iasecc_select_file(card, &path, file_out);
  326|    173|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|    173|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    173|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    173|	int _ret = (r); \
  |  |  |  |  168|    173|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 142, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  169|    142|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    142|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    142|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    142|		return _ret; \
  |  |  |  |  172|    142|	} \
  |  |  |  |  173|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|    173|	}
  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|    160|	mf_file = sc_file_new();
  334|    160|	if (mf_file == NULL)
  ------------------
  |  Branch (334:6): [True: 0, False: 160]
  ------------------
  335|    160|		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|    160|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    160|#define SC_FILE_TYPE_DF			0x04
  ------------------
  337|    160|	mf_file->path = path;
  338|       |
  339|    160|	sc_invalidate_cache(card);
  340|    160|	sc_file_dup(&prv->cache.current_df, mf_file);
  341|    160|	prv->cache.valid = 1;
  342|       |
  343|    160|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (343:6): [True: 136, False: 24]
  |  Branch (343:18): [True: 133, False: 3]
  ------------------
  344|    133|		*file_out = mf_file;
  345|     27|	else
  346|     27|		sc_file_free(mf_file);
  347|       |
  348|    160|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    160|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    160|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    160|	int _ret = r; \
  |  |  |  |  155|    160|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 160, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    160|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 160]
  |  |  |  |  ------------------
  |  |  |  |  157|    160|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    160|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    160|	return _ret; \
  |  |  |  |  163|    160|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|    160|}
card-iasecc.c:iasecc_select_file:
  863|    438|{
  864|    438|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  865|    438|	struct sc_context *ctx = card->ctx;
  866|    438|	struct sc_path lpath;
  867|    438|	int rv, ii;
  868|       |
  869|    438|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    438|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    438|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    438|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    438|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 438]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  870|    438|	memcpy(&lpath, path, sizeof(struct sc_path));
  871|    438|	if (file_out)
  ------------------
  |  Branch (871:6): [True: 263, False: 175]
  ------------------
  872|    263|		*file_out = NULL;
  873|       |
  874|    438|	sc_log(ctx, "iasecc_select_file(card:%p) path.len %zu; path.type %i; aid_len %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  875|    438|			card, path->len, path->type, path->aid.len);
  876|    438|	sc_log(ctx, "iasecc_select_file() path:%s", sc_print_path(path));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  877|       |
  878|    438|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (878:6): [True: 397, False: 41]
  ------------------
  879|    397|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (879:6): [True: 346, False: 51]
  ------------------
  880|    346|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|    692|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (880:7): [True: 173, False: 173]
  ------------------
  881|    173|			&& lpath.len >= 2
  ------------------
  |  Branch (881:7): [True: 173, False: 0]
  ------------------
  882|    173|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (882:7): [True: 173, False: 0]
  |  Branch (882:33): [True: 173, False: 0]
  ------------------
  883|    173|		sc_log(ctx, "EF.ATR(aid:'%s')", card->ef_atr ? sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len) : "");
  ------------------
  |  |   71|    346|#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: 23, False: 150]
  |  |  ------------------
  ------------------
  884|       |
  885|    173|		rv = iasecc_select_mf(card, file_out);
  886|    173|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    173|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    173|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    173|	int _ret = (r); \
  |  |  |  |  168|    173|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 37, False: 136]
  |  |  |  |  ------------------
  |  |  |  |  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|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 136]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  887|       |
  888|    136|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  889|    136|		lpath.len -=  2;
  890|    136|	}
  891|       |
  892|    401|	if (lpath.aid.len)	{
  ------------------
  |  Branch (892:6): [True: 0, False: 401]
  ------------------
  893|      0|		struct sc_file *file = NULL;
  894|      0|		struct sc_path ppath;
  895|       |
  896|      0|		sc_log(ctx, "iasecc_select_file() select parent AID:%p/%zu", lpath.aid.value, lpath.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__
  |  |  ------------------
  ------------------
  897|      0|		sc_log(ctx, "iasecc_select_file() select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.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__
  |  |  ------------------
  ------------------
  898|      0|		memset(&ppath, 0, sizeof(ppath));
  899|      0|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  900|      0|		ppath.len = lpath.aid.len;
  901|      0|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  902|       |
  903|      0|		rv = iasecc_select_file(card, &ppath, &file);
  904|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  905|       |
  906|      0|		if (file_out) {
  ------------------
  |  Branch (906:7): [True: 0, False: 0]
  ------------------
  907|      0|			sc_file_free(*file_out);
  908|      0|			*file_out = file;
  909|      0|		} else {
  910|      0|			sc_file_free(file);
  911|      0|		}
  912|       |
  913|      0|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (913:7): [True: 0, False: 0]
  ------------------
  914|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  915|      0|	}
  916|       |
  917|    401|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|    401|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (917:6): [True: 228, False: 173]
  ------------------
  918|    228|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    228|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  919|       |
  920|    401|	if (!lpath.len) {
  ------------------
  |  Branch (920:6): [True: 0, False: 401]
  ------------------
  921|      0|		if (file_out) {
  ------------------
  |  Branch (921:7): [True: 0, False: 0]
  ------------------
  922|      0|			sc_file_free(*file_out);
  923|      0|			*file_out = NULL;
  924|      0|		}
  925|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|      0|	}
  927|       |
  928|    401|	do   {
  929|    401|		struct sc_apdu apdu;
  930|    401|		struct sc_file *file = NULL;
  931|    401|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  932|    401|		size_t pathlen = lpath.len;
  933|       |
  934|    401|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|    401|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  935|       |
  936|    401|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (936:7): [True: 350, False: 51]
  ------------------
  937|    350|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (937:8): [True: 41, False: 309]
  ------------------
  938|     41|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (938:8): [True: 41, False: 0]
  ------------------
  939|     41|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (939:8): [True: 41, False: 0]
  ------------------
  940|     41|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (940:8): [True: 41, False: 0]
  ------------------
  941|     41|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (941:8): [True: 41, False: 0]
  ------------------
  942|     41|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (942:8): [True: 0, False: 41]
  ------------------
  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|    401|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|    401|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (947:7): [True: 0, False: 401]
  ------------------
  948|      0|			apdu.p1 = 0x02;
  949|      0|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (949:8): [True: 0, False: 0]
  ------------------
  950|      0|				apdu.p1 = 0x01;
  951|      0|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (951:8): [True: 0, False: 0]
  ------------------
  952|      0|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (952:8): [True: 0, False: 0]
  ------------------
  953|      0|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (953:8): [True: 0, False: 0]
  ------------------
  954|      0|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (954:8): [True: 0, False: 0]
  ------------------
  955|      0|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (955:8): [True: 0, False: 0]
  ------------------
  956|      0|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (956:8): [True: 0, False: 0]
  ------------------
  957|      0|			    )   {
  958|      0|				apdu.p2 = 0x04;
  959|      0|			}
  960|      0|		}
  961|    401|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    401|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (961:12): [True: 228, False: 173]
  ------------------
  962|    228|			apdu.p1 = 0x09;
  963|    228|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (963:8): [True: 136, False: 92]
  ------------------
  964|     92|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (964:8): [True: 0, False: 92]
  ------------------
  965|     92|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (965:8): [True: 0, False: 92]
  ------------------
  966|     92|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (966:8): [True: 0, False: 92]
  ------------------
  967|     92|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (967:8): [True: 51, False: 41]
  ------------------
  968|    228|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (968:8): [True: 41, False: 0]
  ------------------
  969|    228|				apdu.p2 = 0x04;
  970|    228|			}
  971|    228|		}
  972|    173|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|    173|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (972:12): [True: 0, False: 173]
  ------------------
  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|    173|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    173|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (977:12): [True: 173, False: 0]
  ------------------
  978|    173|			apdu.p1 = 0x04;
  979|    173|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (979:8): [True: 0, False: 173]
  ------------------
  980|    173|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (980:8): [True: 0, False: 173]
  ------------------
  981|    173|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (981:8): [True: 173, False: 0]
  ------------------
  982|      0|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (982:8): [True: 0, False: 0]
  ------------------
  983|    173|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (983:8): [True: 0, False: 0]
  ------------------
  984|    173|				apdu.p2 = 0x04;
  985|    173|			}
  986|    173|		}
  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|    401|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (993:14): [True: 401, False: 0]
  ------------------
  994|    401|			apdu.lc = pathlen;
  995|    401|			apdu.data = lpath.value;
  996|    401|			apdu.datalen = pathlen;
  997|       |
  998|    401|			apdu.resp = rbuf;
  999|    401|			apdu.resplen = sizeof(rbuf);
 1000|    401|			apdu.le = 256;
 1001|       |
 1002|    401|			rv = sc_transmit_apdu(card, &apdu);
 1003|    401|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|    401|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    401|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    401|	int _ret = (r); \
  |  |  |  |  178|    401|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 396]
  |  |  |  |  ------------------
  |  |  |  |  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|    401|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 396]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1004|    396|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|    396|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|    792|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1005:8): [True: 4, False: 392]
  ------------------
 1006|      4|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|    400|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1006:6): [True: 1, False: 3]
  |  Branch (1006:44): [True: 0, False: 1]
  ------------------
 1007|      0|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1008|      0|				apdu.p2 = 0x0C;
 1009|      0|				continue;
 1010|      0|			}
 1011|       |
 1012|    396|			if (ii)   {
  ------------------
  |  Branch (1012:8): [True: 0, False: 396]
  ------------------
 1013|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1014|      0|				apdu.resplen = sizeof(rbuf);
 1015|      0|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1016|      0|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1017|      0|			}
 1018|       |
 1019|    396|			break;
 1020|    396|		}
 1021|       |
 1022|    396|		LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() check SW failed");
  ------------------
  |  |  184|    396|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    396|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    396|	int _ret = (r); \
  |  |  |  |  178|    396|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 189, False: 207]
  |  |  |  |  ------------------
  |  |  |  |  179|    189|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    189|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    189|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    189|		goto err; \
  |  |  |  |  182|    189|	} \
  |  |  |  |  183|    396|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1023|       |
 1024|    207|		sc_log(ctx, "iasecc_select_file() apdu.resp %zu", apdu.resplen);
  ------------------
  |  |   71|    207|#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|    207|		if (apdu.resplen)   {
  ------------------
  |  Branch (1025:7): [True: 108, False: 99]
  ------------------
 1026|    108|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   71|    108|#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|    108|			switch (apdu.resp[0]) {
 1029|      5|			case 0x62:
  ------------------
  |  Branch (1029:4): [True: 5, False: 103]
  ------------------
 1030|     91|			case 0x6F:
  ------------------
  |  Branch (1030:4): [True: 86, False: 22]
  ------------------
 1031|     91|				file = sc_file_new();
 1032|     91|				if (file == NULL) {
  ------------------
  |  Branch (1032:9): [True: 0, False: 91]
  ------------------
 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|     91|				file->path = lpath;
 1040|       |
 1041|     91|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1042|     91|				if (rv) {
  ------------------
  |  Branch (1042:9): [True: 30, False: 61]
  ------------------
 1043|     30|					sc_file_free(file);
 1044|     30|					if (file_out) {
  ------------------
  |  Branch (1044:10): [True: 23, False: 7]
  ------------------
 1045|     23|						sc_file_free(*file_out);
 1046|     23|						*file_out = NULL;
 1047|     23|					}
 1048|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|     30|				}
 1050|     61|				break;
 1051|     61|			default:
  ------------------
  |  Branch (1051:4): [True: 17, False: 91]
  ------------------
 1052|     17|				if (file_out) {
  ------------------
  |  Branch (1052:9): [True: 10, False: 7]
  ------------------
 1053|     10|					sc_file_free(*file_out);
 1054|     10|					*file_out = NULL;
 1055|     10|				}
 1056|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|    108|			}
 1058|       |
 1059|     61|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1060|     61|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     61|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1060:8): [True: 10, False: 51]
  ------------------
 1061|     10|				sc_invalidate_cache(card);
 1062|     10|				sc_file_dup(&prv->cache.current_df, file);
 1063|     10|				prv->cache.valid = 1;
 1064|     10|			}
 1065|     51|			else   {
 1066|     51|				sc_file_free(prv->cache.current_ef);
 1067|     51|				sc_file_dup(&prv->cache.current_ef, file);
 1068|     51|				prv->cache.valid = 1;
 1069|     51|			}
 1070|       |
 1071|     61|			if (file_out)   {
  ------------------
  |  Branch (1071:8): [True: 52, False: 9]
  ------------------
 1072|     52|				sc_file_free(*file_out);
 1073|     52|				*file_out = file;
 1074|     52|			}
 1075|      9|			else   {
 1076|      9|				sc_file_free(file);
 1077|      9|			}
 1078|     61|		}
 1079|     99|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|     99|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1079:12): [True: 19, False: 80]
  ------------------
 1080|     19|			sc_invalidate_cache(card);
 1081|     19|			prv->cache.valid = 1;
 1082|     19|		}
 1083|    207|	} while(0);
  ------------------
  |  Branch (1083:10): [Folded, False: 160]
  ------------------
 1084|       |
 1085|    160|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    160|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    160|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    160|	int _ret = r; \
  |  |  |  |  155|    160|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 160, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    160|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 160]
  |  |  |  |  ------------------
  |  |  |  |  157|    160|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    160|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    160|	return _ret; \
  |  |  |  |  163|    160|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1086|    194|err:
 1087|    194|	if (file_out) {
  ------------------
  |  Branch (1087:6): [True: 58, False: 136]
  ------------------
 1088|     58|		sc_file_free(*file_out);
 1089|       |		*file_out = NULL;
 1090|     58|	}
 1091|    194|	return rv;
 1092|    160|}
card-iasecc.c:iasecc_process_fci:
 1098|     91|{
 1099|     91|	struct sc_context *ctx = card->ctx;
 1100|     91|	size_t taglen, offs, ii;
 1101|     91|	int rv;
 1102|     91|	const unsigned char *acls = NULL, *tag = NULL;
 1103|     91|	unsigned char mask;
 1104|     91|	unsigned char ops_DF[7] = {
 1105|     91|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|     91|#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|     91|#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|     91|#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|     91|#define SC_AC_OP_CREATE			3
  ------------------
 1106|     91|	};
 1107|     91|	unsigned char ops_EF[7] = {
 1108|     91|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|     91|#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|     91|#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|     91|#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|     91|#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|     91|#define SC_AC_OP_READ			22
  ------------------
 1109|     91|	};
 1110|       |
 1111|     91|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     91|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     91|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     91|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     91|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|       |
 1113|     91|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1114|     91|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1115|     91|	if (tag != NULL) {
  ------------------
  |  Branch (1115:6): [True: 74, False: 17]
  ------------------
 1116|     74|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1117|     74|		buf = tag;
 1118|     74|		buflen = taglen;
 1119|     74|	}
 1120|       |
 1121|     91|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1122|     91|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1123|     91|	if (tag != NULL) {
  ------------------
  |  Branch (1123:6): [True: 1, False: 90]
  ------------------
 1124|      1|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1125|      1|		buf = tag;
 1126|      1|		buflen = taglen;
 1127|      1|	}
 1128|       |
 1129|     91|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1130|     91|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|     91|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     91|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     91|	int _ret = (r); \
  |  |  |  |  168|     91|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  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|     91|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|     91|	sc_log(ctx, "iasecc_process_fci() type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1138|     91|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|     91|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1139|     91|	if (tag)
  ------------------
  |  Branch (1139:6): [True: 1, False: 90]
  ------------------
 1140|      1|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|      1|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1141|     90|	else
 1142|     90|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|     90|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1143|       |
 1144|     91|	if (!acls)   {
  ------------------
  |  Branch (1144:6): [True: 30, False: 61]
  ------------------
 1145|     30|		sc_log(ctx, "ACLs not found in data(%zu) %s", buflen, sc_dump_hex(buf, buflen));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1146|     30|		LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  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: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|     30|	}
 1148|       |
 1149|     61|	sc_log(ctx, "ACLs(%zu) '%s'", taglen, sc_dump_hex(acls, taglen));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1150|     61|	mask = 0x40, offs = 1;
 1151|    426|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1151:15): [True: 379, False: 47]
  ------------------
 1152|    379|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    379|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1152:22): [True: 46, False: 333]
  ------------------
 1153|       |
 1154|       |		/* avoid any access to acls[offs] beyond the taglen */
 1155|    379|		if (offs >= taglen) {
  ------------------
  |  Branch (1155:7): [True: 14, False: 365]
  ------------------
 1156|     14|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1157|     14|			break;
 1158|     14|		}
 1159|    365|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1159:7): [True: 180, False: 185]
  ------------------
 1160|    180|			continue;
 1161|       |
 1162|    185|		sc_log(ctx, "ACLs mask 0x%X, offs %zu, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|    185|#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|    185|		if (op == 0xFF)   {
  ------------------
  |  Branch (1163:7): [True: 48, False: 137]
  ------------------
 1164|     48|			;
 1165|     48|		}
 1166|    137|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1166:12): [True: 33, False: 104]
  ------------------
 1167|     33|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     33|#define SC_AC_NONE			0x00000000
  ------------------
 1168|     33|		}
 1169|    104|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1169:12): [True: 16, False: 88]
  ------------------
 1170|     16|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     16|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1171|     16|		}
 1172|     88|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|     88|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|     88|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1172:12): [True: 15, False: 73]
  ------------------
 1173|     15|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|     15|#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|     15|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1174|     15|		}
 1175|     73|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|     73|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1175:12): [True: 53, False: 20]
  ------------------
 1176|     53|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|     53|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1177|     53|		}
 1178|     20|		else   {
 1179|     20|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1180|     20|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     20|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1181|     20|		}
 1182|       |
 1183|    185|		offs++;
 1184|    185|	}
 1185|       |
 1186|     61|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1187|     61|}
card-iasecc.c:sc_get_driver:
 3591|  8.50k|{
 3592|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3593|       |
 3594|  8.50k|	if (!iso_ops)
  ------------------
  |  Branch (3594:6): [True: 1, False: 8.49k]
  ------------------
 3595|      1|		iso_ops = iso_drv->ops;
 3596|       |
 3597|  8.50k|	iasecc_ops = *iso_ops;
 3598|       |
 3599|  8.50k|	iasecc_ops.match_card = iasecc_match_card;
 3600|  8.50k|	iasecc_ops.init = iasecc_init;
 3601|  8.50k|	iasecc_ops.finish = iasecc_finish;
 3602|  8.50k|	iasecc_ops.read_binary = iasecc_read_binary;
 3603|       |	/*	write_binary: ISO7816 implementation works	*/
 3604|       |	/*	update_binary: ISO7816 implementation works	*/
 3605|  8.50k|	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|  8.50k|	iasecc_ops.select_file = iasecc_select_file;
 3612|       |	/*	get_response: Untested	*/
 3613|  8.50k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3614|  8.50k|	iasecc_ops.logout = iasecc_logout;
 3615|       |	/*	restore_security_env	*/
 3616|  8.50k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3617|  8.50k|	iasecc_ops.decipher = iasecc_decipher;
 3618|  8.50k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3619|  8.50k|	iasecc_ops.create_file = iasecc_create_file;
 3620|  8.50k|	iasecc_ops.delete_file = iasecc_delete_file;
 3621|       |	/*	list_files	*/
 3622|  8.50k|	iasecc_ops.check_sw = iasecc_check_sw;
 3623|  8.50k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3624|  8.50k|	iasecc_ops.process_fci = iasecc_process_fci;
 3625|       |	/*	construct_fci: Not needed	*/
 3626|  8.50k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3627|       |	/*	get_data: Not implemented	*/
 3628|       |	/*	put_data: Not implemented	*/
 3629|       |	/*	delete_record: Not implemented	*/
 3630|       |
 3631|  8.50k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3632|       |
 3633|  8.50k|	return &iasecc_drv;
 3634|  8.50k|}
card-iasecc.c:iasecc_match_card:
  353|  7.21k|{
  354|  7.21k|	struct sc_context *ctx = card->ctx;
  355|  7.21k|	int i;
  356|       |
  357|  7.21k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  358|  7.21k|	if (i < 0)   {
  ------------------
  |  Branch (358:6): [True: 7.00k, False: 216]
  ------------------
  359|  7.00k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  360|  7.00k|		return 0;
  361|  7.00k|	}
  362|       |
  363|    216|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|    216|#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|    216|	return 1;
  365|  7.21k|}
card-iasecc.c:iasecc_init:
  624|    216|{
  625|    216|	struct sc_context *ctx = card->ctx;
  626|    216|	struct iasecc_private_data *private_data = NULL;
  627|    216|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    216|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  628|    216|	void *old_drv_data = card->drv_data;
  629|       |
  630|    216|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    216|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|    216|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  632|    216|	if (private_data == NULL)
  ------------------
  |  Branch (632:6): [True: 0, False: 216]
  ------------------
  633|    216|		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|    216|	card->cla  = 0x00;
  636|    216|	card->drv_data = private_data;
  637|       |
  638|    216|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (638:6): [True: 25, False: 191]
  ------------------
  639|     25|		rv = iasecc_init_gemalto(card);
  640|    191|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (640:11): [True: 150, False: 41]
  ------------------
  641|    150|		rv = iasecc_init_oberthur(card);
  642|     41|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (642:11): [True: 0, False: 41]
  ------------------
  643|      0|		rv = iasecc_init_amos_or_sagem(card);
  644|     41|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (644:11): [True: 0, False: 41]
  ------------------
  645|      0|		rv = iasecc_init_amos_or_sagem(card);
  646|     41|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (646:11): [True: 0, False: 41]
  ------------------
  647|      0|		rv = iasecc_init_amos_or_sagem(card);
  648|     41|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (648:11): [True: 41, False: 0]
  ------------------
  649|     41|		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|    216|	if (!rv)   {
  ------------------
  |  Branch (655:6): [True: 0, False: 216]
  ------------------
  656|      0|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (656:7): [True: 0, False: 0]
  |  Branch (656:23): [True: 0, False: 0]
  ------------------
  657|      0|			struct sc_path path;
  658|       |
  659|      0|			memset(&path, 0, sizeof(struct sc_path));
  660|      0|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  661|      0|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  662|      0|			path.len = card->ef_atr->aid.len;
  663|       |
  664|      0|			rv = iasecc_select_file(card, &path, NULL);
  665|      0|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", 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__
  |  |  ------------------
  ------------------
  666|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|      0|		}
  668|       |
  669|      0|		iasecc_get_serialnr(card, NULL);
  670|      0|	}
  671|       |
  672|    216|#ifdef ENABLE_SM
  673|    216|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  674|    216|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  675|    216|#endif
  676|       |
  677|    216|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (677:6): [True: 0, False: 216]
  |  Branch (677:13): [True: 0, False: 0]
  |  Branch (677:29): [True: 0, False: 0]
  ------------------
  678|      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__
  |  |  ------------------
  ------------------
  679|      0|	}
  680|       |
  681|    216|err:
  682|    216|	if (rv < 0) {
  ------------------
  |  Branch (682:6): [True: 216, False: 0]
  ------------------
  683|    216|		sc_invalidate_cache(card);
  684|    216|		free(private_data);
  685|    216|		card->drv_data = old_drv_data;
  686|    216|	} else {
  687|      0|		free(old_drv_data);
  688|      0|	}
  689|       |
  690|    216|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    216|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    216|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    216|	int _ret = r; \
  |  |  |  |  155|    216|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 216, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    216|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    216|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 216, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    216|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    216|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    216|	return _ret; \
  |  |  |  |  163|    216|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|    216|}
card-iasecc.c:iasecc_init_gemalto:
  419|     25|{
  420|     25|	struct sc_context *ctx = card->ctx;
  421|     25|	struct sc_path path;
  422|     25|	unsigned int flags;
  423|     25|	int rv = 0;
  424|       |
  425|     25|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     25|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     25|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     25|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     25|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 25]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  426|       |
  427|     25|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     25|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     25|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     25|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     25|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     25|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     25|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     25|#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|     25|#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|     25|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     25|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     25|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     25|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     25|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     25|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     25|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  428|       |
  429|     25|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     25|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     25|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     25|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     25|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     25|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     25|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     25|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     25|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     25|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  430|       |
  431|     25|	sc_format_path("3F00", &path);
  432|     25|	if (SC_SUCCESS != sc_select_file(card, &path, NULL)) {
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (432:6): [True: 23, False: 2]
  ------------------
  433|       |		/* Result ignored*/
  434|     23|		sc_log(card->ctx, "Warning, MF select failed");
  ------------------
  |  |   71|     23|#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|     23|	}
  436|       |
  437|     25|	rv = iasecc_parse_ef_atr(card);
  438|     25|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  439|     25|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     25|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (439:6): [True: 2, False: 23]
  ------------------
  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|     24|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  449|     24|	LOG_TEST_RET(ctx, rv, "Cannot read/parse EF.ATR");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|       |
  451|      0|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  452|      0|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  453|       |
  454|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|      0|}
card-iasecc.c:iasecc_parse_ef_atr:
  369|    240|{
  370|    240|	struct sc_context *ctx = card->ctx;
  371|    240|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  372|    240|	struct iasecc_version *version = &pdata->version;
  373|    240|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  374|    240|	int rv;
  375|       |
  376|    240|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    240|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    240|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    240|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    240|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 240]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    240|	rv = sc_parse_ef_atr(card);
  378|    240|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    240|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    240|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    240|	int _ret = (r); \
  |  |  |  |  168|    240|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 158, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  169|    158|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    158|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    158|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    158|		return _ret; \
  |  |  |  |  172|    158|	} \
  |  |  |  |  173|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|     82|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (380:6): [True: 77, False: 5]
  ------------------
  381|     82|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  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: 77, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     77|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     77|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     77|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     77|		return _ret; \
  |  |  |  |  172|     77|	} \
  |  |  |  |  173|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|      5|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  384|      5|	version->ic_type =		card->ef_atr->pre_issuing[1];
  385|      5|	version->os_version =		card->ef_atr->pre_issuing[2];
  386|      5|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  387|      5|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  388|      5|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  389|       |
  390|      5|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (390:6): [True: 1, False: 4]
  ------------------
  391|      5|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |
  393|      4|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  394|      4|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  395|      4|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  396|      4|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  397|       |
  398|      4|	sc_log(ctx, "EF.ATR: IO Buffer Size send/sc %zd/%zd recv/sc %zd/%zd",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  399|      4|			sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  400|       |
  401|      4|	card->max_send_size = sizes->send;
  402|      4|	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|      4|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (408:6): [True: 2, False: 2]
  ------------------
  409|      2|		card->max_send_size -= 5;
  410|       |
  411|      4|	sc_log(ctx, "EF.ATR: max send/recv sizes %zX/%zX", card->max_send_size, card->max_recv_size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  412|       |
  413|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|      4|}
card-iasecc.c:iasecc_init_oberthur:
  488|    150|{
  489|    150|	struct sc_context *ctx = card->ctx;
  490|    150|	unsigned int flags;
  491|    150|	int rv = 0;
  492|       |
  493|    150|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    150|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    150|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    150|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    150|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|       |
  495|    150|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    150|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    150|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    150|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    150|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    150|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    150|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    150|#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|    150|#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|    150|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    150|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    150|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    150|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    150|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    150|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    150|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  496|       |
  497|    150|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  498|    150|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  499|       |
  500|    150|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    150|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    150|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    150|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    150|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    150|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    150|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    150|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    150|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    150|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  501|       |
  502|    150|	iasecc_parse_ef_atr(card);
  503|       |
  504|       |	/* if we fail to select CM, */
  505|    150|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (505:6): [True: 120, False: 30]
  ------------------
  506|    120|		gp_select_isd_rid(card);
  507|    120|	}
  508|       |
  509|    150|	rv = iasecc_oberthur_match(card);
  510|    150|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|    150|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    150|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    150|	int _ret = (r); \
  |  |  |  |  168|    150|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 150]
  |  |  |  |  ------------------
  |  |  |  |  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|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|       |
  512|    150|	rv = iasecc_select_mf(card, NULL);
  513|    150|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    150|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    150|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    150|	int _ret = (r); \
  |  |  |  |  168|    150|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 127, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  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|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|     23|	rv = iasecc_parse_ef_atr(card);
  516|     23|	LOG_TEST_RET(ctx, rv, "EF.ATR read or parse 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    150|{
  461|    150|	struct sc_context *ctx = card->ctx;
  462|    150|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  463|       |
  464|    150|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    150|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    150|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    150|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    150|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|       |
  466|    150|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (466:6): [True: 0, False: 150]
  |  Branch (466:23): [True: 0, False: 150]
  ------------------
  467|    150|		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|    150|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|    150|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    150|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|       |
  471|    150|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (471:6): [True: 0, False: 150]
  ------------------
  472|    150|		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|    150|	if (!card->ef_atr)
  ------------------
  |  Branch (474:6): [True: 76, False: 74]
  ------------------
  475|     76|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  476|    150|	if (!card->ef_atr)
  ------------------
  |  Branch (476:6): [True: 0, False: 150]
  ------------------
  477|    150|		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|    150|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  480|    150|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  481|       |
  482|    150|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    150|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    150|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    150|	int _ret = r; \
  |  |  |  |  155|    150|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 150, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    150|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 150]
  |  |  |  |  ------------------
  |  |  |  |  157|    150|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    150|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    150|	return _ret; \
  |  |  |  |  163|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  483|    150|}
card-iasecc.c:iasecc_init_cpx:
  600|     41|{
  601|     41|	struct sc_context *ctx = card->ctx;
  602|     41|	unsigned int flags;
  603|     41|	int rv = 0;
  604|       |
  605|     41|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     41|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     41|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     41|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     41|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 41]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  606|       |
  607|     41|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     41|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     41|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     41|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     41|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     41|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     41|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     41|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     41|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     41|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  608|       |
  609|     41|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     41|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     41|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     41|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     41|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     41|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     41|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     41|#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|     41|#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|     41|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     41|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     41|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     41|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     41|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     41|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     41|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  610|       |
  611|     41|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  612|     41|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  613|     41|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  614|       |
  615|     41|	rv = iasecc_parse_ef_atr(card);
  616|     41|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|       |
  618|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|      0|}
card-iasecc.c:iasecc_read_binary:
  697|    960|{
  698|    960|	struct sc_context *ctx = card->ctx;
  699|    960|	struct sc_apdu apdu;
  700|    960|	int rv;
  701|       |
  702|    960|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    960|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    960|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    960|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    960|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 960]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  703|    960|	sc_log(ctx, "iasecc_read_binary(card:%p) offs %i; count %zu", card, offs, count);
  ------------------
  |  |   71|    960|#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|    960|	if (offs > 0x7fff) {
  ------------------
  |  Branch (704:6): [True: 1, False: 959]
  ------------------
  705|      1|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", offs);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  706|      1|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      1|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  707|      1|	}
  708|       |
  709|    959|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|    959|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  710|    959|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (710:12): [True: 78, False: 881]
  ------------------
  711|    959|	apdu.resplen = count;
  712|    959|	apdu.resp = buf;
  713|       |
  714|    959|	rv = sc_transmit_apdu(card, &apdu);
  715|    959|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    959|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    959|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    959|	int _ret = (r); \
  |  |  |  |  168|    959|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 948]
  |  |  |  |  ------------------
  |  |  |  |  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|    959|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 948]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|    948|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  717|    948|	LOG_TEST_RET(ctx, rv, "iasecc_read_binary() failed");
  ------------------
  |  |  174|    948|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    948|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    948|	int _ret = (r); \
  |  |  |  |  168|    948|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 97, False: 851]
  |  |  |  |  ------------------
  |  |  |  |  169|     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
  |  |  |  |  ------------------
  |  |  |  |  170|     97|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     97|		return _ret; \
  |  |  |  |  172|     97|	} \
  |  |  |  |  173|    948|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 851]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  718|    851|	sc_log(ctx, "iasecc_read_binary() apdu.resplen %zu", apdu.resplen);
  ------------------
  |  |   71|    851|#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|    851|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  1.70k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (720:6): [True: 3, False: 848]
  |  Branch (720:55): [True: 3, False: 0]
  ------------------
  721|      3|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  722|      3|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|      3|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (722:7): [True: 2, False: 1]
  ------------------
  723|      2|			LOG_TEST_RET(ctx, rv, "iasecc_read_binary() read tail 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|      1|			apdu.resplen += rv;
  725|      1|		}
  726|      3|	}
  727|       |
  728|    850|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    850|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    850|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    850|	int _ret = r; \
  |  |  |  |  155|    850|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 841]
  |  |  |  |  ------------------
  |  |  |  |  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|    841|	} else { \
  |  |  |  |  159|    841|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    841|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    841|	} \
  |  |  |  |  162|    850|	return _ret; \
  |  |  |  |  163|    850|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|    850|}
card-iasecc.c:iasecc_check_sw:
 1487|  2.50k|{
 1488|  2.50k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1488:6): [True: 37, False: 2.46k]
  |  Branch (1488:21): [True: 22, False: 15]
  ------------------
 1489|     22|		return SC_SUCCESS;
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
 1490|       |
 1491|  2.48k|	return iso_ops->check_sw(card, sw1, sw2);
 1492|  2.50k|}

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

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

sc_get_itacns_driver:
  523|  8.50k|{
  524|  8.50k|	return sc_get_driver();
  525|  8.50k|}
card-itacns.c:sc_get_driver:
  504|  8.50k|{
  505|  8.50k|	if (!default_ops)
  ------------------
  |  Branch (505:6): [True: 1, False: 8.49k]
  ------------------
  506|      1|		default_ops = sc_get_iso7816_driver()->ops;
  507|  8.50k|	itacns_ops = *default_ops;
  508|  8.50k|	itacns_ops.match_card = itacns_match_card;
  509|  8.50k|	itacns_ops.init = itacns_init;
  510|  8.50k|	itacns_ops.finish = itacns_finish;
  511|  8.50k|	itacns_ops.set_security_env = itacns_set_security_env;
  512|  8.50k|	itacns_ops.restore_security_env = itacns_restore_security_env;
  513|  8.50k|	itacns_ops.pin_cmd = itacns_pin_cmd;
  514|  8.50k|	itacns_ops.read_binary = itacns_read_binary;
  515|  8.50k|	itacns_ops.list_files = itacns_list_files;
  516|  8.50k|	itacns_ops.select_file = itacns_select_file;
  517|  8.50k|	itacns_ops.card_ctl = itacns_card_ctl;
  518|  8.50k|	itacns_ops.get_challenge = itacns_get_challenge;
  519|  8.50k|	return &itacns_drv;
  520|  8.50k|}
card-itacns.c:itacns_match_card:
  122|  2.86k|{
  123|  2.86k|	int r = 0;
  124|       |
  125|       |	/* Try table first */
  126|  2.86k|	r = _sc_match_atr(card, itacns_atrs, &card->type);
  127|  2.86k|	if(r >= 0) return 1;
  ------------------
  |  Branch (127:5): [True: 161, False: 2.69k]
  ------------------
  128|       |
  129|  2.69k|	if (itacns_match_cns_card(card)) return 1;
  ------------------
  |  Branch (129:6): [True: 44, False: 2.65k]
  ------------------
  130|  2.65k|	if (itacns_match_cie_card(card)) return 1;
  ------------------
  |  Branch (130:6): [True: 7, False: 2.64k]
  ------------------
  131|       |
  132|       |	/* No card type was matched. */
  133|  2.64k|	return 0;
  134|  2.65k|}
card-itacns.c:itacns_match_cns_card:
   85|  2.69k|{
   86|  2.69k|	u8 manufacturer_code;
   87|  2.69k|	u8 manufacturer_mask;
   88|  2.69k|	u8 fw_major;
   89|       |
   90|  2.69k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (90:6): [True: 2.50k, False: 195]
  ------------------
   91|    195|	    0 != memcmp(card->reader->atr_info.hist_bytes+9, "CNS", 3))
  ------------------
  |  Branch (91:6): [True: 151, False: 44]
  ------------------
   92|  2.65k|		return 0;
   93|       |
   94|     44|	card->type = SC_CARD_TYPE_ITACNS_CNS;
   95|       |
   96|     44|	manufacturer_code = card->reader->atr_info.hist_bytes[2];
   97|     44|	manufacturer_mask = card->reader->atr_info.hist_bytes[3];
   98|     44|	fw_major = card->reader->atr_info.hist_bytes[4];
   99|       |
  100|     44|	if (manufacturer_code == ITACNS_ICMAN_INFINEON &&
  ------------------
  |  |    9|     88|#define ITACNS_ICMAN_INFINEON		0x05
  ------------------
  |  Branch (100:6): [True: 8, False: 36]
  ------------------
  101|      8|	    manufacturer_mask == ITACNS_MASKMAN_IDEMIA &&
  ------------------
  |  |   11|     52|#define ITACNS_MASKMAN_IDEMIA		0x05
  ------------------
  |  Branch (101:6): [True: 3, False: 5]
  ------------------
  102|      3|	    fw_major >= 32) {
  ------------------
  |  Branch (102:6): [True: 1, False: 2]
  ------------------
  103|      1|			card->type = SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021;
  104|      1|	}
  105|       |
  106|     44|	return 1;
  107|  2.69k|}
card-itacns.c:itacns_match_cie_card:
  110|  2.65k|{
  111|  2.65k|	u8 h7_to_h15[] = { 0x02, 'I', 'T', 'I', 'D', 0x20, 0x20, 0x31, 0x80, };
  112|  2.65k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (112:6): [True: 2.50k, False: 151]
  ------------------
  113|    151|	    0 != memcmp(card->reader->atr_info.hist_bytes+6,
  ------------------
  |  Branch (113:6): [True: 144, False: 7]
  ------------------
  114|    151|			h7_to_h15, sizeof h7_to_h15))
  115|  2.64k|		return 0;
  116|       |
  117|      7|	card->type = SC_CARD_TYPE_ITACNS_CIE_V2;
  118|      7|	return 1;
  119|  2.65k|}
card-itacns.c:itacns_init:
  141|    212|{
  142|    212|	unsigned long	flags;
  143|       |
  144|    212|	SC_FUNC_CALLED(card->ctx, 1);
  ------------------
  |  |  148|    212|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    212|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    212|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 212]
  |  |  ------------------
  ------------------
  145|       |
  146|    212|	card->name = "CNS card";
  147|    212|	card->cla = 0x00;
  148|       |
  149|    212|	card->drv_data = calloc(1, sizeof(itacns_drv_data_t));
  150|    212|	if (!card->drv_data)
  ------------------
  |  Branch (150:6): [True: 0, False: 212]
  ------------------
  151|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  152|       |
  153|    212|	if (card->type == SC_CARD_TYPE_ITACNS_CNS)
  ------------------
  |  Branch (153:6): [True: 43, False: 169]
  ------------------
  154|     43|		itacns_init_cns_card(card);
  155|       |
  156|    212|	DRVDATA(card)->ic_manufacturer_code = card->reader->atr_info.hist_bytes[2];
  ------------------
  |  |   64|    212|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  157|    212|	DRVDATA(card)->mask_manufacturer_code = card->reader->atr_info.hist_bytes[3];
  ------------------
  |  |   64|    212|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  158|    212|	card->version.fw_major = card->reader->atr_info.hist_bytes[4];
  159|    212|	card->version.fw_minor = card->reader->atr_info.hist_bytes[5];
  160|       |
  161|       |	/* Set up algorithm info. */
  162|    212|	flags = SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|    212|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  163|    212|		| SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    212|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  164|    212|		| SC_ALGORITHM_RSA_HASHES
  ------------------
  |  |  142|    212|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  165|    212|		;
  166|       |
  167|    212|	if ((card->version.hw_major >= 1 && card->version.hw_minor >= 1) ||
  ------------------
  |  Branch (167:7): [True: 27, False: 185]
  |  Branch (167:38): [True: 21, False: 6]
  ------------------
  168|    191|	    card->type == SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021) {
  ------------------
  |  Branch (168:6): [True: 162, False: 29]
  ------------------
  169|    183|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    183|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  170|    183|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  171|    183|	} else {
  172|     29|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  173|     29|	}
  174|    212|	return SC_SUCCESS;
  ------------------
  |  |   28|    212|#define SC_SUCCESS				0
  ------------------
  175|    212|}
card-itacns.c:itacns_init_cns_card:
   67|     43|{
   68|     43|	if (15 != card->reader->atr_info.hist_bytes_len)
  ------------------
  |  Branch (68:6): [True: 0, False: 43]
  ------------------
   69|      0|		return;
   70|       |
   71|     43|	u8 cns_version = card->reader->atr_info.hist_bytes[12];
   72|     43|	card->version.hw_major = (cns_version >> 4) & 0x0f;
   73|     43|	card->version.hw_minor = cns_version & 0x0f;
   74|       |
   75|       |	/* Warn if version is not 1.X. */
   76|     43|	if (cns_version != 0x10 && cns_version != 0x11) {
  ------------------
  |  Branch (76:6): [True: 42, False: 1]
  |  Branch (76:29): [True: 40, False: 2]
  ------------------
   77|     40|		char version[8];
   78|     40|		snprintf(version, sizeof(version), "%d.%d", card->version.hw_major, card->version.hw_minor);
   79|     40|		sc_log(card->ctx, "CNS card version %s; no official specifications "
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   80|     40|		       "are published. Proceeding anyway.\n", version);
   81|     40|	}
   82|     43|}
card-itacns.c:itacns_finish:
  178|    212|{
  179|    212|	if(card->drv_data) {
  ------------------
  |  Branch (179:5): [True: 212, False: 0]
  ------------------
  180|    212|		free(card->drv_data);
  181|    212|	}
  182|    212|	return 0;
  183|    212|}
card-itacns.c:itacns_pin_cmd:
  297|     14|{
  298|     14|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     14|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  299|       |	/* Enable backtracking for STIncard cards. */
  300|     14|	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   64|     14|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
              	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   13|     14|#define ITACNS_MASKMAN_STINCARD		0x09
  ------------------
  |  Branch (300:5): [True: 1, False: 13]
  ------------------
  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|     14|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (306:6): [True: 14, False: 0]
  ------------------
  307|     14|		data->pin1.max_length = 8;
  308|     14|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (308:6): [True: 14, False: 0]
  ------------------
  309|     14|		data->pin2.max_length = 8;
  310|     14|	return default_ops->pin_cmd(card, data);
  311|     14|}
card-itacns.c:itacns_read_binary:
  316|    788|{
  317|    788|	size_t already_read = 0;
  318|    788|	size_t requested;
  319|    788|	int r;
  320|    799|	while(1) {
  ------------------
  |  Branch (320:8): [True: 799, Folded]
  ------------------
  321|    799|		requested = count - already_read;
  322|    799|		if(requested > ITACNS_MAX_PAYLOAD)
  ------------------
  |  |   36|    799|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  |  Branch (322:6): [True: 529, False: 270]
  ------------------
  323|    529|			requested = ITACNS_MAX_PAYLOAD;
  ------------------
  |  |   36|    529|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  324|    799|		r = default_ops->read_binary(card, (unsigned)(idx + already_read),
  325|    799|			&buf[already_read], requested, flags);
  326|    799|		if(r < 0)
  ------------------
  |  Branch (326:6): [True: 123, False: 676]
  ------------------
  327|    123|			return r;
  328|    676|		already_read += r;
  329|    676|		if (r == 0 || (size_t)r < requested || already_read == count) {
  ------------------
  |  Branch (329:7): [True: 65, False: 611]
  |  Branch (329:17): [True: 426, False: 185]
  |  Branch (329:42): [True: 174, False: 11]
  ------------------
  330|       |			/* We have finished */
  331|    665|			return (int)already_read;
  332|    665|		}
  333|    676|	}
  334|    788|}
card-itacns.c:itacns_select_file:
  421|  1.84k|{
  422|  1.84k|	int r;
  423|       |
  424|  1.84k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.84k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.84k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.84k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.84k]
  |  |  ------------------
  ------------------
  425|  1.84k|	r = default_ops->select_file(card, in_path, file);
  426|  1.84k|	if (r >= 0 && file) {
  ------------------
  |  Branch (426:6): [True: 659, False: 1.18k]
  |  Branch (426:16): [True: 215, False: 444]
  ------------------
  427|    215|		parse_sec_attr((*file), (*file)->sec_attr,
  428|    215|			(*file)->sec_attr_len);
  429|    215|	}
  430|  1.84k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.84k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.84k|	int _ret = r; \
  |  |  |  |  155|  1.84k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.18k, False: 659]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.84k|	} else { \
  |  |  |  |  159|      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.84k|	return _ret; \
  |  |  |  |  163|  1.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  1.84k|}
card-itacns.c:parse_sec_attr:
  403|    215|{
  404|    215|	size_t i;
  405|    215|	const int *idx;
  406|       |
  407|    215|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    215|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (407:8): [True: 2, False: 213]
  ------------------
  408|       |
  409|       |	/* acl defaults to 0xFF if unspecified */
  410|  2.15k|	for (i = 0; i < 9; i++) {
  ------------------
  |  Branch (410:14): [True: 1.93k, False: 215]
  ------------------
  411|  1.93k|		if (idx[i] != -1) {
  ------------------
  |  Branch (411:7): [True: 1.50k, False: 430]
  ------------------
  412|  1.50k|			add_acl_entry(file, idx[i],
  413|  1.50k|				(u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (413:10): [True: 87, False: 1.41k]
  ------------------
  414|  1.50k|		}
  415|  1.93k|	}
  416|    215|}
card-itacns.c:add_acl_entry:
  350|  1.50k|{
  351|  1.50k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.50k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  352|       |
  353|  1.50k|	switch (byte) {
  354|     21|	case 0x00:
  ------------------
  |  Branch (354:2): [True: 21, False: 1.48k]
  ------------------
  355|     21|		method = SC_AC_NONE;
  ------------------
  |  |  150|     21|#define SC_AC_NONE			0x00000000
  ------------------
  356|     21|		break;
  357|  1.42k|	case 0xFF:
  ------------------
  |  Branch (357:2): [True: 1.42k, False: 82]
  ------------------
  358|  1.43k|	case 0x66:
  ------------------
  |  Branch (358:2): [True: 7, False: 1.49k]
  ------------------
  359|  1.43k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.43k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  360|  1.43k|		break;
  361|     54|	default:
  ------------------
  |  Branch (361:2): [True: 54, False: 1.45k]
  ------------------
  362|     54|		if (byte > 0x1F) {
  ------------------
  |  Branch (362:7): [True: 35, False: 19]
  ------------------
  363|     35|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     35|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  364|     35|		} else {
  365|     19|			method = SC_AC_CHV;
  ------------------
  |  |  151|     19|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  366|     19|			key_ref = byte;
  367|     19|		}
  368|     54|		break;
  369|  1.50k|	}
  370|  1.50k|	sc_file_add_acl_entry(file, op, method, key_ref);
  371|  1.50k|}
card-itacns.c:itacns_card_ctl:
  486|    475|{
  487|    475|	switch (cmd) {
  ------------------
  |  Branch (487:10): [True: 14, False: 461]
  ------------------
  488|     14|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (488:3): [True: 14, False: 461]
  ------------------
  489|     14|		return itacns_get_serialnr(card, ptr);
  490|    475|	}
  491|    461|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    461|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  492|    475|}
card-itacns.c:itacns_get_serialnr:
  434|     14|{
  435|     14|	sc_path_t path;
  436|     14|	sc_file_t *file;
  437|     14|	size_t    len;
  438|     14|	int r;
  439|     14|	u8        rbuf[256];
  440|       |
  441|     14|	if (!serial) return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  |  Branch (441:6): [True: 0, False: 14]
  ------------------
  442|       |
  443|       |	/* see if we have cached serial number */
  444|     14|	if (card->serialnr.len) {
  ------------------
  |  Branch (444:6): [True: 0, False: 14]
  ------------------
  445|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  446|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  447|      0|	}
  448|       |
  449|     14|	sc_log(card->ctx, "Reading EF_IDCarta.\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  450|       |
  451|     14|	sc_format_path("3F0010001003", &path);
  452|       |
  453|     14|	r = sc_select_file(card, &path, &file);
  454|     14|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
  |  Branch (454:6): [True: 9, False: 5]
  ------------------
  455|      9|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      9|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  456|      9|	}
  457|      5|	len = file->size;
  458|      5|	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|      5|	if (len != 16) {
  ------------------
  |  Branch (464:6): [True: 4, False: 1]
  ------------------
  465|      4|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  466|      4|				"Unexpected file length of EF_IDCarta (%lu)\n",
  467|      4|				(unsigned long) len);
  468|      4|	}
  469|       |
  470|      5|	r = sc_read_binary(card, 0, rbuf, 256, 0);
  471|      5|	if ( r != 16 ) {
  ------------------
  |  Branch (471:7): [True: 4, False: 1]
  ------------------
  472|      4|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      4|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  473|      4|	}
  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|      5|}

jpki_select_ap:
   46|  2.25k|{
   47|  2.25k|	int rc;
   48|  2.25k|	sc_path_t path;
   49|       |
   50|  2.25k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.25k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.25k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.25k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.25k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   51|       |
   52|       |	/* Select JPKI application */
   53|  2.25k|	sc_format_path(AID_JPKI, &path);
  ------------------
  |  |   27|  2.25k|#define AID_JPKI "D392f000260100000001"
  ------------------
   54|  2.25k|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.25k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   55|  2.25k|	rc = sc_select_file(card, &path, NULL);
   56|  2.25k|	LOG_TEST_RET(card->ctx, rc, "select JPKI AP failed");
  ------------------
  |  |  174|  2.25k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.25k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.25k|	int _ret = (r); \
  |  |  |  |  168|  2.25k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.07k, False: 183]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.07k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.07k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.07k|		return _ret; \
  |  |  |  |  172|  2.07k|	} \
  |  |  |  |  173|  2.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   57|       |
   58|    183|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    183|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    183|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    183|	int _ret = r; \
  |  |  |  |  155|    183|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 183, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    183|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 183]
  |  |  |  |  ------------------
  |  |  |  |  157|    183|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    183|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    183|	return _ret; \
  |  |  |  |  163|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|    183|}
sc_get_jpki_driver:
  382|  8.50k|{
  383|  8.50k|	return sc_get_driver();
  384|  8.50k|}
card-jpki.c:sc_get_driver:
  363|  8.50k|{
  364|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  365|       |
  366|  8.50k|	jpki_ops = *iso_drv->ops;
  367|  8.50k|	jpki_ops.match_card = jpki_match_card;
  368|  8.50k|	jpki_ops.init = jpki_init;
  369|  8.50k|	jpki_ops.finish = jpki_finish;
  370|  8.50k|	jpki_ops.select_file = jpki_select_file;
  371|  8.50k|	jpki_ops.pin_cmd = jpki_pin_cmd;
  372|  8.50k|	jpki_ops.set_security_env = jpki_set_security_env;
  373|  8.50k|	jpki_ops.compute_signature = jpki_compute_signature;
  374|  8.50k|	jpki_ops.card_reader_lock_obtained = jpki_card_reader_lock_obtained;
  375|  8.50k|	jpki_ops.logout = jpki_logout;
  376|       |
  377|  8.50k|	return &jpki_drv;
  378|  8.50k|}
card-jpki.c:jpki_match_card:
   63|  2.15k|{
   64|  2.15k|	int i, rc;
   65|       |
   66|  2.15k|	i = _sc_match_atr(card, jpki_atrs, &card->type);
   67|  2.15k|	if (i >= 0) {
  ------------------
  |  Branch (67:6): [True: 0, False: 2.15k]
  ------------------
   68|      0|		return 1;
   69|      0|	}
   70|       |
   71|  2.15k|	rc = jpki_select_ap(card);
   72|  2.15k|	if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|  2.15k|#define SC_SUCCESS				0
  ------------------
  |  Branch (72:6): [True: 100, False: 2.05k]
  ------------------
   73|    100|		card->type = SC_CARD_TYPE_JPKI_BASE;
   74|    100|		return 1;
   75|    100|	}
   76|  2.05k|	return 0;
   77|  2.15k|}
card-jpki.c:jpki_init:
   95|    100|{
   96|    100|	struct jpki_private_data *drvdata;
   97|    100|	sc_file_t *mf;
   98|    100|	int flags;
   99|       |
  100|    100|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    100|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    100|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    100|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    100|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|       |
  102|    100|	drvdata = malloc(sizeof (struct jpki_private_data));
  103|    100|	if (!drvdata)
  ------------------
  |  Branch (103:6): [True: 0, False: 100]
  ------------------
  104|    100|		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|    100|	memset(drvdata, 0, sizeof (struct jpki_private_data));
  107|       |
  108|       |	/* create virtual MF */
  109|    100|	mf = sc_file_new();
  110|    100|	if (!mf) {
  ------------------
  |  Branch (110:6): [True: 0, False: 100]
  ------------------
  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|    100|	sc_format_path("3f00", &mf->path);
  115|    100|	mf->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    100|#define SC_FILE_TYPE_DF			0x04
  ------------------
  116|    100|	mf->shareable = 0;
  117|    100|	mf->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    100|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  118|    100|	mf->size = 0;
  119|    100|	mf->id = 0x3f00;
  120|    100|	mf->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    100|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  121|    100|	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  166|    100|#define SC_AC_OP_SELECT			0
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_SELECT, SC_AC_NONE, 0);
  ------------------
  |  |  150|    100|#define SC_AC_NONE			0x00000000
  ------------------
  122|    100|	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  172|    100|#define SC_AC_OP_LIST_FILES		6
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LIST_FILES, SC_AC_NONE, 0);
  ------------------
  |  |  150|    100|#define SC_AC_NONE			0x00000000
  ------------------
  123|    100|	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  167|    100|#define SC_AC_OP_LOCK			1
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_LOCK, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    100|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  124|    100|	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  168|    100|#define SC_AC_OP_DELETE			2
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_DELETE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    100|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  125|    100|	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  169|    100|#define SC_AC_OP_CREATE			3
  ------------------
              	sc_file_add_acl_entry(mf, SC_AC_OP_CREATE, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    100|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  126|    100|	drvdata->mf = mf;
  127|    100|	drvdata->selected = SELECT_MF;
  ------------------
  |  |   24|    100|#define SELECT_MF 0
  ------------------
  128|       |
  129|    100|	card->name = "jpki";
  130|    100|	card->drv_data = drvdata;
  131|       |
  132|    100|	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  133|    100|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	flags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    100|#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|    100|#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|    100|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  133|    100|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  134|       |
  135|    100|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    100|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  136|    100|}
card-jpki.c:jpki_finish:
   81|    100|{
   82|    100|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|    100|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   83|       |
   84|    100|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    100|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    100|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    100|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    100|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|    100|	if (drvdata) {
  ------------------
  |  Branch (85:6): [True: 100, False: 0]
  ------------------
   86|    100|		sc_file_free(drvdata->mf);
   87|    100|		free(drvdata);
   88|    100|		card->drv_data = NULL;
   89|    100|	}
   90|    100|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    100|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|    100|}
card-jpki.c:jpki_select_file:
  141|  3.29k|{
  142|  3.29k|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|  3.29k|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  143|  3.29k|	int rc;
  144|  3.29k|	sc_apdu_t apdu;
  145|  3.29k|	struct sc_file *file = NULL;
  146|       |
  147|  3.29k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.29k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.29k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.29k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|  3.29k|	sc_log(card->ctx, "jpki_select_file: path=%s, len=%zu", sc_print_path(path), path->len);
  ------------------
  |  |   71|  3.29k|#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.29k|	if (path->len == 2 && memcmp(path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (149:6): [True: 521, False: 2.77k]
  |  Branch (149:24): [True: 0, False: 521]
  ------------------
  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.29k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  293|  3.29k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  161|  3.29k|	switch (path->type) {
  162|    486|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|    486|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (162:2): [True: 486, False: 2.80k]
  ------------------
  163|    486|		apdu.p1 = 2;
  164|    486|		break;
  165|  2.47k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  2.47k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (165:2): [True: 2.47k, False: 819]
  ------------------
  166|  2.47k|		apdu.p1 = 4;
  167|  2.47k|		break;
  168|    333|	default:
  ------------------
  |  Branch (168:2): [True: 333, False: 2.95k]
  ------------------
  169|    333|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    333|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    333|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    333|	int _ret = r; \
  |  |  |  |  155|    333|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 333, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    333|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    333|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 333, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    333|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    333|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    333|	return _ret; \
  |  |  |  |  163|    333|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|  3.29k|	}
  171|  2.95k|	apdu.p2 = 0x0C;
  172|  2.95k|	apdu.data = path->value;
  173|  2.95k|	apdu.datalen = path->len;
  174|  2.95k|	apdu.lc = path->len;
  175|       |
  176|  2.95k|	rc = sc_transmit_apdu(card, &apdu);
  177|  2.95k|	LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|  2.95k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.95k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.95k|	int _ret = (r); \
  |  |  |  |  168|  2.95k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 2.93k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|  2.93k|	rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  179|  2.93k|	LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|  2.93k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.93k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.93k|	int _ret = (r); \
  |  |  |  |  168|  2.93k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.39k, False: 542]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.39k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.39k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.39k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.39k|		return _ret; \
  |  |  |  |  172|  2.39k|	} \
  |  |  |  |  173|  2.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 542]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  180|    542|	if (!file_out) {
  ------------------
  |  Branch (180:6): [True: 444, False: 98]
  ------------------
  181|    444|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    444|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    444|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    444|	int _ret = r; \
  |  |  |  |  155|    444|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 444, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    444|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 444]
  |  |  |  |  ------------------
  |  |  |  |  157|    444|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    444|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    444|	return _ret; \
  |  |  |  |  163|    444|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|    444|	}
  183|       |
  184|       |	/* read certificate file size */
  185|     98|	if (path->len == 2 && (
  ------------------
  |  Branch (185:6): [True: 98, False: 0]
  ------------------
  186|     98|		    memcmp(path->value, "\x00\x0A", 2) == 0 ||
  ------------------
  |  Branch (186:7): [True: 28, False: 70]
  ------------------
  187|     70|		    memcmp(path->value, "\x00\x01", 2) == 0 ||
  ------------------
  |  Branch (187:7): [True: 28, False: 42]
  ------------------
  188|     42|		    memcmp(path->value, "\x00\x0B", 2) == 0 ||
  ------------------
  |  Branch (188:7): [True: 22, False: 20]
  ------------------
  189|     20|		    memcmp(path->value, "\x00\x02", 2) == 0 )
  ------------------
  |  Branch (189:7): [True: 20, False: 0]
  ------------------
  190|     98|		) {
  191|     98|		u8 buf[4];
  192|     98|		rc = sc_read_binary(card, 0, buf, 4, 0);
  193|     98|		LOG_TEST_RET(card->ctx, rc, "SW Check failed");
  ------------------
  |  |  174|     98|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     98|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     98|	int _ret = (r); \
  |  |  |  |  168|     98|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 34, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  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|     98|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|     64|		if (rc < 4)
  ------------------
  |  Branch (194:7): [True: 40, False: 24]
  ------------------
  195|     64|			LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Received data too short");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|     24|		file = sc_file_new();
  197|     24|		if (!file) {
  ------------------
  |  Branch (197:7): [True: 0, False: 24]
  ------------------
  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|     24|		file->path = *path;
  201|     24|		file->size = (buf[2] << 8 | buf[3]) + 4;
  202|     24|		*file_out = file;
  203|     24|	}
  204|     24|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|     24|}
card-jpki.c:jpki_pin_cmd:
  209|    259|{
  210|    259|	int rc;
  211|    259|	sc_path_t path;
  212|    259|	sc_apdu_t apdu;
  213|    259|	struct jpki_private_data *priv = JPKI_DRVDATA(card);
  ------------------
  |  |   36|    259|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
  214|    259|	int max_tries = 0;
  215|       |
  216|    259|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    259|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    259|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    259|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    259|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 259]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|       |
  218|    259|	switch (data->pin_reference) {
  219|    119|	case 1:
  ------------------
  |  Branch (219:2): [True: 119, False: 140]
  ------------------
  220|    119|		sc_format_path(JPKI_AUTH_PIN, &path);
  ------------------
  |  |   29|    119|#define JPKI_AUTH_PIN "0018"
  ------------------
  221|    119|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    119|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  222|    119|		rc = sc_select_file(card, &path, NULL);
  223|    119|		max_tries = JPKI_AUTH_PIN_MAX_TRIES;
  ------------------
  |  |   30|    119|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  224|    119|		break;
  225|    127|	case 2:
  ------------------
  |  Branch (225:2): [True: 127, False: 132]
  ------------------
  226|    127|		sc_format_path(JPKI_SIGN_PIN, &path);
  ------------------
  |  |   33|    127|#define JPKI_SIGN_PIN "001B"
  ------------------
  227|    127|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    127|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  228|    127|		rc = sc_select_file(card, &path, NULL);
  229|    127|		max_tries = JPKI_SIGN_PIN_MAX_TRIES;
  ------------------
  |  |   34|    127|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  230|    127|		break;
  231|     13|	default:
  ------------------
  |  Branch (231:2): [True: 13, False: 246]
  ------------------
  232|     13|		sc_log(card->ctx, "Unknown PIN reference: %d", data->pin_reference);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  233|     13|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    259|	}
  235|    246|	LOG_TEST_RET(card->ctx, rc, "SELECT_FILE error");
  ------------------
  |  |  174|    246|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    246|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    246|	int _ret = (r); \
  |  |  |  |  168|    246|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 105, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  169|    105|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    105|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    105|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    105|		return _ret; \
  |  |  |  |  172|    105|	} \
  |  |  |  |  173|    246|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 141]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|    141|	switch (data->cmd) {
  238|     10|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     10|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (238:2): [True: 10, False: 131]
  ------------------
  239|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
  240|     10|		if (data->pin1.len == 0 && !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      1|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (240:7): [True: 1, False: 9]
  |  Branch (240:30): [True: 1, False: 0]
  ------------------
  241|     10|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  242|      9|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0x20, 0x00, 0x80);
  ------------------
  |  |  302|      9|#define SC_APDU_CASE_3			0x23
  ------------------
  243|      9|		apdu.data = data->pin1.data;
  244|      9|		apdu.datalen = data->pin1.len;
  245|      9|		apdu.lc = data->pin1.len;
  246|      9|		rc = sc_transmit_apdu(card, &apdu);
  247|      9|		LOG_TEST_RET(card->ctx, rc, "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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  248|      8|		rc = sc_check_sw(card, apdu.sw1, apdu.sw2);
  249|      8|		if (rc == SC_SUCCESS) {
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  |  Branch (249:7): [True: 1, False: 7]
  ------------------
  250|      1|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      1|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  251|      1|			data->pin1.tries_left = max_tries;
  252|      7|		} else {
  253|      7|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      7|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
  254|      7|			data->pin1.tries_left = apdu.sw2 & 0xF;
  255|      7|		}
  256|      8|		priv->logged_in = data->pin1.logged_in;
  257|      8|		LOG_TEST_RET(card->ctx, rc, "VERIFY 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: 7, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  258|      1|		break;
  259|    131|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    131|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (259:2): [True: 131, False: 10]
  ------------------
  260|    131|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0x00, 0x80);
  ------------------
  |  |  291|    131|#define SC_APDU_CASE_1			0x01
  ------------------
  261|    131|		rc = sc_transmit_apdu(card, &apdu);
  262|    131|		LOG_TEST_RET(card->ctx, rc, "APDU transmit failed");
  ------------------
  |  |  174|    131|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    131|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    131|	int _ret = (r); \
  |  |  |  |  168|    131|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 128]
  |  |  |  |  ------------------
  |  |  |  |  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|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 128]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|    128|		if (apdu.sw1 != 0x63) {
  ------------------
  |  Branch (263:7): [True: 60, False: 68]
  ------------------
  264|     60|			sc_log(card->ctx, "VERIFY GET_INFO error");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  265|     60|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  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|     60|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 60, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|     60|		}
  267|     68|		data->pin1.logged_in = priv->logged_in;
  268|     68|		data->pin1.tries_left = apdu.sw2 & 0xF;
  269|     68|		break;
  270|      0|	default:
  ------------------
  |  Branch (270:2): [True: 0, False: 141]
  ------------------
  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|    141|	}
  274|       |
  275|     69|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  276|     69|}
card-jpki.c:jpki_card_reader_lock_obtained:
  344|  2.59k|{
  345|  2.59k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.59k|#define SC_SUCCESS				0
  ------------------
  346|       |
  347|  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]
  |  |  ------------------
  ------------------
  348|       |
  349|  2.59k|	if (was_reset > 0) {
  ------------------
  |  Branch (349:6): [True: 0, False: 2.59k]
  ------------------
  350|      0|		r = jpki_select_ap(card);
  351|      0|	}
  352|       |
  353|  2.59k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.59k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.59k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  354|  2.59k|}

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

sc_get_masktech_driver:
  374|  8.50k|{
  375|  8.50k|	return sc_get_driver();
  376|  8.50k|}
card-masktech.c:sc_get_driver:
  355|  8.50k|{
  356|       |
  357|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (357:6): [True: 1, False: 8.49k]
  ------------------
  358|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  359|       |
  360|  8.50k|	masktech_ops = *iso_ops;
  361|       |
  362|  8.50k|	masktech_ops.match_card = masktech_match_card;
  363|  8.50k|	masktech_ops.init = masktech_init;
  364|  8.50k|	masktech_ops.finish = masktech_finish;
  365|  8.50k|	masktech_ops.set_security_env = masktech_set_security_env;
  366|  8.50k|	masktech_ops.compute_signature = masktech_compute_signature;
  367|  8.50k|	masktech_ops.decipher = masktech_decipher;
  368|  8.50k|	masktech_ops.pin_cmd = masktech_pin_cmd;
  369|  8.50k|	masktech_ops.card_ctl = masktech_card_ctl;
  370|  8.50k|	return &masktech_drv;
  371|  8.50k|}
card-masktech.c:masktech_match_card:
   62|  5.68k|{
   63|       |	/* check if the ATR is in the known ATR */
   64|  5.68k|	if (_sc_match_atr(card, masktech_atrs, &card->type) < 0)
  ------------------
  |  Branch (64:6): [True: 5.67k, False: 11]
  ------------------
   65|  5.67k|		return 0;
   66|       |
   67|     11|	return 1;
   68|  5.68k|}
card-masktech.c:masktech_init:
   71|     11|{
   72|     11|	unsigned long flags;
   73|     11|	struct masktech_private_data *data;
   74|       |
   75|     11|	sc_log(card->ctx,  "masktech_init()\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   76|       |
   77|       |	/* private data kept during the live of the driver */
   78|     11|	if (!(data = (struct masktech_private_data *) malloc(sizeof(*data))))
  ------------------
  |  Branch (78:6): [True: 0, False: 11]
  ------------------
   79|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
   80|     11|	card->drv_data = data;
   81|       |
   82|       |	/* supported RSA keys and how padding is done */
   83|     11|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|     11|#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|     11|#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|     11|#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|     11|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   84|     11|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
   85|     11|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
   86|     11|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
   87|     11|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     11|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
   88|     11|	return SC_SUCCESS;
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
   89|     11|}
card-masktech.c:masktech_finish:
   93|     11|{
   94|       |	/* free the private data */
   95|     11|	if (card->drv_data) {
  ------------------
  |  Branch (95:6): [True: 11, False: 0]
  ------------------
   96|     11|		free(card->drv_data);
   97|       |		card->drv_data = NULL;
   98|     11|	}
   99|     11|	return 0;
  100|     11|}
card-masktech.c:masktech_pin_cmd:
  283|     10|{
  284|     10|	int       rv;
  285|     10|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     10|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  ------------------
  ------------------
  286|       |
  287|     10|	switch(data->cmd)
  288|     10|	{
  289|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (289:2): [True: 0, False: 10]
  ------------------
  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: 10]
  ------------------
  293|      0|		rv = masktech_pin_change(card, data);
  294|      0|		break;
  295|     10|	default:
  ------------------
  |  Branch (295:2): [True: 10, False: 0]
  ------------------
  296|     10|		rv = iso_ops->pin_cmd(card, data);
  297|     10|		break;
  298|     10|	}
  299|     10|	return rv;
  300|       |
  301|       |
  302|     10|}
card-masktech.c:masktech_card_ctl:
  344|     10|{
  345|     10|	sc_log(card->ctx,  "masktech_card_ctl()\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__
  |  |  ------------------
  ------------------
  346|     10|	switch (cmd) {
  347|     10|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (347:3): [True: 10, False: 0]
  ------------------
  348|     10|			return masktech_get_serialnr(card, (sc_serial_number_t *) ptr);
  349|      0|		default:
  ------------------
  |  Branch (349:3): [True: 0, False: 10]
  ------------------
  350|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  351|     10|	}
  352|     10|}
card-masktech.c:masktech_get_serialnr:
  305|     10|{
  306|     10|	struct sc_apdu apdu;
  307|     10|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE-2];
  308|     10|	int rv;
  309|       |
  310|     10|	if (!serial)
  ------------------
  |  Branch (310:6): [True: 0, False: 10]
  ------------------
  311|     10|		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|     10|	card->cla = 0x80;
  315|     10|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x08, 0x00, 0x00);
  ------------------
  |  |  292|     10|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  316|     10|	apdu.resplen = sizeof(apdu_resp);
  317|     10|	apdu.resp = apdu_resp;
  318|       |
  319|     10|	rv = sc_transmit_apdu(card, &apdu);
  320|     10|	card->cla = 0x00;
  321|       |
  322|     10|	LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 1, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|      9|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (324:6): [True: 6, False: 3]
  |  Branch (324:26): [True: 1, False: 2]
  ------------------
  325|      7|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
  326|       |
  327|      2|	if (SC_MAX_SERIALNR < apdu.resplen)
  ------------------
  |  |  372|      2|#define SC_MAX_SERIALNR         32
  ------------------
  |  Branch (327:6): [True: 1, False: 1]
  ------------------
  328|      1|	{
  329|      1|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|      1|	}
  331|       |	/* cache serial number */
  332|      1|	card->serialnr.len = apdu.resplen;
  333|      1|	memcpy(card->serialnr.value, apdu.resp, card->serialnr.len);
  334|       |
  335|       |	/* copy and return serial number */
  336|      1|	if (serial)
  ------------------
  |  Branch (336:6): [True: 1, False: 0]
  ------------------
  337|      1|		memcpy(serial, &card->serialnr, sizeof(*serial));
  338|       |
  339|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  340|      1|}

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

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

sc_get_myeid_driver:
 2133|  8.50k|{
 2134|  8.50k|	return sc_get_driver();
 2135|  8.50k|}
card-myeid.c:sc_get_driver:
 2098|  8.50k|{
 2099|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2100|       |
 2101|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2101:6): [True: 1, False: 8.49k]
  ------------------
 2102|      1|		iso_ops = iso_drv->ops;
 2103|       |
 2104|  8.50k|	myeid_ops			= *iso_drv->ops;
 2105|  8.50k|	myeid_ops.match_card		= myeid_match_card;
 2106|  8.50k|	myeid_ops.init			= myeid_init;
 2107|  8.50k|	myeid_ops.finish		= myeid_finish;
 2108|       |	/* no record oriented file services */
 2109|  8.50k|	myeid_ops.read_record		= NULL;
 2110|  8.50k|	myeid_ops.write_record		= NULL;
 2111|  8.50k|	myeid_ops.append_record		= NULL;
 2112|       |	myeid_ops.update_record		= NULL;
 2113|  8.50k|	myeid_ops.select_file		= myeid_select_file;
 2114|  8.50k|	myeid_ops.get_response		= iso_ops->get_response;
 2115|  8.50k|	myeid_ops.logout		= myeid_logout;
 2116|  8.50k|	myeid_ops.create_file		= myeid_create_file;
 2117|  8.50k|	myeid_ops.delete_file		= myeid_delete_file;
 2118|  8.50k|	myeid_ops.list_files		= myeid_list_files;
 2119|  8.50k|	myeid_ops.set_security_env	= myeid_set_security_env;
 2120|  8.50k|	myeid_ops.compute_signature	= myeid_compute_signature;
 2121|  8.50k|	myeid_ops.decipher		= myeid_decipher;
 2122|  8.50k|	myeid_ops.process_fci		= myeid_process_fci;
 2123|  8.50k|	myeid_ops.card_ctl		= myeid_card_ctl;
 2124|  8.50k|	myeid_ops.pin_cmd		= myeid_pin_cmd;
 2125|  8.50k|	myeid_ops.wrap			= myeid_wrap_key;
 2126|  8.50k|	myeid_ops.unwrap		= myeid_unwrap_key;
 2127|  8.50k|	myeid_ops.encrypt_sym		= myeid_encrypt_sym;
 2128|  8.50k|	myeid_ops.decrypt_sym		= myeid_decrypt_sym;
 2129|  8.50k|	return &myeid_drv;
 2130|  8.50k|}
card-myeid.c:myeid_match_card:
  122|  6.50k|{
  123|  6.50k|	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|  6.50k|	if (len >= 5) {
  ------------------
  |  Branch (126:6): [True: 3.58k, False: 2.92k]
  ------------------
  127|  3.58k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "MyEID", 5)) {
  ------------------
  |  Branch (127:7): [True: 431, False: 3.15k]
  ------------------
  128|    431|			sc_log(card->ctx, "Matched MyEID card");
  ------------------
  |  |   71|    431|#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|    431|			card->type = SC_CARD_TYPE_MYEID_GENERIC;
  130|    431|			return 1;
  131|    431|		}
  132|       |		/* The software implementation of MyEID is identified by OsEID bytes */
  133|  3.15k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "OsEID", 5)) {
  ------------------
  |  Branch (133:7): [True: 88, False: 3.06k]
  ------------------
  134|     88|			sc_log(card->ctx, "Matched OsEID card");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  135|     88|			card->type = SC_CARD_TYPE_MYEID_OSEID;
  136|     88|			return 1;
  137|     88|		}
  138|  3.15k|	}
  139|  5.98k|	return 0;
  140|  6.50k|}
card-myeid.c:myeid_init:
  171|    519|{
  172|    519|	unsigned long flags = 0, ext_flags = 0;
  173|    519|	myeid_private_data_t *priv;
  174|    519|	u8 appletInfo[20];
  175|    519|	size_t appletInfoLen;
  176|    519|	myeid_card_caps_t card_caps;
  177|    519|	static struct sc_aid myeid_aid = { "\xA0\x00\x00\x00\x63\x50\x4B\x43\x53\x2D\x31\x35", 0x0C };
  178|    519|	int rv = 0;
  179|    519|	void *old_drv_data = card->drv_data;
  180|       |
  181|    519|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    519|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    519|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    519|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    519|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 519]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|    519|	switch (card->type) {
  184|     88|	case SC_CARD_TYPE_MYEID_OSEID:
  ------------------
  |  Branch (184:2): [True: 88, False: 431]
  ------------------
  185|     88|		card->name = oseid_card_name;
  186|     88|		break;
  187|    431|	case SC_CARD_TYPE_MYEID_GENERIC:
  ------------------
  |  Branch (187:2): [True: 431, False: 88]
  ------------------
  188|    431|		card->name = myeid_card_name;
  189|    431|		break;
  190|      0|	default:
  ------------------
  |  Branch (190:2): [True: 0, False: 519]
  ------------------
  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|    519|	}
  193|       |
  194|    519|	priv = calloc(1, sizeof(myeid_private_data_t));
  195|       |
  196|    519|	if (!priv)
  ------------------
  |  Branch (196:6): [True: 0, False: 519]
  ------------------
  197|    519|		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|    519|	rv = myeid_load_options (card->ctx, priv);
  200|    519|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Unable to read options from opensc.conf");
  ------------------
  |  |  184|    519|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    519|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    519|	int _ret = (r); \
  |  |  |  |  178|    519|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 519]
  |  |  |  |  ------------------
  |  |  |  |  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|    519|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 519]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|    519|	priv->card_state = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|    519|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  203|    519|	card->drv_data = priv;
  204|       |
  205|       |	/* Ensure that the MyEID applet is selected. */
  206|    519|	rv = iso7816_select_aid(card, myeid_aid.value, myeid_aid.len, NULL, NULL);
  207|    519|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to select MyEID applet.");
  ------------------
  |  |  184|    519|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    519|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    519|	int _ret = (r); \
  |  |  |  |  178|    519|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 9, False: 510]
  |  |  |  |  ------------------
  |  |  |  |  179|      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
  |  |  |  |  ------------------
  |  |  |  |  180|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      9|		goto err; \
  |  |  |  |  182|      9|	} \
  |  |  |  |  183|    519|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 510]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|       |	/* find out MyEID version */
  210|       |
  211|    510|	appletInfoLen = 20;
  212|       |
  213|    510|	if (0 > myeid_get_info(card, appletInfo, appletInfoLen))
  ------------------
  |  Branch (213:6): [True: 187, False: 323]
  ------------------
  214|    510|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information.");
  ------------------
  |  |  184|    187|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    187|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    187|	int _ret = (r); \
  |  |  |  |  178|    187|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 187, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    187|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    187|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    187|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    187|		goto err; \
  |  |  |  |  182|    187|	} \
  |  |  |  |  183|    187|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|       |
  216|    323|	priv->change_counter = appletInfo[19] | appletInfo[18] << 8;
  217|       |
  218|    323|	memset(&card_caps, 0, sizeof(myeid_card_caps_t));
  219|    323|	card_caps.max_ecc_key_length = 256;
  220|    323|	card_caps.max_rsa_key_length = 2048;
  221|       |
  222|    323|	if (card->version.fw_major >= 40) {
  ------------------
  |  Branch (222:6): [True: 296, False: 27]
  ------------------
  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|    296|	    if (myeid_get_card_caps(card, &card_caps) != SC_SUCCESS) {
  ------------------
  |  |   28|    296|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:10): [True: 44, False: 252]
  ------------------
  226|     44|			sc_log(card->ctx, "Failed to get card capabilities. Using default max ECC key length 256.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  227|     44|	    }
  228|    296|	}
  229|       |
  230|    323|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    323|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    323|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  231|    323|	if (priv->disable_hw_pkcs1_padding == 0)
  ------------------
  |  Branch (231:6): [True: 323, False: 0]
  ------------------
  232|    323|		flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    323|#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|    323|#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|    323|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  233|    323|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    323|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  234|       |
  235|    323|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  236|    323|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  237|    323|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  238|    323|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  239|    323|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  240|       |
  241|    323|	if (card_caps.card_supported_features & MYEID_CARD_CAP_RSA) {
  ------------------
  |  |   50|    323|#define MYEID_CARD_CAP_RSA		0x01
  ------------------
  |  Branch (241:6): [True: 240, False: 83]
  ------------------
  242|    240|		if (card_caps.max_rsa_key_length >= 3072)
  ------------------
  |  Branch (242:7): [True: 223, False: 17]
  ------------------
  243|    223|			_sc_card_add_rsa_alg(card, 3072, flags, 0);
  244|    240|		if (card_caps.max_rsa_key_length >= 4096)
  ------------------
  |  Branch (244:7): [True: 168, False: 72]
  ------------------
  245|    168|			_sc_card_add_rsa_alg(card, 4096, flags, 0);
  246|    240|	}
  247|       |
  248|       |	/* show ECC algorithms if the applet version of the inserted card supports them */
  249|    323|	if (card->version.fw_major >= 35) {
  ------------------
  |  Branch (249:6): [True: 299, False: 24]
  ------------------
  250|    299|		int i;
  251|       |
  252|    299|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  174|    299|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  173|    299|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    299|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  253|    299|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    299|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    299|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  254|    299|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    299|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    299|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  255|       |
  256|  1.49k|		for (i=0; ec_curves[i].curve_name != NULL; i++) {
  ------------------
  |  Branch (256:13): [True: 1.19k, False: 299]
  ------------------
  257|  1.19k|			if (card_caps.max_ecc_key_length >= ec_curves[i].size)
  ------------------
  |  Branch (257:8): [True: 1.04k, False: 155]
  ------------------
  258|  1.04k|				_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].curve_oid);
  259|  1.19k|		}
  260|    299|	}
  261|       |
  262|       |	/* show supported symmetric algorithms */
  263|    323|	flags = 0;
  264|    323|	if (card_caps.card_supported_features & MYEID_CARD_CAP_3DES) {
  ------------------
  |  |   51|    323|#define MYEID_CARD_CAP_3DES		0x02
  ------------------
  |  Branch (264:6): [True: 228, False: 95]
  ------------------
  265|    228|		if (card_caps.max_des_key_length >= 64)
  ------------------
  |  Branch (265:7): [True: 218, False: 10]
  ------------------
  266|    218|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_DES, 64, flags);
  ------------------
  |  |   76|    218|#define SC_ALGORITHM_DES		64
  ------------------
  267|    228|		if (card_caps.max_des_key_length >= 128)
  ------------------
  |  Branch (267:7): [True: 150, False: 78]
  ------------------
  268|    150|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 128, flags);
  ------------------
  |  |   77|    150|#define SC_ALGORITHM_3DES		65
  ------------------
  269|    228|		if (card_caps.max_des_key_length >= 192)
  ------------------
  |  Branch (269:7): [True: 146, False: 82]
  ------------------
  270|    146|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 192, flags);
  ------------------
  |  |   77|    146|#define SC_ALGORITHM_3DES		65
  ------------------
  271|    228|	}
  272|    323|	if (card_caps.card_supported_features & MYEID_CARD_CAP_AES) {
  ------------------
  |  |   52|    323|#define MYEID_CARD_CAP_AES		0x04
  ------------------
  |  Branch (272:6): [True: 231, False: 92]
  ------------------
  273|    231|		if (card_caps.max_aes_key_length >= 128)
  ------------------
  |  Branch (273:7): [True: 200, False: 31]
  ------------------
  274|    200|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 128, flags);
  ------------------
  |  |   79|    200|#define SC_ALGORITHM_AES		67
  ------------------
  275|    231|		if (card_caps.max_aes_key_length >= 256)
  ------------------
  |  Branch (275:7): [True: 192, False: 39]
  ------------------
  276|    192|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 256, flags);
  ------------------
  |  |   79|    192|#define SC_ALGORITHM_AES		67
  ------------------
  277|    231|	}
  278|       |
  279|       |	/* State that we have an RNG */
  280|    323|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    323|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    323|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  281|       |
  282|    323|	if ((card->version.fw_major == 40 && card->version.fw_minor >= 10 )
  ------------------
  |  Branch (282:7): [True: 7, False: 316]
  |  Branch (282:39): [True: 2, False: 5]
  ------------------
  283|    321|		|| card->version.fw_major >= 41)
  ------------------
  |  Branch (283:6): [True: 289, False: 32]
  ------------------
  284|    291|		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  572|    291|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  574|    291|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  285|    291|			   | SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  569|    291|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  286|       |
  287|    323|	if (card->version.fw_major >= 45)
  ------------------
  |  Branch (287:6): [True: 285, False: 38]
  ------------------
  288|    285|		priv->cap_chaining = 1;
  289|    323|	if (card->version.fw_major >= 40)
  ------------------
  |  Branch (289:6): [True: 296, False: 27]
  ------------------
  290|    296|		card->max_recv_size = 256;
  291|     27|	else
  292|     27|		card->max_recv_size = 255;
  293|    323|	card->max_send_size = 255;
  294|       |
  295|    323|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    323|#define SC_SUCCESS				0
  ------------------
  296|       |
  297|    519|err:
  298|    519|	if (rv < 0) {
  ------------------
  |  Branch (298:6): [True: 9, False: 510]
  ------------------
  299|      9|		free(priv);
  300|      9|		card->drv_data = old_drv_data;
  301|      9|	}
  302|       |
  303|    519|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    519|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    519|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    519|	int _ret = r; \
  |  |  |  |  155|    519|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 519, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    519|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 510]
  |  |  |  |  ------------------
  |  |  |  |  157|    519|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    519|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    519|	return _ret; \
  |  |  |  |  163|    519|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|    519|}
card-myeid.c:myeid_load_options:
  143|    519|{
  144|    519|	int r;
  145|    519|	size_t i, j;
  146|    519|	scconf_block **found_blocks, *block;
  147|       |
  148|    519|	if (!ctx || !priv) {
  ------------------
  |  Branch (148:6): [True: 0, False: 519]
  |  Branch (148:14): [True: 0, False: 519]
  ------------------
  149|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  150|      0|		goto err;
  151|      0|	}
  152|    519|	priv->disable_hw_pkcs1_padding = 0;
  153|  1.03k|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (153:14): [True: 519, False: 519]
  ------------------
  154|    519|		found_blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  155|    519|				"card_driver", "myeid");
  156|    519|		if (!found_blocks)
  ------------------
  |  Branch (156:7): [True: 0, False: 519]
  ------------------
  157|      0|			continue;
  158|    519|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (158:40): [True: 0, False: 519]
  ------------------
  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|    519|		free(found_blocks);
  163|    519|	}
  164|    519|	r = SC_SUCCESS;
  ------------------
  |  |   28|    519|#define SC_SUCCESS				0
  ------------------
  165|       |
  166|    519|err:
  167|    519|	return r;
  168|    519|}
card-myeid.c:myeid_get_info:
 1690|    844|{
 1691|    844|	sc_apdu_t apdu;
 1692|    844|	int r;
 1693|       |
 1694|    844|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    844|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    844|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    844|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    844|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 844]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1695|       |
 1696|    844|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xA0);
  ------------------
  |  |  292|    844|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1697|    844|	apdu.resp    = rbuf;
 1698|    844|	apdu.resplen = buflen;
 1699|    844|	apdu.le      = buflen;
 1700|       |
 1701|    844|	r = sc_transmit_apdu(card, &apdu);
 1702|    844|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|    844|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    844|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    844|	int _ret = (r); \
  |  |  |  |  168|    844|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 824]
  |  |  |  |  ------------------
  |  |  |  |  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|    844|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 824]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|       |
 1704|    824|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1704:6): [True: 314, False: 510]
  |  Branch (1704:26): [True: 17, False: 493]
  ------------------
 1705|    331|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    331|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1706|       |
 1707|    493|	if (apdu.resplen != 20)
  ------------------
  |  Branch (1707:6): [True: 151, False: 342]
  ------------------
 1708|    151|	{
 1709|    151|		sc_log(card->ctx, "Unexpected response to GET DATA (applet info)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1710|    151|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    151|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1711|    151|	}
 1712|       |
 1713|       |	/* store the applet version */
 1714|    342|	card->version.fw_major = rbuf[5] * 10 + rbuf[6];
 1715|    342|	card->version.fw_minor = rbuf[7];
 1716|       |	/* add version to name */
 1717|    342|	snprintf(card_name_buf, sizeof(card_name_buf),
 1718|    342|			"%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
 1719|    342|	card->name = card_name_buf;
 1720|       |
 1721|    342|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    342|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    342|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    342|	int _ret = r; \
  |  |  |  |  155|    342|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 342, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    342|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 342]
  |  |  |  |  ------------------
  |  |  |  |  157|    342|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    342|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    342|	return _ret; \
  |  |  |  |  163|    342|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1722|    342|}
card-myeid.c:myeid_get_card_caps:
 1773|    296|{
 1774|    296|	sc_apdu_t apdu;
 1775|    296|	int r;
 1776|    296|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1777|       |
 1778|    296|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    296|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    296|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    296|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    296|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 296]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|       |
 1780|    296|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xAA);
  ------------------
  |  |  292|    296|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1781|    296|	apdu.resp    = rbuf;
 1782|    296|	apdu.resplen = sizeof(myeid_card_caps_t);
 1783|    296|	apdu.le      = sizeof(myeid_card_caps_t);
 1784|       |
 1785|    296|	r = sc_transmit_apdu(card, &apdu);
 1786|    296|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|    296|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    296|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    296|	int _ret = (r); \
  |  |  |  |  168|    296|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 293]
  |  |  |  |  ------------------
  |  |  |  |  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|    296|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 293]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1787|       |
 1788|    293|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1788:6): [True: 22, False: 271]
  |  Branch (1788:26): [True: 16, False: 255]
  ------------------
 1789|     38|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     38|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1790|       |
 1791|    255|	if (apdu.resplen < 11) {
  ------------------
  |  Branch (1791:6): [True: 3, False: 252]
  ------------------
 1792|      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__
  |  |  ------------------
  ------------------
 1793|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1794|      3|	}
 1795|       |
 1796|    252|	card_caps->card_caps_ver = rbuf[0];
 1797|       |	/* the card returns big endian values */
 1798|    252|	card_caps->card_supported_features = (unsigned short) rbuf[1] << 8 | rbuf[2];
 1799|    252|	card_caps->max_rsa_key_length = (unsigned short) rbuf[3] << 8 | rbuf[4];
 1800|    252|	card_caps->max_des_key_length = (unsigned short) rbuf[5] << 8 | rbuf[6];
 1801|    252|	card_caps->max_aes_key_length = (unsigned short) rbuf[7] << 8 | rbuf[8];
 1802|    252|	card_caps->max_ecc_key_length = (unsigned short) rbuf[9] << 8 | rbuf[10];
 1803|       |
 1804|    252|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    252|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    252|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    252|	int _ret = r; \
  |  |  |  |  155|    252|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 252, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    252|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 252]
  |  |  |  |  ------------------
  |  |  |  |  157|    252|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    252|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    252|	return _ret; \
  |  |  |  |  163|    252|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1805|    252|}
card-myeid.c:myeid_finish:
 1843|    510|{
 1844|    510|	struct myeid_private_data *priv = (struct myeid_private_data *) card->drv_data;
 1845|    510|	free(priv);
 1846|    510|	return SC_SUCCESS;
  ------------------
  |  |   28|    510|#define SC_SUCCESS				0
  ------------------
 1847|    510|}
card-myeid.c:myeid_select_file:
  392|  2.87k|{
  393|  2.87k|	int r;
  394|       |
  395|  2.87k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.87k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.87k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.87k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.87k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|  2.87k|	r = iso_ops->select_file(card, in_path, file);
  397|       |
  398|  2.87k|	if (r == 0 && file != NULL && *file != NULL)
  ------------------
  |  Branch (398:6): [True: 1.07k, False: 1.80k]
  |  Branch (398:16): [True: 677, False: 393]
  |  Branch (398:32): [True: 677, False: 0]
  ------------------
  399|    677|		parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  400|       |
  401|  2.87k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.87k|	int _ret = r; \
  |  |  |  |  155|  2.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  1.80k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.80k, False: 1.07k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.87k|	return _ret; \
  |  |  |  |  163|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|  2.87k|}
card-myeid.c:parse_sec_attr:
  350|    677|{
  351|    677|	int i;
  352|    677|	const int df_ops[4] =
  353|    677|		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|    677|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|    677|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|    677|#define SC_AC_OP_DELETE			2
  ------------------
  354|    677|	const int ef_ops[4] =
  355|    677|		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  188|    677|#define SC_AC_OP_READ			22
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  189|    677|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|    677|#define SC_AC_OP_DELETE			2
  ------------------
  356|    677|	const int key_ops[4] =
  357|    677|		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  173|    677|#define SC_AC_OP_CRYPTO			7
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  189|    677|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  168|    677|#define SC_AC_OP_DELETE			2
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  192|    677|#define SC_AC_OP_GENERATE		26
  ------------------
  358|       |
  359|    677|	const int *ops;
  360|       |
  361|    677|	if (len < 2)
  ------------------
  |  Branch (361:6): [True: 274, False: 403]
  ------------------
  362|    274|		return;
  363|       |
  364|    403|	switch (file->type) {
  365|    377|	case SC_FILE_TYPE_WORKING_EF:
  ------------------
  |  |  216|    377|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (365:2): [True: 377, False: 26]
  ------------------
  366|    377|		ops = ef_ops;
  367|    377|		break;
  368|      5|	case SC_FILE_TYPE_INTERNAL_EF:
  ------------------
  |  |  215|      5|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (368:2): [True: 5, False: 398]
  ------------------
  369|      5|		ops = key_ops;
  370|      5|		break;
  371|      4|	case SC_FILE_TYPE_DF:
  ------------------
  |  |  214|      4|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (371:2): [True: 4, False: 399]
  ------------------
  372|      4|		ops = df_ops;
  373|      4|		break;
  374|     17|	default:
  ------------------
  |  Branch (374:2): [True: 17, False: 386]
  ------------------
  375|     17|		ops = key_ops;
  376|     17|		break;
  377|    403|	}
  378|       |
  379|  2.01k|	for (i = 0; i < 4; i++)
  ------------------
  |  Branch (379:14): [True: 1.61k, False: 403]
  ------------------
  380|  1.61k|	{
  381|  1.61k|		if (ops[i] == -1)
  ------------------
  |  Branch (381:7): [True: 381, False: 1.23k]
  ------------------
  382|    381|			continue;
  383|  1.23k|		if ((i & 1) == 0)
  ------------------
  |  Branch (383:7): [True: 806, False: 425]
  ------------------
  384|    806|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] >> 4));
  385|    425|		else
  386|    425|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] & 0x0F));
  387|  1.23k|	}
  388|    403|}
card-myeid.c:add_acl_entry:
  330|  1.23k|{
  331|  1.23k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.23k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  332|       |
  333|  1.23k|	switch (byte)
  334|  1.23k|	{
  335|    491|	case 0:
  ------------------
  |  Branch (335:2): [True: 491, False: 740]
  ------------------
  336|    491|		method = SC_AC_NONE;
  ------------------
  |  |  150|    491|#define SC_AC_NONE			0x00000000
  ------------------
  337|    491|		break;
  338|     32|	case 15:
  ------------------
  |  Branch (338:2): [True: 32, False: 1.19k]
  ------------------
  339|     32|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     32|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  340|     32|		break;
  341|    708|	default:
  ------------------
  |  Branch (341:2): [True: 708, False: 523]
  ------------------
  342|    708|		method = SC_AC_CHV;
  ------------------
  |  |  151|    708|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  343|    708|		key_ref = byte;
  344|    708|		break;
  345|  1.23k|	}
  346|  1.23k|	sc_file_add_acl_entry(file, op, method, key_ref);
  347|  1.23k|}
card-myeid.c:myeid_process_fci:
  442|    666|{
  443|    666|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  444|    666|	size_t taglen = 0;
  445|    666|	const u8 *tag = NULL;
  446|    666|	int r;
  447|       |
  448|    666|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    666|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    666|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    666|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    666|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 666]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  449|    666|	r = iso_ops->process_fci(card, file, buf, buflen);
  450|    666|	if (r < 0)
  ------------------
  |  Branch (450:6): [True: 0, False: 666]
  ------------------
  451|    666|	 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|    666|	if(file->type == SC_FILE_EF_UNKNOWN)
  ------------------
  |  |  220|    666|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  |  Branch (453:5): [True: 176, False: 490]
  ------------------
  454|    176|	{
  455|    176|		tag = sc_asn1_find_tag(NULL, buf, buflen, 0x82, &taglen);
  456|    176|		if (tag != NULL && taglen > 0 && *tag == 17)
  ------------------
  |  Branch (456:7): [True: 24, False: 152]
  |  Branch (456:22): [True: 21, False: 3]
  |  Branch (456:36): [True: 4, False: 17]
  ------------------
  457|      4|		{
  458|      4|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      4|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  459|      4|		}
  460|    176|	}
  461|    666|	if(file->sec_attr_len >= 3)
  ------------------
  |  Branch (461:5): [True: 401, False: 265]
  ------------------
  462|    401|	{
  463|    401|		sc_log(card->ctx, "id (%X) sec_attr (%X %X %X)", file->id,
  ------------------
  |  |   71|    401|#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|    401|			file->sec_attr[0],file->sec_attr[1],file->sec_attr[2]);
  465|    401|	}
  466|       |
  467|    666|	priv->card_state = file->status;
  468|    666|	switch (file->status) {
  469|      2|		case SC_FILE_STATUS_CREATION:
  ------------------
  |  |  240|      2|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (469:3): [True: 2, False: 664]
  ------------------
  470|      2|			file->acl_inactive = 1;
  471|      2|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_CREATION", file->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  472|      2|			break;
  473|    319|		case SC_FILE_STATUS_ACTIVATED:
  ------------------
  |  |  236|    319|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  |  Branch (473:3): [True: 319, False: 347]
  ------------------
  474|    319|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_ACTIVATED", file->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  475|    319|			break;
  476|    345|		default:
  ------------------
  |  Branch (476:3): [True: 345, False: 321]
  ------------------
  477|    345|			sc_log(card->ctx, "File id (%X) unusual status (0x%X)", file->id, file->status);
  ------------------
  |  |   71|    345|#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|    666|	}
  479|       |
  480|    666|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|    666|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    666|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    666|	int _ret = r; \
  |  |  |  |  155|    666|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 666, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    666|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 666]
  |  |  |  |  ------------------
  |  |  |  |  157|    666|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    666|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    666|	return _ret; \
  |  |  |  |  163|    666|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|    666|}
card-myeid.c:myeid_card_ctl:
 1808|    334|{
 1809|    334|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    334|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1810|    334|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1811|       |
 1812|    334|	switch(cmd) {
  ------------------
  |  Branch (1812:9): [True: 334, False: 0]
  ------------------
 1813|      0|	case SC_CARDCTL_MYEID_PUTDATA:
  ------------------
  |  Branch (1813:2): [True: 0, False: 334]
  ------------------
 1814|      0|		r = myeid_putdata(card,
 1815|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1816|      0|		break;
 1817|      0|	case SC_CARDCTL_MYEID_GETDATA:
  ------------------
  |  Branch (1817:2): [True: 0, False: 334]
  ------------------
 1818|      0|		r = myeid_getdata(card,
 1819|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1820|      0|		break;
 1821|      0|	case SC_CARDCTL_MYEID_GENERATE_STORE_KEY:
  ------------------
  |  Branch (1821:2): [True: 0, False: 334]
  ------------------
 1822|      0|		r = myeid_generate_store_key(card,
 1823|      0|			(struct sc_cardctl_myeid_gen_store_key_info *) ptr);
 1824|      0|		break;
 1825|      0|	case SC_CARDCTL_MYEID_ACTIVATE_CARD:
  ------------------
  |  Branch (1825:2): [True: 0, False: 334]
  ------------------
 1826|      0|		r = myeid_activate_card(card);
 1827|      0|		break;
 1828|     93|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1828:2): [True: 93, False: 241]
  ------------------
 1829|     93|		r = myeid_get_serialnr(card, (sc_serial_number_t *)ptr);
 1830|     93|		break;
 1831|    241|	case SC_CARDCTL_GET_CHANGE_COUNTER:
  ------------------
  |  Branch (1831:2): [True: 241, False: 93]
  ------------------
 1832|    241|		r = myeid_get_change_counter(card, (size_t *)ptr);
 1833|    241|		break;
 1834|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1834:2): [True: 0, False: 334]
  ------------------
 1835|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1835:2): [True: 0, False: 334]
  ------------------
 1836|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1836:2): [True: 0, False: 334]
  ------------------
 1837|      0|		break;
 1838|    334|	}
 1839|    334|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    334|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    334|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    334|	int _ret = r; \
  |  |  |  |  155|    334|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 334, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    334|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    315|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 315, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  157|    334|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    334|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    334|	return _ret; \
  |  |  |  |  163|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|    334|}
card-myeid.c:myeid_get_serialnr:
 1725|     93|{
 1726|     93|	int r;
 1727|     93|	u8  rbuf[256];
 1728|       |
 1729|     93|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     93|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     93|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     93|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     93|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 93]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1730|       |
 1731|       |	/* if number cached, get it
 1732|       |	if(card->serialnr.value) {
 1733|       |		memcpy(serial, &card->serialnr, sizeof(*serial));
 1734|       |		LOG_FUNC_RETURN(card->ctx, r);
 1735|       |	}*/
 1736|       |
 1737|       |	/* get number from card */
 1738|     93|	r = myeid_get_info(card, rbuf, sizeof(rbuf));
 1739|     93|	LOG_TEST_RET(card->ctx, r,  "Get applet info failed");
  ------------------
  |  |  174|     93|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     93|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     93|	int _ret = (r); \
  |  |  |  |  168|     93|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 75, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  169|     75|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     75|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     75|		return _ret; \
  |  |  |  |  172|     75|	} \
  |  |  |  |  173|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1740|       |
 1741|       |	/* cache serial number */
 1742|     18|	memcpy(card->serialnr.value, &rbuf[8], 10);
 1743|     18|	card->serialnr.len = 10;
 1744|       |
 1745|       |	/* copy and return serial number */
 1746|     18|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1747|       |
 1748|     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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1749|     18|}
card-myeid.c:myeid_get_change_counter:
 1753|    241|{
 1754|    241|	int r;
 1755|    241|	u8 rbuf[256];
 1756|       |
 1757|    241|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1758|       |
 1759|       |	/* get change counter from card */
 1760|    241|	r = myeid_get_info(card, rbuf, sizeof(rbuf));
 1761|    241|	LOG_TEST_RET(card->ctx, r, "Get applet info failed");
  ------------------
  |  |  174|    241|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    241|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    241|	int _ret = (r); \
  |  |  |  |  168|    241|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 240, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    240|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    240|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    240|		return _ret; \
  |  |  |  |  172|    240|	} \
  |  |  |  |  173|    241|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1762|       |
 1763|      1|	*change_counter = rbuf[18] * 256 + rbuf[19];
 1764|       |
 1765|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1766|      1|}
card-myeid.c:myeid_pin_cmd:
  667|    108|{
  668|    108|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  669|       |
  670|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  671|       |
  672|    108|	sc_log(card->ctx, "ref (%d), pin1 len(%zu), pin2 len (%zu)\n",
  ------------------
  |  |   71|    108|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  673|    108|			data->pin_reference, data->pin1.len, data->pin2.len);
  674|       |
  675|    108|	if(data->pin1.len > 8 || data->pin2.len > 8)
  ------------------
  |  Branch (675:5): [True: 1, False: 107]
  |  Branch (675:27): [True: 0, False: 107]
  ------------------
  676|    108|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|       |
  678|    107|	data->pin1.pad_length = data->pin2.pad_length = 8;
  679|    107|	data->pin1.pad_char = data->pin2.pad_char = 0xFF;
  680|       |
  681|    107|	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  415|    214|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  240|      7|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (681:6): [True: 7, False: 100]
  |  Branch (681:40): [True: 3, False: 4]
  ------------------
  682|      3|		sc_log(card->ctx, "Card in creation state, no need to verify");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  683|      3|		return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  684|      3|	}
  685|       |
  686|    104|	LOG_FUNC_RETURN(card->ctx, iso_ops->pin_cmd(card, data));
  ------------------
  |  |  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|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|    104|}

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

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

sc_get_oberthur_driver:
 2319|  8.50k|{
 2320|  8.50k|	return sc_get_driver();
 2321|  8.50k|}
card-oberthur.c:sc_get_driver:
 2288|  8.50k|{
 2289|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2289:6): [True: 1, False: 8.49k]
  ------------------
 2290|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2291|       |
 2292|  8.50k|	auth_ops = *iso_ops;
 2293|  8.50k|	auth_ops.match_card = auth_match_card;
 2294|  8.50k|	auth_ops.init = auth_init;
 2295|  8.50k|	auth_ops.finish = auth_finish;
 2296|  8.50k|	auth_ops.select_file = auth_select_file;
 2297|  8.50k|	auth_ops.list_files = auth_list_files;
 2298|  8.50k|	auth_ops.delete_file = auth_delete_file;
 2299|  8.50k|	auth_ops.create_file = auth_create_file;
 2300|  8.50k|	auth_ops.read_binary = auth_read_binary;
 2301|  8.50k|	auth_ops.update_binary = auth_update_binary;
 2302|  8.50k|	auth_ops.read_record = auth_read_record;
 2303|  8.50k|	auth_ops.delete_record = auth_delete_record;
 2304|  8.50k|	auth_ops.card_ctl = auth_card_ctl;
 2305|  8.50k|	auth_ops.set_security_env = auth_set_security_env;
 2306|  8.50k|	auth_ops.restore_security_env = auth_restore_security_env;
 2307|  8.50k|	auth_ops.compute_signature = auth_compute_signature;
 2308|  8.50k|	auth_ops.decipher = auth_decipher;
 2309|  8.50k|	auth_ops.process_fci = auth_process_fci;
 2310|  8.50k|	auth_ops.pin_cmd = auth_pin_cmd;
 2311|  8.50k|	auth_ops.logout = auth_logout;
 2312|  8.50k|	auth_ops.check_sw = auth_check_sw;
 2313|  8.50k|	return &auth_drv;
 2314|  8.50k|}
card-oberthur.c:auth_match_card:
  204|  7.21k|{
  205|  7.21k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 7.21k, False: 0]
  ------------------
  206|  7.21k|		return 0;
  207|      0|	else
  208|      0|		return 1;
  209|  7.21k|}

populate_blobs_to_mf:
  381|    411|{
  382|    411|	pgp_do_info_t	*info;
  383|       |
  384|    411|	if (priv->mf == NULL)
  ------------------
  |  Branch (384:6): [True: 0, False: 411]
  ------------------
  385|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  386|       |
  387|  24.5k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (387:33): [True: 24.5k, False: 0]
  |  Branch (387:51): [True: 24.0k, False: 411]
  ------------------
  388|  24.0k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (388:7): [True: 17.8k, False: 6.29k]
  |  Branch (388:53): [True: 7.74k, False: 10.0k]
  ------------------
  389|  7.74k|			pgp_blob_t *child = NULL;
  390|  7.74k|			sc_file_t *file = sc_file_new();
  391|       |
  392|  7.74k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  393|       |
  394|       |			/* catch out of memory condition */
  395|  7.74k|			if (child == NULL) {
  ------------------
  |  Branch (395:8): [True: 0, False: 7.74k]
  ------------------
  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|  7.74k|		}
  400|  24.0k|	}
  401|    411|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    411|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    411|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    411|	int _ret = r; \
  |  |  |  |  155|    411|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 411, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    411|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 411]
  |  |  |  |  ------------------
  |  |  |  |  157|    411|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    411|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    411|	return _ret; \
  |  |  |  |  163|    411|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    411|}
_pgp_add_algo:
  740|     16|{
  741|     16|	unsigned long flags = 0, ext_flags = 0;
  742|       |
  743|     16|	if (!card || !key_info)
  ------------------
  |  Branch (743:6): [True: 0, False: 16]
  |  Branch (743:15): [True: 0, False: 16]
  ------------------
  744|      0|		return 0;
  745|       |
  746|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  747|     16|	switch (key_info->algorithm) {
  748|     16|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  870|     16|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (748:2): [True: 16, False: 0]
  ------------------
  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|     16|		flags = 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 */
  |  |  ------------------
  ------------------
  752|     16|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  133|     16|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  753|     16|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |   93|     16|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  754|       |
  755|     16|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  756|     16|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  757|     16|				do_num, key_info->u.rsa.modulus_len);
  758|     16|		break;
  759|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  871|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (759:2): [True: 0, False: 16]
  ------------------
  760|       |		/* The montgomery curve (curve25519) needs to go through
  761|       |		 * different paths, otherwise we handle it as a normal EC key */
  762|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (762:7): [True: 0, False: 0]
  ------------------
  763|      0|			break;
  764|       |		/* fall through */
  765|      0|	case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  872|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (765:2): [True: 0, False: 16]
  ------------------
  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|      0|		flags = SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  771|      0|		flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  772|      0|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|      0|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  773|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  774|      0|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|      0|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  775|       |
  776|      0|		_sc_card_add_ec_alg(card, key_info->u.ec.key_length, flags, ext_flags,
  777|      0|			&key_info->u.ec.oid);
  778|      0|		sc_log(card->ctx, "DO %uX: Added EC algorithm (%d), mod_len = %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__
  |  |  ------------------
  ------------------
  779|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  780|      0|		break;
  781|      0|	case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  873|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (781:2): [True: 0, False: 16]
  ------------------
  782|       |		/* EdDSA from draft-ietf-openpgp-rfc4880bis-08 */
  783|       |		/* Handle Yubikey bug, that in DO FA curve25519 has EDDSA algo */
  784|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (784:7): [True: 0, False: 0]
  ------------------
  785|      0|			break;
  786|      0|		_sc_card_add_eddsa_alg(card, key_info->u.ec.key_length,
  787|      0|				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  188|      0|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
              				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  788|       |
  789|      0|		sc_log(card->ctx, "DO %uX: Added EDDSA algorithm (%d), mod_len = %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__
  |  |  ------------------
  ------------------
  790|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  791|      0|		break;
  792|      0|	default:
  ------------------
  |  Branch (792:2): [True: 0, False: 16]
  ------------------
  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|     16|	}
  798|       |	/* return true */
  799|     16|	return 1;
  800|     16|}
sc_get_openpgp_driver:
 4209|  8.50k|{
 4210|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4211|       |
 4212|  8.50k|	iso_ops = iso_drv->ops;
 4213|       |
 4214|  8.50k|	pgp_ops = *iso_ops;
 4215|  8.50k|	pgp_ops.match_card	= pgp_match_card;
 4216|  8.50k|	pgp_ops.init		= pgp_init;
 4217|  8.50k|	pgp_ops.finish		= pgp_finish;
 4218|  8.50k|	pgp_ops.select_file	= pgp_select_file;
 4219|  8.50k|	pgp_ops.list_files	= pgp_list_files;
 4220|  8.50k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4221|  8.50k|	pgp_ops.read_binary	= pgp_read_binary;
 4222|  8.50k|	pgp_ops.write_binary	= NULL;
 4223|  8.50k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4224|  8.50k|	pgp_ops.logout		= pgp_logout;
 4225|  8.50k|	pgp_ops.get_data	= pgp_get_data;
 4226|  8.50k|	pgp_ops.put_data	= pgp_put_data;
 4227|  8.50k|	pgp_ops.set_security_env= pgp_set_security_env;
 4228|  8.50k|	pgp_ops.compute_signature= pgp_compute_signature;
 4229|  8.50k|	pgp_ops.decipher	= pgp_decipher;
 4230|  8.50k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4231|  8.50k|	pgp_ops.delete_file	= pgp_delete_file;
 4232|  8.50k|	pgp_ops.update_binary	= pgp_update_binary;
 4233|  8.50k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4234|       |
 4235|  8.50k|	return &pgp_drv;
 4236|  8.50k|}
card-openpgp.c:pgp_new_blob:
 1240|  34.0k|{
 1241|  34.0k|	pgp_blob_t *blob = NULL;
 1242|       |
 1243|  34.0k|	if (file == NULL)
  ------------------
  |  Branch (1243:6): [True: 0, False: 34.0k]
  ------------------
 1244|      0|		return NULL;
 1245|       |
 1246|  34.0k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1246:6): [True: 34.0k, False: 0]
  ------------------
 1247|  34.0k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  34.0k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1248|  34.0k|		pgp_do_info_t *info;
 1249|       |
 1250|  34.0k|		blob->file = file;
 1251|       |
 1252|  34.0k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  34.0k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1253|  34.0k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  34.0k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1254|  34.0k|		blob->file->id           = file_id;
 1255|       |
 1256|  34.0k|		blob->id     = file_id;
 1257|  34.0k|		blob->parent = parent;
 1258|       |
 1259|  34.0k|		if (parent != NULL) {
  ------------------
  |  Branch (1259:7): [True: 33.6k, False: 411]
  ------------------
 1260|  33.6k|			pgp_blob_t **p;
 1261|       |
 1262|       |			/* set file's path = parent's path + file's id */
 1263|  33.6k|			blob->file->path = parent->file->path;
 1264|  33.6k|			sc_append_file_id(&blob->file->path, file_id);
 1265|       |
 1266|       |			/* append blob to list of parent's children */
 1267|  8.61M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1267:29): [True: 8.58M, False: 33.6k]
  ------------------
 1268|  8.58M|				;
 1269|  33.6k|			*p = blob;
 1270|  33.6k|		}
 1271|    411|		else {
 1272|    411|			char path[10] = "0000";	/* long enough */
 1273|       |
 1274|       |			/* no parent: set file's path = file's id */
 1275|    411|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1275:8): [True: 0, False: 411]
  ------------------
 1276|      0|				free(blob);
 1277|      0|				return NULL;
 1278|      0|			}
 1279|       |
 1280|    411|			sc_format_path(path, &blob->file->path);
 1281|    411|		}
 1282|       |
 1283|       |		/* find matching DO info: set file type depending on it */
 1284|  1.93M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1284:34): [True: 1.93M, False: 0]
  |  Branch (1284:52): [True: 1.91M, False: 24.0k]
  ------------------
 1285|  1.91M|			if (info->id == file_id) {
  ------------------
  |  Branch (1285:8): [True: 10.0k, False: 1.90M]
  ------------------
 1286|  10.0k|				blob->info = info;
 1287|  10.0k|				blob->file->type = blob->info->type;
 1288|  10.0k|				pgp_attach_acl(card, blob->file, info);
 1289|  10.0k|				break;
 1290|  10.0k|			}
 1291|  1.91M|		}
 1292|  34.0k|	}
 1293|       |
 1294|  34.0k|	return blob;
 1295|  34.0k|}
card-openpgp.c:pgp_attach_acl:
 1172|  10.0k|{
 1173|  10.0k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  10.0k|#define SC_AC_NONE			0x00000000
  ------------------
 1174|  10.0k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  10.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1175|       |
 1176|       |	/* Write access */
 1177|  10.0k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1177:10): [True: 10.0k, False: 0]
  ------------------
 1178|  3.90k|	case WRITE_NEVER:
  ------------------
  |  Branch (1178:2): [True: 3.90k, False: 6.16k]
  ------------------
 1179|  3.90k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  3.90k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1180|  3.90k|		break;
 1181|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1181:2): [True: 0, False: 10.0k]
  ------------------
 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|    822|	case WRITE_PIN2:
  ------------------
  |  Branch (1185:2): [True: 822, False: 9.25k]
  ------------------
 1186|    822|		method = SC_AC_CHV;
  ------------------
  |  |  151|    822|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1187|    822|		key_ref = 0x02;
 1188|    822|		break;
 1189|  5.34k|	case WRITE_PIN3:
  ------------------
  |  Branch (1189:2): [True: 5.34k, False: 4.73k]
  ------------------
 1190|  5.34k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  5.34k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1191|  5.34k|		key_ref = 0x03;
 1192|  5.34k|		break;
 1193|  10.0k|	}
 1194|       |
 1195|  10.0k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  20.1k|#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: 10.0k, False: 0]
  |  Branch (1195:30): [True: 0, False: 0]
  ------------------
 1196|  10.0k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  10.0k|#define SC_AC_OP_WRITE			24
  ------------------
 1197|  10.0k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  10.0k|#define SC_AC_OP_UPDATE			23
  ------------------
 1198|  10.0k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  10.0k|#define SC_AC_OP_DELETE			2
  ------------------
 1199|  10.0k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  10.0k|#define SC_AC_OP_CREATE			3
  ------------------
 1200|  10.0k|	}
 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|  10.0k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  10.0k|#define SC_AC_NONE			0x00000000
  ------------------
 1208|  10.0k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  10.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1209|       |	/* Read access */
 1210|  10.0k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1210:10): [True: 1.21k, False: 8.86k]
  ------------------
 1211|    391|	case READ_NEVER:
  ------------------
  |  Branch (1211:2): [True: 391, False: 9.68k]
  ------------------
 1212|    391|		method = SC_AC_NEVER;
  ------------------
  |  |  163|    391|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1213|    391|		break;
 1214|      0|	case READ_PIN1:
  ------------------
  |  Branch (1214:2): [True: 0, False: 10.0k]
  ------------------
 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|    411|	case READ_PIN2:
  ------------------
  |  Branch (1218:2): [True: 411, False: 9.66k]
  ------------------
 1219|    411|		method = SC_AC_CHV;
  ------------------
  |  |  151|    411|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1220|    411|		key_ref = 0x02;
 1221|    411|		break;
 1222|    411|	case READ_PIN3:
  ------------------
  |  Branch (1222:2): [True: 411, False: 9.66k]
  ------------------
 1223|    411|		method = SC_AC_CHV;
  ------------------
  |  |  151|    411|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1224|    411|		key_ref = 0x03;
 1225|    411|		break;
 1226|  10.0k|	}
 1227|       |
 1228|  10.0k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  20.1k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  8.86k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1228:6): [True: 1.21k, False: 8.86k]
  |  Branch (1228:30): [True: 0, False: 8.86k]
  ------------------
 1229|  1.21k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  1.21k|#define SC_AC_OP_READ			22
  ------------------
 1230|  1.21k|	}
 1231|  10.0k|}
card-openpgp.c:pgp_match_card:
  326|  2.56k|{
  327|  2.56k|	int i;
  328|       |
  329|  2.56k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.56k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.56k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.56k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.56k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.56k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  2.56k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  2.56k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 9, False: 2.55k]
  ------------------
  333|      9|		card->name = pgp_atrs[i].name;
  334|      9|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      9|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      9|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      9|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|      9|	}
  336|  2.55k|	else {
  337|  2.55k|		sc_path_t	partial_aid;
  338|  2.55k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  2.55k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  2.55k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.55k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  2.55k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  2.55k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  2.55k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 465, False: 2.09k]
  ------------------
  346|    465|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    465|			card->name = default_cardname;
  348|       |
  349|    465|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 465, False: 0]
  ------------------
  350|    465|				(void) get_full_pgp_aid(card, file);
  351|    465|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 25, False: 440]
  ------------------
  352|     25|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     25|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     25|				switch (major) {
  355|      3|					case 1:
  ------------------
  |  Branch (355:6): [True: 3, False: 22]
  ------------------
  356|      3|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      3|						card->name = default_cardname_v1;
  358|      3|						break;
  359|      7|					case 2:
  ------------------
  |  Branch (359:6): [True: 7, False: 18]
  ------------------
  360|      7|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|      7|						card->name = default_cardname_v2;
  362|      7|						break;
  363|      4|					case 3:
  ------------------
  |  Branch (363:6): [True: 4, False: 21]
  ------------------
  364|      4|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      4|						card->name = default_cardname_v3;
  366|      4|						break;
  367|     11|					default:
  ------------------
  |  Branch (367:6): [True: 11, False: 14]
  ------------------
  368|     11|						break;
  369|     25|				}
  370|     25|			}
  371|    465|			sc_file_free(file);
  372|    465|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    465|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    465|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    465|	int _ret = r; \
  |  |  |  |  155|    465|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 465]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    465|	} else { \
  |  |  |  |  159|    465|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    465|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    465|	} \
  |  |  |  |  162|    465|	return _ret; \
  |  |  |  |  163|    465|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    465|		}
  374|  2.55k|	}
  375|  2.09k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.09k|	int _ret = r; \
  |  |  |  |  155|  2.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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: 2.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.09k|	return _ret; \
  |  |  |  |  163|  2.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.09k|}
card-openpgp.c:get_full_pgp_aid:
  307|    884|{
  308|    884|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    884|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|    884|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 884, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|    884|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|    884|		file->namelen = MAX(r, 0);
  ------------------
  |  |   67|    884|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (67:20): [True: 434, False: 450]
  |  |  ------------------
  ------------------
  314|    884|	}
  315|       |
  316|    884|	return r;
  317|    884|}
card-openpgp.c:pgp_init:
  409|    474|{
  410|    474|	struct pgp_priv_data *priv;
  411|    474|	sc_path_t	path;
  412|    474|	sc_file_t	*file = NULL;
  413|    474|	int		r, i;
  414|       |
  415|    474|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    474|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    474|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    474|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    474|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 474]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |
  417|    474|	priv = calloc (1, sizeof *priv);
  418|    474|	if (!priv)
  ------------------
  |  Branch (418:6): [True: 0, False: 474]
  ------------------
  419|    474|		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|    474|	card->drv_data = priv;
  421|       |
  422|    474|	card->cla = 0x00;
  423|       |
  424|       |	/* select application "OpenPGP" */
  425|    474|	sc_format_path("D276:0001:2401", &path);
  426|    474|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    474|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  427|    474|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (427:6): [True: 55, False: 419]
  ------------------
  428|     55|		sc_file_free(file);
  429|     55|		pgp_finish(card);
  430|     55|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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: 55, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 55, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     55|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     55|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     55|	return _ret; \
  |  |  |  |  163|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|     55|	}
  432|       |
  433|       |	/* defensive programming check */
  434|    419|	if (!file)   {
  ------------------
  |  Branch (434:6): [True: 0, False: 419]
  ------------------
  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|    419|	if (file->namelen != 16) {
  ------------------
  |  Branch (439:6): [True: 419, False: 0]
  ------------------
  440|       |		/* explicitly get the full aid */
  441|    419|		r = get_full_pgp_aid(card, file);
  442|    419|		if (r < 0) {
  ------------------
  |  Branch (442:7): [True: 8, False: 411]
  ------------------
  443|      8|			sc_file_free(file);
  444|      8|			pgp_finish(card);
  445|      8|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      8|		}
  447|    419|	}
  448|       |
  449|       |	/* read information from AID */
  450|    411|	if (file->namelen == 16) {
  ------------------
  |  Branch (450:6): [True: 329, False: 82]
  ------------------
  451|    329|		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|    329|		priv->bcd_version = bebytes2ushort(file->name + 6);
  455|    329|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    329|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  456|    329|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    329|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  457|       |
  458|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  459|    329|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (459:7): [True: 1, False: 328]
  ------------------
  460|    328|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (460:7): [True: 2, False: 326]
  ------------------
  461|    326|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (461:7): [True: 2, False: 324]
  ------------------
  462|      5|			snprintf(card_name, sizeof(card_name),
  463|      5|				 "OpenPGP card v%u.%u (%04X %08lX)",
  464|      5|				 card->version.hw_major, card->version.hw_minor,
  465|      5|				 bebytes2ushort(file->name + 8),
  466|      5|				 bebytes2ulong(file->name + 10));
  467|      5|		}
  468|    324|		else if (card->name != NULL) {
  ------------------
  |  Branch (468:12): [True: 324, False: 0]
  ------------------
  469|       |			/* for other cards, append serial number to the card name */
  470|    324|			snprintf(card_name, sizeof(card_name),
  471|    324|				 "%s (%04X %08lX)",
  472|    324|				 card->name,
  473|    324|				 bebytes2ushort(file->name + 8),
  474|    324|				 bebytes2ulong(file->name + 10));
  475|    324|		}
  476|    329|		card->name = card_name;
  477|       |
  478|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  479|    329|		memcpy(card->serialnr.value, file->name + 8, 6);
  480|    329|		card->serialnr.len = 6;
  481|    329|	} else {
  482|       |		/* set detailed card version */
  483|     82|		switch (card->type) {
  484|      2|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (484:4): [True: 2, False: 80]
  ------------------
  485|      2|				priv->bcd_version = OPENPGP_CARD_3_0;
  486|      2|				break;
  487|      0|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (487:4): [True: 0, False: 82]
  ------------------
  488|      4|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (488:4): [True: 4, False: 78]
  ------------------
  489|      4|				priv->bcd_version = OPENPGP_CARD_2_0;
  490|      4|				break;
  491|     76|			default:
  ------------------
  |  Branch (491:4): [True: 76, False: 6]
  ------------------
  492|     76|				priv->bcd_version = OPENPGP_CARD_1_1;
  493|     76|				break;
  494|     82|		}
  495|     82|	}
  496|       |
  497|       |	/* set pointer to correct list of card objects */
  498|    411|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (498:22): [True: 138, False: 273]
  ------------------
  499|    411|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (499:8): [True: 6, False: 267]
  ------------------
  500|    273|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (500:8): [True: 9, False: 258]
  ------------------
  501|    267|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (501:8): [True: 7, False: 251]
  ------------------
  502|    258|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (502:8): [True: 12, False: 239]
  ------------------
  503|    251|			  :					     pgp34_objects;
  504|       |
  505|       |	/* With gnuk, we use different curves */
  506|    411|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (506:6): [True: 0, False: 411]
  ------------------
  507|      0|		priv->ec_curves = ec_curves_gnuk;
  508|    411|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (508:13): [True: 239, False: 172]
  ------------------
  509|    239|		priv->ec_curves = ec_curves_openpgp34;
  510|    239|	} else {
  511|    172|		priv->ec_curves = ec_curves_openpgp;
  512|    172|	}
  513|       |
  514|       |	/* change file path to MF for reuse in MF */
  515|    411|	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|    411|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  520|    411|	if (!priv->mf) {
  ------------------
  |  Branch (520:6): [True: 0, False: 411]
  ------------------
  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|    411|	priv->current = priv->mf;
  528|       |
  529|    411|	r = populate_blobs_to_mf(card, priv);
  530|    411|	if (r < 0) {
  ------------------
  |  Branch (530:6): [True: 0, False: 411]
  ------------------
  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|    411|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (536:6): [True: 8, False: 403]
  ------------------
  537|      8|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|      8|	}
  539|       |
  540|       |	/* if algorithm attributes can be changed,
  541|       |	 * add supported algorithms based on specification for pkcs15-init */
  542|    403|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (542:6): [True: 0, False: 403]
  ------------------
  543|      0|		unsigned long flags_rsa, flags_ecc, ext_flags;
  544|      0|		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|      0|		flags_rsa = 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 */
  |  |  ------------------
  ------------------
  548|      0|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  549|      0|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|      0|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  551|      0|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  552|      0|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|      0|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  553|      0|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|      0|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|      0|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  555|       |
  556|      0|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  188|      0|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  557|      0|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  558|       |		/* xeddsa may allow signing at some time */
  559|      0|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  173|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  560|      0|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  561|       |
  562|      0|		switch (card->type) {
  563|      0|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (563:4): [True: 0, False: 0]
  ------------------
  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|      0|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (568:4): [True: 0, False: 0]
  ------------------
  569|      0|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  570|      0|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (570:15): [True: 0, False: 0]
  ------------------
  571|      0|				{
  572|      0|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (572:10): [True: 0, False: 0]
  ------------------
  573|      0|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  574|      0|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  575|      0|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (575:15): [True: 0, False: 0]
  ------------------
  576|      0|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  577|      0|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  578|      0|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (578:15): [True: 0, False: 0]
  ------------------
  579|      0|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  580|      0|								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|      0|				}
  584|      0|				break;
  585|      0|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (585:4): [True: 0, False: 0]
  ------------------
  586|      0|			default:
  ------------------
  |  Branch (586:4): [True: 0, False: 0]
  ------------------
  587|      0|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  588|      0|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  589|      0|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  590|      0|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  591|      0|				break;
  592|      0|		}
  593|      0|	}
  594|       |
  595|    403|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    403|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    403|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    403|	int _ret = r; \
  |  |  |  |  155|    403|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 403, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    403|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 403]
  |  |  |  |  ------------------
  |  |  |  |  157|    403|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    403|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    403|	return _ret; \
  |  |  |  |  163|    403|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|    403|}
card-openpgp.c:pgp_get_blob:
 1480|  3.07k|{
 1481|  3.07k|	pgp_blob_t		*child;
 1482|  3.07k|	int			r;
 1483|       |
 1484|  3.07k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1484:6): [True: 801, False: 2.27k]
  ------------------
 1485|    801|		return r;
 1486|       |
 1487|  24.7k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1487:28): [True: 23.7k, False: 912]
  ------------------
 1488|  23.7k|		if (child->id == id) {
  ------------------
  |  Branch (1488:7): [True: 1.36k, False: 22.4k]
  ------------------
 1489|  1.36k|			(void) pgp_read_blob(card, child);
 1490|  1.36k|			*ret = child;
 1491|  1.36k|			return SC_SUCCESS;
  ------------------
  |  |   28|  1.36k|#define SC_SUCCESS				0
  ------------------
 1492|  1.36k|		}
 1493|  23.7k|	}
 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|    912|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  1.82k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|     40|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|     40|#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: 20, False: 892]
  |  Branch (1500:36): [True: 0, False: 20]
  |  Branch (1500:53): [True: 20, False: 0]
  |  Branch (1500:75): [True: 0, False: 0]
  ------------------
 1501|     20|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1502|     20|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1503|     20|		if (child) {
  ------------------
  |  Branch (1503:7): [True: 20, False: 0]
  ------------------
 1504|     20|			pgp_set_blob(child, NULL, 0);
 1505|     20|			*ret = child;
 1506|     20|			return SC_SUCCESS;
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
 1507|     20|		}
 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|     20|			       "Not enough memory to create blob for DO %X",
 1511|     20|			       id);
 1512|     20|	}
 1513|       |
 1514|    892|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    892|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1515|    912|}
card-openpgp.c:pgp_enumerate_blob:
 1398|  3.31k|{
 1399|  3.31k|	const u8	*in;
 1400|  3.31k|	int		r;
 1401|  3.31k|	sc_file_t	*file = NULL;
 1402|       |
 1403|  3.31k|	if (blob->files != NULL)
  ------------------
  |  Branch (1403:6): [True: 2.18k, False: 1.13k]
  ------------------
 1404|  2.18k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.18k|#define SC_SUCCESS				0
  ------------------
 1405|       |
 1406|  1.13k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1406:6): [True: 729, False: 401]
  ------------------
 1407|    729|		return r;
 1408|       |
 1409|    401|	in = blob->data;
 1410|       |
 1411|  26.6k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1411:9): [True: 26.5k, False: 93]
  ------------------
 1412|  26.5k|		unsigned int	cla, tag, tmptag;
 1413|  26.5k|		size_t		len;
 1414|  26.5k|		const u8	*data = in;
 1415|  26.5k|		pgp_blob_t	*new;
 1416|       |
 1417|  26.5k|		if (!in)
  ------------------
  |  Branch (1417:7): [True: 0, False: 26.5k]
  ------------------
 1418|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1419|       |
 1420|  26.5k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1421|  26.5k|					&cla, &tag, &len);
 1422|  26.5k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  26.5k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1422:7): [True: 48, False: 26.5k]
  ------------------
 1423|     48|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1424|     48|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     48|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1425|     48|		}
 1426|       |		/* Check for unknown error, or empty data */
 1427|  26.5k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    162|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1427:8): [True: 162, False: 26.3k]
  |  Branch (1427:19): [True: 0, False: 162]
  ------------------
 1428|  26.5k|		    (data == NULL)) {
  ------------------
  |  Branch (1428:7): [True: 108, False: 26.3k]
  ------------------
 1429|    108|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    108|#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|    108|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    108|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1431|    108|		}
 1432|       |
 1433|       |		/* undo ASN1's split of tag & class */
 1434|  27.5k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1434:22): [True: 1.12k, False: 26.3k]
  ------------------
 1435|  1.12k|			cla <<= 8;
 1436|  1.12k|		}
 1437|  26.3k|		tag |= cla;
 1438|       |		/* Check for length mismatch */
 1439|  26.3k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  26.3k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1439:7): [True: 162, False: 26.2k]
  ------------------
 1440|  26.2k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1440:7): [True: 0, False: 26.2k]
  ------------------
 1441|       |			// Check if it is not known Yubikey 5 issue
 1442|    162|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1442:8): [True: 142, False: 20]
  |  Branch (1442:29): [True: 10, False: 10]
  ------------------
 1443|    152|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    152|#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|    152|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    152|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1445|    152|			}
 1446|    162|		}
 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|  26.2k|		if (tag == blob->id) {
  ------------------
  |  Branch (1451:7): [True: 320, False: 25.9k]
  ------------------
 1452|    320|			in = data;
 1453|    320|			continue;
 1454|    320|		}
 1455|       |
 1456|       |		/* create fake file system hierarchy by
 1457|       |		 * using constructed DOs as DF */
 1458|  25.9k|		file = sc_file_new();
 1459|  25.9k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1459:7): [True: 0, False: 25.9k]
  ------------------
 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|  25.9k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  25.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1463:7): [True: 0, False: 25.9k]
  ------------------
 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|  25.9k|		in = data + len;
 1468|  25.9k|	}
 1469|       |
 1470|     93|	return SC_SUCCESS;
  ------------------
  |  |   28|     93|#define SC_SUCCESS				0
  ------------------
 1471|    401|}
card-openpgp.c:pgp_set_blob:
 1140|  26.3k|{
 1141|  26.3k|	if (blob->data)
  ------------------
  |  Branch (1141:6): [True: 0, False: 26.3k]
  ------------------
 1142|      0|		free(blob->data);
 1143|  26.3k|	blob->data = NULL;
 1144|  26.3k|	blob->len    = 0;
 1145|  26.3k|	blob->status = 0;
 1146|       |
 1147|  26.3k|	if (len > 0) {
  ------------------
  |  Branch (1147:6): [True: 5.91k, False: 20.4k]
  ------------------
 1148|  5.91k|		void *tmp = calloc(1, len);
 1149|       |
 1150|  5.91k|		if (tmp == NULL)
  ------------------
  |  Branch (1150:7): [True: 0, False: 5.91k]
  ------------------
 1151|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|  5.91k|		blob->data = tmp;
 1154|  5.91k|		blob->len  = (unsigned int)len;
 1155|  5.91k|		if (data != NULL)
  ------------------
  |  Branch (1155:7): [True: 5.91k, False: 0]
  ------------------
 1156|  5.91k|			memcpy(blob->data, data, len);
 1157|  5.91k|	}
 1158|       |
 1159|  26.3k|	if (blob->file)
  ------------------
  |  Branch (1159:6): [True: 26.3k, False: 0]
  ------------------
 1160|  26.3k|		blob->file->size = len;
 1161|       |
 1162|  26.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  26.3k|#define SC_SUCCESS				0
  ------------------
 1163|  26.3k|}
card-openpgp.c:pgp_read_blob:
 1348|  2.49k|{
 1349|  2.49k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  2.49k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1350|       |
 1351|  2.49k|	if (blob->data != NULL)
  ------------------
  |  Branch (1351:6): [True: 275, False: 2.21k]
  ------------------
 1352|    275|		return SC_SUCCESS;
  ------------------
  |  |   28|    275|#define SC_SUCCESS				0
  ------------------
 1353|  2.21k|	if (blob->info == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 2.21k]
  ------------------
 1354|      0|		return blob->status;
 1355|       |
 1356|  2.21k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1356:6): [True: 2.17k, False: 38]
  ------------------
 1357|  2.17k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1358|  2.17k|		size_t	buf_len = sizeof(buffer);
 1359|  2.17k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.17k|#define SC_SUCCESS				0
  ------------------
 1360|       |
 1361|       |		/* buffer length for certificate */
 1362|  2.17k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  4.35k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1362:7): [True: 0, False: 2.17k]
  |  Branch (1362:30): [True: 0, False: 0]
  ------------------
 1363|      0|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1364|      0|		}
 1365|       |
 1366|       |		/* buffer length for Gnuk pubkey */
 1367|  2.17k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1367:7): [True: 0, False: 2.17k]
  ------------------
 1368|      0|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|      0|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1368:8): [True: 0, False: 0]
  ------------------
 1369|      0|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|      0|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1369:8): [True: 0, False: 0]
  ------------------
 1370|      0|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|      0|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1370:8): [True: 0, False: 0]
  ------------------
 1371|      0|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|      0|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1371:8): [True: 0, False: 0]
  ------------------
 1372|      0|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|      0|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1372:8): [True: 0, False: 0]
  ------------------
 1373|      0|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|      0|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1373:8): [True: 0, False: 0]
  ------------------
 1374|      0|			buf_len = MIN(MAXLEN_RESP_PUBKEY_GNUK, sizeof(buffer));
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, Folded]
  |  |  ------------------
  ------------------
 1375|      0|		}
 1376|       |
 1377|  2.17k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1378|       |
 1379|  2.17k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1379:7): [True: 1.78k, False: 391]
  ------------------
 1380|  1.78k|			blob->status = r;
 1381|  1.78k|			return r;
 1382|  1.78k|		}
 1383|       |
 1384|    391|		return pgp_set_blob(blob, buffer, r);
 1385|  2.17k|	}
 1386|     38|	else {		/* un-readable DO or part of a constructed DO */
 1387|     38|		return SC_SUCCESS;
  ------------------
  |  |   28|     38|#define SC_SUCCESS				0
  ------------------
 1388|     38|	}
 1389|  2.21k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  634|  1.25k|{
  635|  1.25k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.25k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  636|  1.25k|	struct sc_object_id oid;
  637|  1.25k|	unsigned int j, r;
  638|       |
  639|  1.25k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.25k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.25k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.25k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.25k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |
  641|  1.25k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (641:6): [True: 0, False: 1.25k]
  |  Branch (641:22): [True: 92, False: 1.15k]
  |  Branch (641:44): [True: 0, False: 1.15k]
  ------------------
  642|  1.15k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 1.15k]
  |  Branch (642:27): [True: 0, False: 1.15k]
  |  Branch (642:48): [True: 0, False: 1.15k]
  ------------------
  643|     92|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  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|     92|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 92, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|     92|	}
  645|       |
  646|  1.15k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  647|       |
  648|  1.15k|	switch (blob->data[0]) {
  649|     26|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  870|     26|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (649:3): [True: 26, False: 1.13k]
  ------------------
  650|     26|			if (blob->len < 5) {
  ------------------
  |  Branch (650:8): [True: 10, False: 16]
  ------------------
  651|     10|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|     10|			}
  653|       |
  654|     16|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  870|     16|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  655|     16|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  656|     16|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  657|       |
  658|     16|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (658:32): [True: 15, False: 1]
  ------------------
  659|     16|						  ? blob->data[5]
  660|     16|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  875|     17|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  661|     16|			break;
  662|    814|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  871|    814|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (662:3): [True: 814, False: 344]
  ------------------
  663|    865|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  872|    865|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (663:3): [True: 51, False: 1.10k]
  ------------------
  664|    878|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  873|    878|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (664:3): [True: 13, False: 1.14k]
  ------------------
  665|       |
  666|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  667|    878|			key_info->algorithm = blob->data[0];
  668|       |
  669|       |			/* last byte is set to 0xFF if pubkey import is supported */
  670|    878|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  881|    878|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (670:8): [True: 26, False: 852]
  ------------------
  671|     26|				if (blob->len < 3)
  ------------------
  |  Branch (671:9): [True: 1, False: 25]
  ------------------
  672|      1|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      1|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  673|     25|				key_info->u.ec.oidv_len = blob->len - 2;
  674|     25|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  881|     25|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  675|     25|			}
  676|    852|			else {
  677|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  678|       |				 * it is not part of OID */
  679|    852|				if (blob->len < 2)
  ------------------
  |  Branch (679:9): [True: 53, False: 799]
  ------------------
  680|     53|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|     53|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  681|    799|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  880|    799|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (681:9): [True: 202, False: 597]
  ------------------
  682|    202|					key_info->u.ec.oidv_len = blob->len - 2;
  683|    597|				else
  684|    597|					key_info->u.ec.oidv_len = blob->len - 1;
  685|    799|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  880|    799|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  686|    799|			}
  687|       |
  688|       |			/* Create copy of oid from blob */
  689|    824|			sc_init_oid(&oid);
  690|    824|			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|    824|			if (r > 0){
  ------------------
  |  Branch (693:8): [True: 234, False: 590]
  ------------------
  694|    234|				return r;
  695|    234|			}
  696|       |			/* compare with list of supported ec_curves */
  697|  8.26k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (697:16): [True: 7.67k, False: 590]
  ------------------
  698|  7.67k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (698:9): [True: 0, False: 7.67k]
  ------------------
  699|      0|					sc_log(card->ctx, "Matched EC oid %s (%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__
  |  |  ------------------
  ------------------
  700|      0|						sc_dump_oid(&oid), j);
  701|      0|					key_info->u.ec.oid = priv->ec_curves[j].oid;
  702|      0|					key_info->u.ec.key_length = priv->ec_curves[j].size;
  703|      0|					break;
  704|      0|				}
  705|  7.67k|			}
  706|       |			/* We did not match the OID */
  707|    590|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (707:8): [True: 590, False: 0]
  ------------------
  708|    590|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    590|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    590|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    590|	int _ret = r; \
  |  |  |  |  155|    590|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 590, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    590|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    590|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 590, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    590|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    590|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    590|	return _ret; \
  |  |  |  |  163|    590|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|    590|			}
  710|      0|			break;
  711|    254|		default:
  ------------------
  |  Branch (711:3): [True: 254, False: 904]
  ------------------
  712|    254|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    254|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    254|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    254|	int _ret = r; \
  |  |  |  |  155|    254|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 254, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    254|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 254, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    254|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    254|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    254|	return _ret; \
  |  |  |  |  163|    254|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|  1.15k|	}
  714|       |
  715|     16|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|     16|}
card-openpgp.c:pgp_get_card_features:
  909|    411|{
  910|    411|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    411|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  911|    411|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  912|    411|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  913|    411|	unsigned int i;
  914|    411|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  915|    411|	int handled_algos = 0;
  916|       |
  917|    411|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    411|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    411|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    411|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    411|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 411]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  918|       |
  919|       |	/* parse card capabilities from historical bytes in ATR */
  920|    411|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (920:6): [True: 46, False: 365]
  ------------------
  921|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  922|     46|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (922:11): [True: 43, False: 3]
  ------------------
  923|     26|			case 0x00:
  ------------------
  |  Branch (923:4): [True: 26, False: 20]
  ------------------
  924|     26|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (924:9): [True: 15, False: 11]
  ------------------
  925|     15|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  926|     15|				}
  927|     26|				break;
  928|     14|			case 0x80:
  ------------------
  |  Branch (928:4): [True: 14, False: 32]
  ------------------
  929|     14|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (929:9): [True: 13, False: 1]
  ------------------
  930|     13|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  931|     13|				}
  932|     14|				break;
  933|      3|			case 0x10:
  ------------------
  |  Branch (933:4): [True: 3, False: 43]
  ------------------
  934|      3|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (934:9): [True: 2, False: 1]
  ------------------
  935|      2|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  936|      2|				}
  937|      3|				break;
  938|     46|		}
  939|     46|	}
  940|       |
  941|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  942|    411|	priv->ext_caps &= ~EXT_CAP_LCS;
  943|       |
  944|    411|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (944:6): [True: 273, False: 138]
  ------------------
  945|       |		/* get card capabilities from "historical bytes" DO */
  946|    273|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (946:7): [True: 273, False: 0]
  ------------------
  947|    273|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (947:7): [True: 37, False: 236]
  |  Branch (947:31): [True: 32, False: 5]
  ------------------
  948|       |
  949|     32|			if (blob->len > 4) {
  ------------------
  |  Branch (949:8): [True: 29, False: 3]
  ------------------
  950|     29|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  951|     29|			}
  952|       |
  953|       |			/* get card status from historical bytes status indicator */
  954|     32|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (954:8): [True: 32, False: 0]
  |  Branch (954:35): [True: 31, False: 1]
  ------------------
  955|     31|				priv->state = blob->data[blob->len-3];
  956|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  957|     31|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (957:9): [True: 22, False: 9]
  ------------------
  958|     22|					priv->ext_caps |= EXT_CAP_LCS;
  959|     31|			}
  960|     32|		}
  961|    273|	}
  962|       |
  963|    411|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (963:6): [True: 252, False: 159]
  ------------------
  964|    252|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    252|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  965|    252|	}
  966|       |
  967|    411|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (967:6): [True: 239, False: 172]
  ------------------
  968|       |		/* Parse supported algorithms from Algorithm Information DO
  969|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  970|    239|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (970:7): [True: 239, False: 0]
  ------------------
  971|    239|			pgp_blob_t *child;
  972|    239|			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|  22.1k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (975:32): [True: 21.9k, False: 239]
  ------------------
  976|  21.9k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (976:9): [True: 18.6k, False: 3.32k]
  |  Branch (976:33): [True: 2.07k, False: 1.25k]
  ------------------
  977|  20.6k|					continue;
  978|  1.25k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  979|  1.25k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (979:9): [True: 16, False: 1.23k]
  ------------------
  980|     16|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  981|  1.25k|			}
  982|    239|		}
  983|    239|	}
  984|       |
  985|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  986|    411|	priv->max_specialDO_size = 254;
  987|       |
  988|    411|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (988:6): [True: 411, False: 0]
  ------------------
  989|    411|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (989:6): [True: 13, False: 398]
  ------------------
  990|       |
  991|       |		/* get "extended capabilities" DO */
  992|     13|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (992:7): [True: 0, False: 13]
  ------------------
  993|      0|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (993:7): [True: 0, False: 0]
  |  Branch (993:31): [True: 0, False: 0]
  ------------------
  994|      0|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (994:8): [True: 0, False: 0]
  |  Branch (994:34): [True: 0, False: 0]
  ------------------
  995|      0|				priv->ext_caps |= EXT_CAP_KDF_DO;
  996|      0|			}
  997|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  998|      0|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (998:8): [True: 0, False: 0]
  ------------------
  999|      0|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (999:6): [True: 0, False: 0]
  ------------------
 1000|      0|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
 1001|       |			/* bit 0x08 in first byte means "support for private use DOs" */
 1002|      0|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (1002:8): [True: 0, False: 0]
  ------------------
 1003|      0|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1004|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1005|      0|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1005:8): [True: 0, False: 0]
  ------------------
 1006|      0|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1007|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1008|      0|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1008:8): [True: 0, False: 0]
  ------------------
 1009|      0|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1010|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1011|      0|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1011:8): [True: 0, False: 0]
  ------------------
 1012|      0|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|      0|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1013|      0|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1014|      0|			}
 1015|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1016|      0|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1016:8): [True: 0, False: 0]
  ------------------
 1017|      0|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1017:6): [True: 0, False: 0]
  ------------------
 1018|      0|				priv->ext_caps |= EXT_CAP_SM;
 1019|       |
 1020|      0|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1020:8): [True: 0, False: 0]
  |  Branch (1020:51): [True: 0, False: 0]
  ------------------
 1021|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1022|      0|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1023|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1024|      0|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1025|       |
 1026|      0|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1026:9): [True: 0, False: 0]
  ------------------
 1027|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1028|      0|					priv->sm_algo = blob->data[1];
 1029|      0|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1029:10): [True: 0, False: 0]
  |  Branch (1029:45): [True: 0, False: 0]
  ------------------
 1030|      0|						priv->sm_algo = SM_ALGO_3DES;
 1031|       |
 1032|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1033|      0|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1034|      0|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1035|      0|				}
 1036|      0|				else {
 1037|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1038|      0|					priv->sm_algo = blob->data[1];
 1039|      0|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1039:10): [True: 0, False: 0]
  |  Branch (1039:45): [True: 0, False: 0]
  ------------------
 1040|      0|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1041|       |
 1042|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1043|      0|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1044|      0|				}
 1045|      0|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1045:9): [True: 0, False: 0]
  |  Branch (1045:50): [True: 0, False: 0]
  ------------------
 1046|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1047|      0|					if (blob->data[9])
  ------------------
  |  Branch (1047:10): [True: 0, False: 0]
  ------------------
 1048|      0|						priv->ext_caps |= EXT_CAP_MSE;
 1049|      0|				}
 1050|      0|			}
 1051|      0|		}
 1052|       |
 1053|       |		/* get max. PIN length from "CHV status bytes" DO */
 1054|     13|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1054:7): [True: 0, False: 13]
  ------------------
 1055|      0|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1055:4): [True: 0, False: 0]
  |  Branch (1055:28): [True: 0, False: 0]
  ------------------
 1056|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1057|      0|			card->max_pin_len = blob->data[1];
 1058|      0|		}
 1059|       |
 1060|     13|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1060:7): [True: 5, False: 8]
  ------------------
 1061|       |			/* v3.0+: get length info from "extended length information" DO */
 1062|      5|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1062:8): [True: 0, False: 5]
  ------------------
 1063|      0|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1063:5): [True: 0, False: 0]
  |  Branch (1063:29): [True: 0, False: 0]
  ------------------
 1064|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1065|      0|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1066|      0|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1067|      0|			}
 1068|      5|		}
 1069|       |
 1070|     13|#ifdef ENABLE_OPENSSL
 1071|     13|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1071:7): [True: 0, False: 13]
  ------------------
 1072|      0|			int r = pgp_decode_kdf_do(card, priv);
 1073|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1073:8): [True: 0, False: 0]
  ------------------
 1074|      0|				sc_log(card->ctx, "Failed to decode KDF DO: %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__
  |  |  ------------------
  ------------------
 1075|      0|			}
 1076|      0|		}
 1077|     13|#endif /* ENABLE_OPENSSL */
 1078|       |
 1079|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1080|     13|		if (handled_algos) {
  ------------------
  |  Branch (1080:7): [True: 0, False: 13]
  ------------------
 1081|      0|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1082|      0|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1083|      0|		}
 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|     52|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1091:20): [True: 39, False: 13]
  ------------------
 1092|     39|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1093|       |
 1094|     39|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , 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__
  |  |  ------------------
  ------------------
 1095|       |
 1096|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1097|     39|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1097:8): [True: 0, False: 39]
  ------------------
 1098|      0|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1098:8): [True: 0, False: 0]
  ------------------
 1099|      0|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1099:9): [True: 0, False: 0]
  ------------------
 1100|      0|					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|      0|			}
 1102|     39|		}
 1103|       |
 1104|     13|	}
 1105|       |
 1106|    411|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    411|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    411|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    411|	int _ret = r; \
  |  |  |  |  155|    411|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 403, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  156|    403|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 403]
  |  |  |  |  ------------------
  |  |  |  |  157|    403|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    403|	} else { \
  |  |  |  |  159|      8|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      8|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      8|	} \
  |  |  |  |  162|    411|	return _ret; \
  |  |  |  |  163|    411|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|    411|}
card-openpgp.c:pgp_parse_hist_bytes:
  604|     59|{
  605|     59|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     59|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  606|     59|	const u8 *ptr;
  607|       |
  608|       |	/* IS07816-4 hist bytes: 3rd function table */
  609|     59|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (609:6): [True: 20, False: 39]
  ------------------
  610|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  611|     20|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (611:7): [True: 13, False: 7]
  ------------------
  612|     13|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     13|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  613|     13|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  614|     13|		}
  615|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  616|     20|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (616:7): [True: 8, False: 12]
  ------------------
  617|      8|			priv->ext_caps |= EXT_CAP_CHAINING;
  618|      8|		}
  619|     20|	}
  620|       |
  621|     59|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (621:6): [True: 50, False: 9]
  ------------------
  622|     50|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (622:6): [True: 16, False: 34]
  ------------------
  623|       |		// ToDo ...
  624|     16|	}
  625|     59|}
card-openpgp.c:pgp_finish:
 1115|    474|{
 1116|    474|	if (card != NULL) {
  ------------------
  |  Branch (1116:6): [True: 474, False: 0]
  ------------------
 1117|    474|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    474|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1118|       |
 1119|    474|		if (priv != NULL) {
  ------------------
  |  Branch (1119:7): [True: 474, False: 0]
  ------------------
 1120|       |			/* delete fake file hierarchy */
 1121|    474|			pgp_free_blobs(priv->mf);
 1122|       |
 1123|       |			/* delete kdf do related data if exists */
 1124|    474|			free(priv->pin_kdf_info);
 1125|       |
 1126|       |			/* delete private data */
 1127|    474|			free(priv);
 1128|    474|		}
 1129|    474|		card->drv_data = NULL;
 1130|    474|	}
 1131|    474|	return SC_SUCCESS;
  ------------------
  |  |   28|    474|#define SC_SUCCESS				0
  ------------------
 1132|    474|}
card-openpgp.c:pgp_free_blobs:
 1328|  34.1k|{
 1329|  34.1k|	if (blob) {
  ------------------
  |  Branch (1329:6): [True: 34.0k, False: 63]
  ------------------
 1330|  34.0k|		pgp_blob_t *child = blob->files;
 1331|       |
 1332|  67.7k|		while (child != NULL) {
  ------------------
  |  Branch (1332:10): [True: 33.6k, False: 34.0k]
  ------------------
 1333|  33.6k|			pgp_blob_t *next = child->next;
 1334|       |
 1335|  33.6k|			pgp_free_blobs(child);
 1336|  33.6k|			child = next;
 1337|  33.6k|		}
 1338|  34.0k|		pgp_free_blob(blob);
 1339|  34.0k|	}
 1340|  34.1k|}
card-openpgp.c:pgp_free_blob:
 1303|  34.0k|{
 1304|  34.0k|	if (blob) {
  ------------------
  |  Branch (1304:6): [True: 34.0k, False: 0]
  ------------------
 1305|  34.0k|		if (blob->parent) {
  ------------------
  |  Branch (1305:7): [True: 33.6k, False: 411]
  ------------------
 1306|  33.6k|			pgp_blob_t **p;
 1307|       |
 1308|       |			/* remove blob from list of parent's children */
 1309|  33.6k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1309:35): [True: 33.6k, False: 0]
  |  Branch (1309:49): [True: 0, False: 33.6k]
  ------------------
 1310|      0|				;
 1311|  33.6k|			if (*p == blob)
  ------------------
  |  Branch (1311:8): [True: 33.6k, False: 0]
  ------------------
 1312|  33.6k|				*p = blob->next;
 1313|  33.6k|		}
 1314|       |
 1315|  34.0k|		sc_file_free(blob->file);
 1316|  34.0k|		if (blob->data)
  ------------------
  |  Branch (1316:7): [True: 5.91k, False: 28.1k]
  ------------------
 1317|  5.91k|			free(blob->data);
 1318|  34.0k|		free(blob);
 1319|  34.0k|	}
 1320|  34.0k|}
card-openpgp.c:pgp_select_file:
 1614|  2.44k|{
 1615|  2.44k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  2.44k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1616|  2.44k|	pgp_blob_t	*blob;
 1617|  2.44k|	unsigned int	path_start = 0;
 1618|  2.44k|	unsigned int	n;
 1619|  2.44k|	sc_path_t dummy_path;
 1620|       |
 1621|  2.44k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.44k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.44k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.44k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  2.44k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  2.44k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1623:6): [True: 805, False: 1.64k]
  ------------------
 1624|  2.44k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  164|    805|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    805|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    805|	int _ret = r; \
  |  |  |  |  155|    805|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 805, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    805|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 42]
  |  |  |  |  ------------------
  |  |  |  |  157|    805|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    805|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    805|	return _ret; \
  |  |  |  |  163|    805|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|       |
 1626|  1.64k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1626:6): [True: 0, False: 1.64k]
  |  Branch (1626:23): [True: 0, False: 1.64k]
  ------------------
 1627|  1.64k|		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|  1.64k|				"invalid path length");
 1629|       |
 1630|  1.64k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  3.28k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1630:6): [True: 0, False: 1.64k]
  |  Branch (1630:44): [True: 0, False: 0]
  ------------------
 1631|  1.64k|		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|  1.64k|				"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|  1.64k|	sc_format_path("11001101", &dummy_path);
 1641|  1.64k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1641:6): [True: 0, False: 1.64k]
  ------------------
 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|  1.64k|	path_start = pgp_strip_path(card, path);
 1653|       |
 1654|       |	/* starting with the MF ... */
 1655|  1.64k|	blob = priv->mf;
 1656|       |	/* ... recurse through the tree following the path */
 1657|  2.08k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1657:23): [True: 1.67k, False: 416]
  ------------------
 1658|  1.67k|		unsigned int	id = bebytes2ushort(path->value + n);
 1659|  1.67k|		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|  1.67k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1663:7): [True: 0, False: 1.67k]
  |  Branch (1663:23): [True: 0, False: 1.67k]
  ------------------
 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|  1.67k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1674:7): [True: 1.22k, False: 445]
  ------------------
 1675|  1.22k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.22k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.22k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.22k|	int _ret = r; \
  |  |  |  |  155|  1.22k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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.22k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.22k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.22k|	return _ret; \
  |  |  |  |  163|  1.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1676|  1.22k|		}
 1677|  1.67k|	}
 1678|       |
 1679|       |	/* success: select file = set "current" pointer to blob found */
 1680|    416|	priv->current = blob;
 1681|       |
 1682|    416|	if (ret)
  ------------------
  |  Branch (1682:6): [True: 20, False: 396]
  ------------------
 1683|     20|		sc_file_dup(ret, blob->file);
 1684|       |
 1685|    416|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    416|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    416|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    416|	int _ret = r; \
  |  |  |  |  155|    416|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 416]
  |  |  |  |  ------------------
  |  |  |  |  157|    416|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    416|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    416|	return _ret; \
  |  |  |  |  163|    416|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1686|    416|}
card-openpgp.c:pgp_strip_path:
 1595|  1.64k|{
 1596|  1.64k|	unsigned int start_point = 0;
 1597|       |	/* start_point will move through the path string */
 1598|  1.64k|	if (path->len == 0)
  ------------------
  |  Branch (1598:6): [True: 0, False: 1.64k]
  ------------------
 1599|      0|		return 0;
 1600|       |
 1601|       |	/* ignore 3F00 (MF) at the beginning */
 1602|  1.64k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1602:16): [True: 1.19k, False: 449]
  ------------------
 1603|       |	/* strip path of PKCS15-App DF (5015) */
 1604|  1.64k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1604:17): [True: 792, False: 849]
  ------------------
 1605|  1.64k|	return start_point;
 1606|  1.64k|}
card-openpgp.c:pgp_pin_cmd:
 2388|     30|{
 2389|     30|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|     30|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2390|     30|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2391|       |
 2392|     30|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     30|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2393|       |
 2394|     30|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|     30|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2394:6): [True: 0, False: 30]
  ------------------
 2395|     30|		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|     30|				"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|     30|	data->pin_reference |= 0x80;
 2423|       |
 2424|       |	/* check version-dependent constraints */
 2425|     30|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|     60|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|     29|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2425:6): [True: 1, False: 29]
  |  Branch (2425:40): [True: 0, False: 29]
  ------------------
 2426|      1|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2426:7): [True: 1, False: 0]
  ------------------
 2427|      1|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2427:8): [True: 1, False: 0]
  ------------------
 2428|      1|				data->pin_reference = 0x81;
 2429|       |
 2430|      1|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|      1|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2430:8): [True: 1, False: 0]
  ------------------
 2431|      1|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2431:9): [True: 0, False: 1]
  ------------------
 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|      1|					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|      1|							"v2 cards don't support implicit old PIN for PIN change");
 2435|       |
 2436|      1|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      1|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2437|      1|			}
 2438|      1|		} 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|      1|	}
 2450|       |
 2451|     30|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  417|     60|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2451:6): [True: 0, False: 30]
  |  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|     30|		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|     30|				"new PIN must be provided for unblock operation");
 2455|       |
 2456|       |	/* ensure pin_reference is 81, 82, 83 */
 2457|     30|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2457:6): [True: 6, False: 24]
  |  Branch (2457:36): [True: 0, False: 24]
  ------------------
 2458|     30|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|     24|				"Invalid key ID; must be 1, 2, or 3");
 2460|       |
 2461|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2462|     24|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  418|     48|#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|     21|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2462:6): [True: 21, False: 3]
  |  Branch (2462:42): [True: 10, False: 11]
  ------------------
 2463|     10|		u8 c4data[10];
 2464|     10|		int r;
 2465|       |
 2466|     10|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2467|     10|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes 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: 6, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2468|       |
 2469|      4|		if (r != 7)
  ------------------
  |  Branch (2469:7): [True: 2, False: 2]
  ------------------
 2470|      4|			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|      2|				"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|      2|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2478:7): [True: 1, False: 1]
  |  Branch (2478:48): [True: 1, False: 0]
  ------------------
 2479|      1|			data->pin_reference = 0x81;
 2480|       |
 2481|      2|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2482|      2|		data->pin1.max_tries = 3;
 2483|      2|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      2|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2484|       |
 2485|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2486|      2|	}
 2487|       |
 2488|     14|#ifdef ENABLE_OPENSSL
 2489|     14|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2489:6): [True: 0, False: 14]
  ------------------
 2490|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2491|      0|	}
 2492|     14|#endif /* ENABLE_OPENSSL */
 2493|       |
 2494|     14|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, 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|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|     14|}
card-openpgp.c:pgp_get_data:
 1994|  3.07k|{
 1995|  3.07k|	sc_apdu_t	apdu;
 1996|  3.07k|	int		r;
 1997|       |
 1998|  3.07k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.07k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.07k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1999|       |
 2000|  3.07k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  3.07k|#define SC_APDU_CASE_2			0x22
  ------------------
 2001|  3.07k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  547|  2.17k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2001:13): [True: 2.17k, False: 894]
  |  Branch (2001:33): [True: 2.12k, False: 58]
  ------------------
 2002|  3.07k|	apdu.resp = buf;
 2003|  3.07k|	apdu.resplen = buf_len;
 2004|       |
 2005|  3.07k|	r = sc_transmit_apdu(card, &apdu);
 2006|  3.07k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  3.07k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.07k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.07k|	int _ret = (r); \
  |  |  |  |  168|  3.07k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 289, False: 2.78k]
  |  |  |  |  ------------------
  |  |  |  |  169|    289|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    289|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    289|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    289|		return _ret; \
  |  |  |  |  172|    289|	} \
  |  |  |  |  173|  3.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2007|       |
 2008|  2.78k|	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|  2.78k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2012:6): [True: 0, False: 2.78k]
  ------------------
 2013|      0|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|      0|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2013:7): [True: 0, False: 0]
  ------------------
 2014|      0|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|      0|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2014:7): [True: 0, False: 0]
  ------------------
 2015|      0|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|      0|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2015:7): [True: 0, False: 0]
  ------------------
 2016|      0|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|      0|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2016:7): [True: 0, False: 0]
  ------------------
 2017|      0|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|      0|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2017:7): [True: 0, False: 0]
  ------------------
 2018|      0|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2018:7): [True: 0, False: 0]
  ------------------
 2019|      0|			r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2020|      0|			apdu.resplen = 0;
 2021|      0|		}
 2022|      0|	}
 2023|  2.78k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  2.78k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.78k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.78k|	int _ret = (r); \
  |  |  |  |  168|  2.78k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.94k, False: 836]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.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|  1.94k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.94k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.94k|		return _ret; \
  |  |  |  |  172|  1.94k|	} \
  |  |  |  |  173|  2.78k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 836]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2024|       |
 2025|    836|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    836|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    836|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    836|	int _ret = r; \
  |  |  |  |  155|    836|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 50, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  156|     50|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  157|     50|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    786|	} else { \
  |  |  |  |  159|    786|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    786|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    786|	} \
  |  |  |  |  162|    836|	return _ret; \
  |  |  |  |  163|    836|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|    836|}
card-openpgp.c:pgp_card_ctl:
 4009|     15|{
 4010|     15|	int r;
 4011|       |
 4012|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4013|       |
 4014|     15|	switch(cmd) {
  ------------------
  |  Branch (4014:9): [True: 15, False: 0]
  ------------------
 4015|     15|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4015:2): [True: 15, False: 0]
  ------------------
 4016|     15|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4017|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4018|      0|		break;
 4019|      0|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4019:2): [True: 0, False: 15]
  ------------------
 4020|      0|		r = pgp_select_data(card, *((u8 *) ptr));
 4021|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4022|      0|		break;
 4023|      0|#ifdef ENABLE_OPENSSL
 4024|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4024:2): [True: 0, False: 15]
  ------------------
 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: 15]
  ------------------
 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: 15]
  ------------------
 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|     15|	}
 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_card_reader_lock_obtained:
 4169|  5.70k|{
 4170|  5.70k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  5.70k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4171|  5.70k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  5.70k|#define SC_SUCCESS				0
  ------------------
 4172|       |
 4173|  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]
  |  |  ------------------
  ------------------
 4174|       |
 4175|  5.70k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  537|  11.4k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4175:6): [True: 0, False: 5.70k]
  ------------------
 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|  5.70k|	if (was_reset > 0) {
  ------------------
  |  Branch (4190:6): [True: 0, False: 5.70k]
  ------------------
 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|  5.70k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  5.70k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.70k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.70k|	int _ret = r; \
  |  |  |  |  155|  5.70k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.70k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.70k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.70k|	} else { \
  |  |  |  |  159|      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.70k|	return _ret; \
  |  |  |  |  163|  5.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4201|  5.70k|}

sc_get_piv_driver:
 6570|  8.50k|{
 6571|  8.50k|	return sc_get_driver();
 6572|  8.50k|}
card-piv.c:sc_get_driver:
 6543|  8.50k|{
 6544|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6545|       |
 6546|  8.50k|	piv_ops = *iso_drv->ops;
 6547|  8.50k|	piv_ops.match_card = piv_match_card;
 6548|  8.50k|	piv_ops.init = piv_init;
 6549|  8.50k|	piv_ops.finish = piv_finish;
 6550|       |
 6551|  8.50k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6552|  8.50k|	piv_ops.get_challenge = piv_get_challenge;
 6553|  8.50k|	piv_ops.logout = piv_logout;
 6554|  8.50k|	piv_ops.read_binary = piv_read_binary;
 6555|  8.50k|	piv_ops.write_binary = piv_write_binary;
 6556|  8.50k|	piv_ops.set_security_env = piv_set_security_env;
 6557|  8.50k|	piv_ops.restore_security_env = piv_restore_security_env;
 6558|  8.50k|	piv_ops.compute_signature = piv_compute_signature;
 6559|  8.50k|	piv_ops.decipher = piv_decipher;
 6560|  8.50k|	piv_ops.check_sw = piv_check_sw;
 6561|  8.50k|	piv_ops.card_ctl = piv_card_ctl;
 6562|  8.50k|	piv_ops.pin_cmd = piv_pin_cmd;
 6563|  8.50k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6564|       |
 6565|  8.50k|	return &piv_drv;
 6566|  8.50k|}
card-piv.c:piv_match_card:
 5508|  4.36k|{
 5509|  4.36k|	int r = 0;
 5510|       |
 5511|  4.36k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  4.36k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5512|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5513|       |	/* user provided card type must be one we know */
 5514|  4.36k|	switch (card->type) {
 5515|  4.36k|	case -1:
  ------------------
  |  Branch (5515:2): [True: 4.36k, False: 0]
  ------------------
 5516|  4.36k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5516:2): [True: 0, False: 4.36k]
  ------------------
 5517|  4.36k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5517:2): [True: 0, False: 4.36k]
  ------------------
 5518|  4.36k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5518:2): [True: 0, False: 4.36k]
  ------------------
 5519|  4.36k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5519:2): [True: 0, False: 4.36k]
  ------------------
 5520|  4.36k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5520:2): [True: 0, False: 4.36k]
  ------------------
 5521|  4.36k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5521:2): [True: 0, False: 4.36k]
  ------------------
 5522|  4.36k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5522:2): [True: 0, False: 4.36k]
  ------------------
 5523|  4.36k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5523:2): [True: 0, False: 4.36k]
  ------------------
 5524|  4.36k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5524:2): [True: 0, False: 4.36k]
  ------------------
 5525|  4.36k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5525:2): [True: 0, False: 4.36k]
  ------------------
 5526|  4.36k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5526:2): [True: 0, False: 4.36k]
  ------------------
 5527|  4.36k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5527:2): [True: 0, False: 4.36k]
  ------------------
 5528|  4.36k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5528:2): [True: 0, False: 4.36k]
  ------------------
 5529|  4.36k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5529:2): [True: 0, False: 4.36k]
  ------------------
 5530|  4.36k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5530:2): [True: 0, False: 4.36k]
  ------------------
 5531|  4.36k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5531:2): [True: 0, False: 4.36k]
  ------------------
 5532|  4.36k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5532:2): [True: 0, False: 4.36k]
  ------------------
 5533|  4.36k|		break;
 5534|      0|	default:
  ------------------
  |  Branch (5534:2): [True: 0, False: 4.36k]
  ------------------
 5535|      0|		return 0; /* can not handle the card */
 5536|  4.36k|	}
 5537|       |
 5538|  4.36k|	r = sc_lock(card);
 5539|  4.36k|	if (r < 0)
  ------------------
  |  Branch (5539:6): [True: 0, False: 4.36k]
  ------------------
 5540|      0|		return 0;
 5541|       |	/* its one we know, or we can test for it in piv_init */
 5542|  4.36k|	r = piv_match_card_continued(card);
 5543|  4.36k|	sc_unlock(card);
 5544|       |
 5545|  4.36k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5545:6): [True: 3.27k, False: 1.09k]
  |  Branch (5545:15): [True: 0, False: 1.09k]
  ------------------
 5546|       |		/* clean up what we left in card */
 5547|  3.27k|		piv_finish(card);
 5548|  3.27k|		return 0; /* match failed */
 5549|  3.27k|	}
 5550|       |
 5551|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5552|  1.09k|	return 1; /* matched */
 5553|  4.36k|}
card-piv.c:piv_match_card_continued:
 5557|  4.36k|{
 5558|  4.36k|	int i, r = 0, r2 = 0;
 5559|  4.36k|	int type = -1;
 5560|  4.36k|	piv_private_data_t *priv = NULL;
 5561|  4.36k|	int saved_type = card->type;
 5562|  4.36k|	sc_apdu_t apdu;
 5563|  4.36k|	u8 yubico_version_buf[3] = {0};
 5564|       |
 5565|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5566|       |	/* User provided card type must be one we know */
 5567|       |
 5568|  4.36k|	switch (card->type) {
 5569|  4.36k|	case -1:
  ------------------
  |  Branch (5569:2): [True: 4.36k, False: 0]
  ------------------
 5570|  4.36k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5570:2): [True: 0, False: 4.36k]
  ------------------
 5571|  4.36k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5571:2): [True: 0, False: 4.36k]
  ------------------
 5572|  4.36k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5572:2): [True: 0, False: 4.36k]
  ------------------
 5573|  4.36k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5573:2): [True: 0, False: 4.36k]
  ------------------
 5574|  4.36k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5574:2): [True: 0, False: 4.36k]
  ------------------
 5575|  4.36k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5575:2): [True: 0, False: 4.36k]
  ------------------
 5576|  4.36k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5576:2): [True: 0, False: 4.36k]
  ------------------
 5577|  4.36k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5577:2): [True: 0, False: 4.36k]
  ------------------
 5578|  4.36k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5578:2): [True: 0, False: 4.36k]
  ------------------
 5579|  4.36k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5579:2): [True: 0, False: 4.36k]
  ------------------
 5580|  4.36k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5580:2): [True: 0, False: 4.36k]
  ------------------
 5581|  4.36k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5581:2): [True: 0, False: 4.36k]
  ------------------
 5582|  4.36k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5582:2): [True: 0, False: 4.36k]
  ------------------
 5583|  4.36k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5583:2): [True: 0, False: 4.36k]
  ------------------
 5584|  4.36k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5584:2): [True: 0, False: 4.36k]
  ------------------
 5585|  4.36k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5585:2): [True: 0, False: 4.36k]
  ------------------
 5586|  4.36k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5586:2): [True: 0, False: 4.36k]
  ------------------
 5587|  4.36k|		type = card->type;
 5588|  4.36k|		break;
 5589|      0|	default:
  ------------------
  |  Branch (5589:2): [True: 0, False: 4.36k]
  ------------------
 5590|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5591|  4.36k|	}
 5592|  4.36k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  4.36k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5593|  4.36k|	if (type == -1) {
  ------------------
  |  Branch (5593:6): [True: 4.36k, False: 0]
  ------------------
 5594|       |		/*
 5595|       |		 * Try to identify card by ATR or historical data in ATR
 5596|       |		 * currently all PIV card will respond to piv_find_aid
 5597|       |		 * the same. But in future may need to know card type first,
 5598|       |		 * so do it here.
 5599|       |		 */
 5600|       |
 5601|  4.36k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5601:7): [True: 2.05k, False: 2.30k]
  ------------------
 5602|  2.05k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5602:8): [True: 26, False: 2.03k]
  ------------------
 5603|     26|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5603:6): [True: 1, False: 25]
  ------------------
 5604|      1|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5605|  2.05k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5605:15): [True: 1.82k, False: 236]
  ------------------
 5606|  1.82k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5606:6): [True: 469, False: 1.35k]
  ------------------
 5607|    469|				type = SC_CARD_TYPE_PIV_II_NEO;
 5608|  1.58k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5608:15): [True: 1.36k, False: 220]
  ------------------
 5609|  1.36k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5609:6): [True: 54, False: 1.31k]
  ------------------
 5610|     54|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5611|  1.53k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5611:15): [True: 1.31k, False: 220]
  ------------------
 5612|  1.31k|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5612:6): [True: 84, False: 1.23k]
  ------------------
 5613|     84|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5614|     84|			}
 5615|       |			/* look for TLV historic data */
 5616|  1.45k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5616:13): [True: 1.41k, False: 34]
  ------------------
 5617|  1.41k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5617:6): [True: 662, False: 755]
  ------------------
 5618|    662|				size_t datalen;
 5619|    662|				const u8 *data;
 5620|       |
 5621|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5622|    662|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5622:9): [True: 548, False: 114]
  ------------------
 5623|    662|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5624|    548|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5624:10): [True: 24, False: 524]
  |  Branch (5624:26): [True: 9, False: 15]
  ------------------
 5625|      9|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5626|    539|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5626:17): [True: 519, False: 20]
  |  Branch (5626:33): [True: 487, False: 32]
  ------------------
 5627|    487|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5628|    487|					}
 5629|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5630|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5631|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5632|       |					 * will look at only 6 bytes that do match
 5633|       |					 */
 5634|     52|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5634:15): [True: 32, False: 20]
  |  Branch (5634:31): [True: 11, False: 21]
  ------------------
 5635|     11|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5636|     11|					}
 5637|    548|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5637:16): [True: 16, False: 98]
  ------------------
 5638|    114|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5639|     16|					int k;
 5640|       |
 5641|     47|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5641:18): [True: 32, False: 15]
  ------------------
 5642|     32|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5642:11): [True: 26, False: 6]
  ------------------
 5643|     26|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5643:9): [True: 1, False: 25]
  ------------------
 5644|      1|							type = SC_CARD_TYPE_PIV_II_HIST;
 5645|      1|							break;
 5646|      1|						}
 5647|     32|					}
 5648|     16|				}
 5649|    662|			}
 5650|  2.05k|		}
 5651|       |
 5652|  4.36k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  4.36k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5653|       |
 5654|  4.36k|		if (type == -1) {
  ------------------
  |  Branch (5654:7): [True: 3.25k, False: 1.11k]
  ------------------
 5655|       |			/* use known ATRs  which changes the type */
 5656|  3.25k|			i = _sc_match_atr(card, piv_atrs, &type);
 5657|  3.25k|			if (i < 0)
  ------------------
  |  Branch (5657:8): [True: 3.22k, False: 26]
  ------------------
 5658|  3.22k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5659|  3.25k|		}
 5660|  4.36k|	}
 5661|       |
 5662|  4.36k|	card->type = type;
 5663|       |
 5664|       |	/* we either found via ATR historic bytes or ATR directly */
 5665|  4.36k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  4.36k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5666|       |
 5667|       |	/* allocate and init basic fields */
 5668|  4.36k|	priv = calloc(1, sizeof(piv_private_data_t));
 5669|       |
 5670|  4.36k|	if (!priv)
  ------------------
  |  Branch (5670:6): [True: 0, False: 4.36k]
  ------------------
 5671|  4.36k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5672|       |
 5673|  4.36k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5674|       |	/*
 5675|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5676|       |	 * If for some reason future cards have larger objects, this value needs to
 5677|       |	 * be increased here.
 5678|       |	 */
 5679|  4.36k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  4.36k|#define MAX_FILE_SIZE 65535
  ------------------
 5680|  4.36k|	priv->selected_obj = -1;
 5681|  4.36k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5682|  4.36k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  4.36k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5683|  4.36k|	priv->pstate = PIV_STATE_MATCH;
 5684|       |
 5685|       |#ifdef ENABLE_PIV_SM
 5686|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5687|       |	card->sm_ctx.ops.open = piv_sm_open;
 5688|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5689|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5690|       |	card->sm_ctx.ops.close = piv_sm_close;
 5691|       |#endif /* ENABLE_PIV_SM */
 5692|       |
 5693|       |	/* See if contactless  or run as virtual card */
 5694|       |	/* PivApplet in .github/test_piv.sh for example */
 5695|  4.36k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5695:6): [True: 2.19k, False: 2.17k]
  ------------------
 5696|  2.19k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5696:4): [True: 2.07k, False: 120]
  ------------------
 5697|  2.07k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5697:4): [True: 234, False: 1.84k]
  ------------------
 5698|    234|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5698:4): [True: 198, False: 36]
  ------------------
 5699|    198|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5699:4): [True: 181, False: 17]
  ------------------
 5700|    181|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|    181|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5701|    181|	}
 5702|       |
 5703|   266k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5703:14): [True: 261k, False: 4.36k]
  ------------------
 5704|   261k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  646|   261k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5704:7): [True: 87.3k, False: 174k]
  ------------------
 5705|  87.3k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|  91.6k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5706|       |	/*
 5707|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5708|       |	 * and PIV must be the default application.
 5709|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5710|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5711|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5712|       |	 *
 5713|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5714|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5715|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5716|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5717|       |	 */
 5718|       |
 5719|       |	/*
 5720|       |	 * if ATR matched or user forced card type
 5721|       |	 * test if PIV is active applet without using AID If fails try AID
 5722|       |	 */
 5723|       |
 5724|  4.36k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5724:6): [True: 1.14k, False: 3.22k]
  ------------------
 5725|  1.14k|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|  1.14k|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5725:4): [True: 1.14k, False: 2]
  ------------------
 5726|  1.14k|		r = piv_find_discovery(card);
 5727|  1.14k|		if (r < 0) {
  ------------------
  |  Branch (5727:7): [True: 542, False: 598]
  ------------------
 5728|    542|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5729|    542|			r = piv_find_aid(card);
 5730|    542|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    542|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    542|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    542|	int _ret = (r); \
  |  |  |  |  178|    542|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 134, False: 408]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    134|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    134|		goto err; \
  |  |  |  |  182|    134|	} \
  |  |  |  |  183|    542|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 408]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5731|    542|		}
 5732|  3.22k|	} else {
 5733|       |		/* piv_find_aid saves al_label from response */
 5734|  3.22k|		r = piv_find_aid(card);
 5735|  3.22k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  3.22k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  3.22k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  3.22k|	int _ret = (r); \
  |  |  |  |  178|  3.22k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.13k, False: 89]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.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|  3.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.13k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.13k|		goto err; \
  |  |  |  |  182|  3.13k|	} \
  |  |  |  |  183|  3.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 89]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5736|  3.22k|	}
 5737|       |
 5738|       |	/* Know to be PIV card but not the type */
 5739|       |
 5740|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5741|  1.09k|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5741:6): [True: 6, False: 1.08k]
  |  Branch (5741:24): [True: 5, False: 1]
  ------------------
 5742|      5|		switch (card->type) {
  ------------------
  |  Branch (5742:11): [True: 4, False: 1]
  ------------------
 5743|      4|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5743:3): [True: 4, False: 1]
  ------------------
 5744|      4|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5744:3): [True: 0, False: 5]
  ------------------
 5745|      8|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5745:16): [True: 4, False: 4]
  ------------------
 5746|      4|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5746:9): [True: 2, False: 2]
  ------------------
 5747|      2|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5747:7): [True: 0, False: 2]
  ------------------
 5748|      0|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_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__
  |  |  ------------------
  ------------------
 5749|      0|					card->type = al_map[i].al_type;
 5750|      0|					break;
 5751|      0|				}
 5752|      4|			}
 5753|      4|			break;
 5754|      5|		}
 5755|      5|	}
 5756|       |
 5757|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5758|  1.09k|			card->type, priv->card_issues, r, priv->alg_ids);
 5759|       |
 5760|       |	/*
 5761|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5762|       |	 * via ATR, ATR Historic bytes or Application Label
 5763|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5764|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5765|       |	 */
 5766|  1.09k|	switch (card->type) {
  ------------------
  |  Branch (5766:10): [True: 1.03k, False: 60]
  ------------------
 5767|    389|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5767:2): [True: 389, False: 706]
  ------------------
 5768|    867|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5768:2): [True: 478, False: 617]
  ------------------
 5769|    875|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5769:2): [True: 8, False: 1.08k]
  ------------------
 5770|    946|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5770:2): [True: 71, False: 1.02k]
  ------------------
 5771|    946|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5771:2): [True: 0, False: 1.09k]
  ------------------
 5772|    946|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5772:2): [True: 0, False: 1.09k]
  ------------------
 5773|  1.03k|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5773:2): [True: 89, False: 1.00k]
  ------------------
 5774|  1.03k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|  1.03k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5775|  1.03k|		apdu.lc = 0;
 5776|  1.03k|		apdu.data = NULL;
 5777|  1.03k|		apdu.datalen = 0;
 5778|  1.03k|		apdu.resp = yubico_version_buf;
 5779|  1.03k|		apdu.resplen = sizeof(yubico_version_buf);
 5780|  1.03k|		apdu.le = apdu.resplen;
 5781|  1.03k|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5782|  1.03k|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  2.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5782:7): [True: 1.03k, False: 4]
  |  Branch (5782:27): [True: 824, False: 207]
  ------------------
 5783|    824|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5784|    824|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    824|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5785|    824|		}
 5786|  1.03k|		break;
 5787|  1.09k|	}
 5788|       |
 5789|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5790|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5791|       |
 5792|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5793|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5794|  1.09k|	switch (card->type) {
  ------------------
  |  Branch (5794:10): [True: 114, False: 981]
  ------------------
 5795|       |	/*
 5796|       |	 * For cards that may also be CAC, try and read the CCC
 5797|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5798|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5799|       |	 */
 5800|     89|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5800:2): [True: 89, False: 1.00k]
  ------------------
 5801|     89|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5801:2): [True: 0, False: 1.09k]
  ------------------
 5802|     89|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5802:2): [True: 0, False: 1.09k]
  ------------------
 5803|     89|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5803:2): [True: 0, False: 1.09k]
  ------------------
 5804|    114|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5804:2): [True: 25, False: 1.07k]
  ------------------
 5805|    114|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5805:2): [True: 0, False: 1.09k]
  ------------------
 5806|    114|		r2 = piv_process_ccc(card);
 5807|    114|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    114|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5808|    114|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5809|       |		/* Ignore any error. */
 5810|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5811|    114|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    114|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5811:7): [True: 0, False: 114]
  ------------------
 5812|      0|			switch (card->type) {
  ------------------
  |  Branch (5812:12): [True: 0, False: 0]
  ------------------
 5813|      0|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5813:4): [True: 0, False: 0]
  ------------------
 5814|      0|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5814:4): [True: 0, False: 0]
  ------------------
 5815|      0|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5815:4): [True: 0, False: 0]
  ------------------
 5816|      0|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5816:4): [True: 0, False: 0]
  ------------------
 5817|      0|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5818|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5819|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5820|      0|				break;
 5821|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5821:4): [True: 0, False: 0]
  ------------------
 5822|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5823|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5824|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5825|      0|				break;
 5826|      0|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5826:4): [True: 0, False: 0]
  ------------------
 5827|      0|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5828|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5829|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5830|      0|				break;
 5831|      0|			}
 5832|      0|		}
 5833|    114|		break;
 5834|       |
 5835|    114|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5835:2): [True: 0, False: 1.09k]
  ------------------
 5836|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5836:2): [True: 0, False: 1.09k]
  ------------------
 5837|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5837:2): [True: 0, False: 1.09k]
  ------------------
 5838|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5839|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5840|      0|		break;
 5841|  1.09k|	}
 5842|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5843|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5844|       |
 5845|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5846|  1.09k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  380|  1.09k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  385|    598|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5846:6): [True: 598, False: 497]
  |  Branch (5846:51): [True: 0, False: 598]
  ------------------
 5847|      0|		r2 = piv_find_aid(card);
 5848|      0|	}
 5849|       |
 5850|       |	/* Read AID if needed for these cards types */
 5851|  1.09k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|  1.09k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5851:6): [True: 598, False: 497]
  ------------------
 5852|    598|		switch (card->type) {
  ------------------
  |  Branch (5852:11): [True: 71, False: 527]
  ------------------
 5853|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5853:3): [True: 0, False: 598]
  ------------------
 5854|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5854:3): [True: 0, False: 598]
  ------------------
 5855|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5855:3): [True: 0, False: 598]
  ------------------
 5856|      2|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5856:3): [True: 2, False: 596]
  ------------------
 5857|     71|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5857:3): [True: 69, False: 529]
  ------------------
 5858|     71|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5858:3): [True: 0, False: 598]
  ------------------
 5859|     71|			r2 = piv_find_aid(card);
 5860|    598|		}
 5861|    598|	}
 5862|       |
 5863|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5864|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5865|       |
 5866|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5867|  1.09k|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  609|  1.09k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|  1.09k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|  1.09k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|  1.09k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|  1.09k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|  1.09k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5867:6): [True: 1.09k, False: 0]
  ------------------
 5868|  1.09k|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  609|  1.09k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|  1.09k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|  1.09k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|  1.09k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|  1.09k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|  1.09k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5869|  1.09k|	}
 5870|       |
 5871|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5872|  1.09k|	switch (card->type) {
  ------------------
  |  Branch (5872:10): [True: 89, False: 1.00k]
  ------------------
 5873|     89|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5873:2): [True: 89, False: 1.00k]
  ------------------
 5874|     89|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5874:2): [True: 0, False: 1.09k]
  ------------------
 5875|     89|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|     89|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5875:7): [True: 0, False: 89]
  ------------------
 5876|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5877|      0|		}
 5878|       |
 5879|       |#ifdef ENABLE_PIV_SM
 5880|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 5881|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 5882|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5883|       |		}
 5884|       |#endif
 5885|     89|		break;
 5886|  1.09k|	}
 5887|       |
 5888|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5889|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5890|       |
 5891|       |	/*
 5892|       |	 * Set card_issues flags based card->type and version numbers if available.
 5893|       |	 *
 5894|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 5895|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 5896|       |	 * access to all the different devices or versions of the devices.
 5897|       |	 * Vendor and user input is welcome on any compliance issues.
 5898|       |	 *
 5899|       |	 * For the Yubico devices The assumption is also made that if a bug is
 5900|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 5901|       |	 *
 5902|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 5903|       |	 * may be set earlier or later then in the following code.
 5904|       |	 */
 5905|       |
 5906|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5907|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5908|  1.09k|	switch (card->type) {
 5909|    389|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5909:2): [True: 389, False: 706]
  ------------------
 5910|    389|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  596|    389|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5911|    389|				     CI_VERIFY_630X |
  ------------------
  |  |  584|    389|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5912|    389|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|    389|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5913|    389|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  589|    389|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5914|    389|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  594|    389|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5915|    389|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5915:7): [True: 324, False: 65]
  ------------------
 5916|    324|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  585|    324|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5917|    389|		break;
 5918|       |
 5919|    478|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5919:2): [True: 478, False: 617]
  ------------------
 5920|    478|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5920:2): [True: 0, False: 1.09k]
  ------------------
 5921|    549|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5921:2): [True: 71, False: 1.02k]
  ------------------
 5922|    549|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|    549|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5923|    549|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  589|    549|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5924|    549|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5924:7): [True: 102, False: 447]
  ------------------
 5925|    102|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  585|    102|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5926|    549|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5926:7): [True: 437, False: 112]
  ------------------
 5927|    437|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  603|    437|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  606|    437|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  607|    437|#define AI_X25519			    0x00200000U
  ------------------
 5928|    549|		break;
 5929|       |
 5930|      8|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5930:2): [True: 8, False: 1.08k]
  ------------------
 5931|      8|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      8|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5932|      8|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5932:7): [True: 5, False: 3]
  ------------------
 5933|      5|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  603|      5|#define AI_RSA_4096			    0x00000008U
  ------------------
 5934|      8|		break;
 5935|       |
 5936|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5936:2): [True: 0, False: 1.09k]
  ------------------
 5937|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5937:2): [True: 0, False: 1.09k]
  ------------------
 5938|     25|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5938:2): [True: 25, False: 1.07k]
  ------------------
 5939|     25|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5939:2): [True: 0, False: 1.09k]
  ------------------
 5940|     25|		priv->card_issues |= 0; /* could add others here */
 5941|     25|		break;
 5942|       |
 5943|     89|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5943:2): [True: 89, False: 1.00k]
  ------------------
 5944|     89|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5944:2): [True: 0, False: 1.09k]
  ------------------
 5945|     89|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5945:2): [True: 0, False: 1.09k]
  ------------------
 5946|     89|		priv->card_issues |= 0; /* could add others here */
 5947|     89|		break;
 5948|       |
 5949|      0|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5949:2): [True: 0, False: 1.09k]
  ------------------
 5950|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5950:2): [True: 0, False: 1.09k]
  ------------------
 5951|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5951:2): [True: 0, False: 1.09k]
  ------------------
 5952|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5953|      0|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  591|      0|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5954|      0|				     CI_NO_RANDOM |
  ------------------
  |  |  587|      0|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5955|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5956|      0|		break;
 5957|       |
 5958|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5958:2): [True: 0, False: 1.09k]
  ------------------
 5959|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5960|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5961|      0|		break;
 5962|       |
 5963|     35|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5963:2): [True: 35, False: 1.06k]
  ------------------
 5964|     35|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|     35|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5965|     35|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  591|     35|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5966|     35|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  587|     35|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5967|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 5968|     35|		break;
 5969|       |
 5970|      0|	default:
  ------------------
  |  Branch (5970:2): [True: 0, False: 1.09k]
  ------------------
 5971|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5972|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5973|       |		/* opensc.conf may have it wrong, continue anyway */
 5974|      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__
  |  |  ------------------
  ------------------
 5975|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 5976|  1.09k|	}
 5977|  1.09k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5978|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5979|       |
 5980|  1.09k|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  590|  1.09k|#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|  1.09k|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5980:6): [True: 1.09k, False: 0]
  |  Branch (5980:53): [True: 497, False: 598]
  ------------------
 5981|       |		/*
 5982|       |		 * We now know PIV AID is active, test DISCOVERY object again
 5983|       |		 * Some PIV don't support DISCOVERY and return
 5984|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 5985|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 5986|       |		 * to test for active AID.
 5987|       |		 */
 5988|    497|		r2 = piv_find_discovery(card);
 5989|       |
 5990|    497|		if (r2 < 0) {
  ------------------
  |  Branch (5990:7): [True: 317, False: 180]
  ------------------
 5991|    317|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|    317|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5992|    317|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    317|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5993|    317|		}
 5994|    497|	}
 5995|       |
 5996|  1.09k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5997|  1.09k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5998|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5999|  1.09k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.09k|	int _ret = r; \
  |  |  |  |  155|  1.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.09k|	return _ret; \
  |  |  |  |  163|  1.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6000|       |
 6001|  3.27k|err:
 6002|  3.27k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH failed card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  3.27k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6003|  3.27k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6004|       |	/* don't match. Does not have a PIV applet. */
 6005|  3.27k|	piv_finish(card);
 6006|  3.27k|	card->type = saved_type;
 6007|  3.27k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.27k|	int _ret = r; \
  |  |  |  |  155|  3.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.27k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.27k|	return _ret; \
  |  |  |  |  163|  3.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6008|  3.27k|}
card-piv.c:piv_find_discovery:
 5158|  10.2k|{
 5159|  10.2k|	int r = 0;
 5160|  10.2k|	size_t rbuflen;
 5161|  10.2k|	u8 *rbuf = NULL;
 5162|  10.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  10.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5163|       |
 5164|  10.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  ------------------
  ------------------
 5165|       |
 5166|       |	/*
 5167|       |	 * During piv_card_reader_lock_obtained,
 5168|       |	 * we use the discovery object to test if card present, and
 5169|       |	 * if PIV AID is active.
 5170|       |	 */
 5171|  10.2k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  10.2k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5171:6): [True: 0, False: 10.2k]
  ------------------
 5172|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5173|      0|		goto end;
 5174|      0|	}
 5175|       |
 5176|       |	/* If not valid: read, test,  cache */
 5177|  10.2k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|  10.2k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5177:6): [True: 1.63k, False: 8.63k]
  ------------------
 5178|  1.63k|		r = piv_process_discovery(card);
 5179|  8.63k|	} else {
 5180|       |		/* if already in cache,force read */
 5181|  8.63k|		rbuflen = 1;
 5182|  8.63k|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5183|       |		/* if same response as last, no need to parse */
 5184|  8.63k|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5184:7): [True: 0, False: 8.63k]
  |  Branch (5184:17): [True: 0, False: 0]
  ------------------
 5185|      0|			goto end;
 5186|       |
 5187|  8.63k|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5187:7): [True: 206, False: 8.43k]
  |  Branch (5187:17): [True: 182, False: 24]
  ------------------
 5188|    182|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5188:5): [True: 182, False: 0]
  ------------------
 5189|    182|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5189:5): [True: 112, False: 70]
  ------------------
 5190|    112|			goto end;
 5191|    112|		}
 5192|       |		/* This should not happen  bad card */
 5193|  8.52k|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
 5194|  8.52k|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  8.52k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5195|  8.52k|		goto end;
 5196|  8.63k|	}
 5197|       |
 5198|  10.2k|end:
 5199|  10.2k|	free(rbuf);
 5200|  10.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  10.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.2k|	int _ret = r; \
  |  |  |  |  155|  10.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.1k, False: 112]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.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|  9.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.38k, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.1k|	} else { \
  |  |  |  |  159|    112|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    112|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    112|	} \
  |  |  |  |  162|  10.2k|	return _ret; \
  |  |  |  |  163|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5201|  10.2k|}
card-piv.c:piv_process_discovery:
 5051|  1.63k|{
 5052|  1.63k|	int r;
 5053|  1.63k|	u8 *rbuf = NULL;
 5054|  1.63k|	size_t rbuflen = 0;
 5055|       |
 5056|  1.63k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5057|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5058|  1.63k|	if (r < 0)
  ------------------
  |  Branch (5058:6): [True: 774, False: 863]
  ------------------
 5059|    774|		goto err;
 5060|       |
 5061|       |	/* the object is now cached, see what we have */
 5062|    863|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5063|       |
 5064|  1.63k|err:
 5065|  1.63k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.63k|	int _ret = r; \
  |  |  |  |  155|  1.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    859|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 859, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.63k|	} else { \
  |  |  |  |  159|      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.63k|	return _ret; \
  |  |  |  |  163|  1.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|  1.63k|}
card-piv.c:piv_get_cached_data:
 3201|  19.2k|{
 3202|       |
 3203|  19.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  19.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3204|  19.2k|	int r;
 3205|  19.2k|	u8 *rbuf = NULL;
 3206|  19.2k|	size_t rbuflen;
 3207|       |
 3208|  19.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  19.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  19.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  19.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 19.2k]
  |  |  ------------------
  ------------------
 3209|       |
 3210|  19.2k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3210:6): [True: 0, False: 19.2k]
  |  Branch (3210:21): [True: 0, False: 19.2k]
  ------------------
 3211|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3212|       |
 3213|  19.2k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  19.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__
  |  |  ------------------
  ------------------
 3214|       |
 3215|       |	/* see if we have it cached */
 3216|  19.2k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  19.2k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3216:6): [True: 3.22k, False: 16.0k]
  ------------------
 3217|       |
 3218|  3.22k|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
 3219|  3.22k|				enumtag,
 3220|  3.22k|				priv->obj_cache[enumtag].obj_data,
 3221|  3.22k|				priv->obj_cache[enumtag].obj_len,
 3222|  3.22k|				priv->obj_cache[enumtag].internal_obj_data,
 3223|  3.22k|				priv->obj_cache[enumtag].internal_obj_len);
 3224|       |
 3225|  3.22k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3225:7): [True: 832, False: 2.39k]
  ------------------
 3226|    832|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    832|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3227|    832|			sc_log(card->ctx, "#%d found but len=0", enumtag);
  ------------------
  |  |   71|    832|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3228|    832|			goto err;
 3229|    832|		}
 3230|  2.39k|		*buf = priv->obj_cache[enumtag].obj_data;
 3231|  2.39k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3232|  2.39k|		r = (int)*buf_len;
 3233|  2.39k|		goto ok;
 3234|  3.22k|	}
 3235|       |
 3236|       |	/*
 3237|       |	 * If we know it can not be on the card  i.e. History object
 3238|       |	 * has been read, and we know what other certs may or
 3239|       |	 * may not be on the card. We can avoid extra overhead
 3240|       |	 * Also used if object on card was not parsable
 3241|       |	 */
 3242|       |
 3243|  16.0k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  16.0k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3243:6): [True: 0, False: 16.0k]
  ------------------
 3244|      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__
  |  |  ------------------
  ------------------
 3245|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3246|      0|		goto err;
 3247|      0|	}
 3248|       |
 3249|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3250|  16.0k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 3251|  16.0k|	rbuflen = 1;
 3252|  16.0k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3253|  16.0k|	if (r > 0) {
  ------------------
  |  Branch (3253:6): [True: 1.86k, False: 14.1k]
  ------------------
 3254|  1.86k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.86k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3255|  1.86k|		priv->obj_cache[enumtag].obj_len = r;
 3256|  1.86k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3257|  1.86k|		*buf = rbuf;
 3258|  1.86k|		*buf_len = r;
 3259|       |
 3260|  1.86k|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|  1.86k|#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|  1.86k|				enumtag,
 3262|  1.86k|				priv->obj_cache[enumtag].obj_data,
 3263|  1.86k|				priv->obj_cache[enumtag].obj_len,
 3264|  1.86k|				priv->obj_cache[enumtag].internal_obj_data,
 3265|  1.86k|				priv->obj_cache[enumtag].internal_obj_len);
 3266|       |
 3267|  14.1k|	} else {
 3268|  14.1k|		free(rbuf);
 3269|  14.1k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  14.1k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3269:7): [True: 0, False: 14.1k]
  |  Branch (3269:17): [True: 1.29k, False: 12.8k]
  ------------------
 3270|  1.29k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.29k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3271|  1.29k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.29k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3272|  1.29k|			priv->obj_cache[enumtag].obj_len = 0;
 3273|  12.8k|		} else {
 3274|  12.8k|			goto err;
 3275|  12.8k|		}
 3276|  14.1k|	}
 3277|  5.55k|ok:
 3278|       |
 3279|  19.2k|err:
 3280|  19.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  19.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  19.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  19.2k|	int _ret = r; \
  |  |  |  |  155|  19.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.9k, False: 4.25k]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.9k|	} else { \
  |  |  |  |  159|  4.25k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  4.25k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  4.25k|	} \
  |  |  |  |  162|  19.2k|	return _ret; \
  |  |  |  |  163|  19.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3281|  19.2k|}
card-piv.c:piv_parse_discovery:
 4995|    863|{
 4996|    863|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    863|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4997|    863|	int r = 0;
 4998|    863|	const u8 *body;
 4999|    863|	size_t bodylen;
 5000|    863|	const u8 *aid;
 5001|    863|	size_t aidlen;
 5002|    863|	const u8 *pinp;
 5003|    863|	size_t pinplen;
 5004|    863|	unsigned int cla_out, tag_out;
 5005|       |
 5006|    863|	if (rbuflen != 0) {
  ------------------
  |  Branch (5006:6): [True: 863, False: 0]
  ------------------
 5007|    863|		body = rbuf;
 5008|    863|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|  1.72k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5008:7): [True: 0, False: 863]
  ------------------
 5009|    863|				body == NULL ||
  ------------------
  |  Branch (5009:5): [True: 0, False: 863]
  ------------------
 5010|    863|				bodylen == 0 ||
  ------------------
  |  Branch (5010:5): [True: 5, False: 858]
  ------------------
 5011|    858|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5011:5): [True: 0, False: 858]
  ------------------
 5012|      5|			sc_log(card->ctx, "DER problem %d", 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__
  |  |  ------------------
  ------------------
 5013|      5|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5014|      5|			goto err;
 5015|      5|		}
 5016|       |
 5017|    858|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   71|    858|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5018|    858|				cla_out, tag_out, body, bodylen);
 5019|    858|		aidlen = 0;
 5020|    858|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5021|    858|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5021:7): [True: 8, False: 850]
  |  Branch (5021:22): [True: 2, False: 848]
  ------------------
 5022|    848|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5022:5): [True: 70, False: 778]
  ------------------
 5023|     80|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5024|     80|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     80|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 5025|     80|			goto err;
 5026|     80|		}
 5027|    778|		if (aid_only == 0) {
  ------------------
  |  Branch (5027:7): [True: 778, False: 0]
  ------------------
 5028|    778|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5029|    778|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5029:8): [True: 344, False: 434]
  |  Branch (5029:16): [True: 338, False: 6]
  ------------------
 5030|    338|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|    338|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5031|    338|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5032|    338|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   71|    338|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5033|    338|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    338|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    338|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    338|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    338|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5033:9): [True: 46, False: 292]
  ------------------
 5034|     46|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|     46|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5034:7): [True: 43, False: 3]
  ------------------
 5035|     43|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5036|     43|					priv->pin_preference = 0x00;
 5037|     43|				}
 5038|    338|			}
 5039|    778|		}
 5040|    778|		r = SC_SUCCESS;
  ------------------
  |  |   28|    778|#define SC_SUCCESS				0
  ------------------
 5041|    778|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|    778|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5042|    778|	}
 5043|       |
 5044|    863|err:
 5045|    863|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    863|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    863|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    863|	int _ret = r; \
  |  |  |  |  155|    863|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 863, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    863|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     85|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 85, False: 778]
  |  |  |  |  ------------------
  |  |  |  |  157|    863|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    863|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    863|	return _ret; \
  |  |  |  |  163|    863|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5046|    863|}
card-piv.c:piv_get_data:
 3091|  24.7k|{
 3092|  24.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  24.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3093|  24.7k|	u8 *p;
 3094|  24.7k|	u8 *tbuf;
 3095|  24.7k|	int r = 0;
 3096|  24.7k|	u8 tagbuf[8];
 3097|  24.7k|	size_t tag_len;
 3098|  24.7k|	int alloc_buf = 0;
 3099|       |
 3100|  24.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  24.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  24.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  24.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24.7k]
  |  |  ------------------
  ------------------
 3101|       |
 3102|  24.7k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  24.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__
  |  |  ------------------
  ------------------
 3103|       |
 3104|  24.7k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3105|  24.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  24.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3105:6): [True: 0, False: 24.7k]
  ------------------
 3106|      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__
  |  |  ------------------
  ------------------
 3107|      0|		return r;
 3108|      0|	}
 3109|       |
 3110|  24.7k|	tag_len = piv_objects[enumtag].tag_len;
 3111|       |
 3112|  24.7k|	p = tagbuf;
 3113|  24.7k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3114|  24.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  24.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3114:6): [True: 0, False: 24.7k]
  ------------------
 3115|      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__
  |  |  ------------------
  ------------------
 3116|      0|		goto err;
 3117|      0|	}
 3118|       |
 3119|  24.7k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3119:6): [True: 24.6k, False: 51]
  |  Branch (3119:23): [True: 24.6k, False: 0]
  ------------------
 3120|  24.6k|		*buf_len = priv->max_object_size; /* will allocate below */
 3121|  24.6k|		alloc_buf = 1;
 3122|  24.6k|	}
 3123|       |
 3124|  24.7k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  24.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__
  |  |  ------------------
  ------------------
 3125|  24.7k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3125:6): [True: 24.6k, False: 51]
  |  Branch (3125:22): [True: 24.6k, False: 0]
  ------------------
 3126|  24.6k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  24.6k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3126:7): [True: 0, False: 24.6k]
  ------------------
 3127|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3128|      0|			goto err;
 3129|      0|		}
 3130|  24.6k|		*buf = malloc(*buf_len);
 3131|  24.6k|		if (*buf == NULL) {
  ------------------
  |  Branch (3131:7): [True: 0, False: 24.6k]
  ------------------
 3132|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3133|      0|			goto err;
 3134|      0|		}
 3135|  24.6k|	}
 3136|       |
 3137|       |#ifdef ENABLE_PIV_SM
 3138|       |	/*
 3139|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3140|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3141|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3142|       |	 * i.e. no interference from other applications
 3143|       |	 */
 3144|       |	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",
 3145|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3146|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3147|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3148|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3149|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3150|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3151|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3152|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3153|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3154|       |	}
 3155|       |
 3156|       |#endif /* ENABLE_PIV_SM */
 3157|  24.7k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3158|  24.7k|	if (r > 0) {
  ------------------
  |  Branch (3158:6): [True: 3.35k, False: 21.3k]
  ------------------
 3159|  3.35k|		int r_tag;
 3160|  3.35k|		unsigned int cla_out, tag_out;
 3161|  3.35k|		size_t bodylen = 0;
 3162|  3.35k|		const u8 *body = *buf;
 3163|  3.35k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3164|  3.35k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  6.71k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3164:7): [True: 612, False: 2.74k]
  |  Branch (3164:30): [True: 109, False: 2.63k]
  ------------------
 3165|  2.63k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3165:5): [True: 560, False: 2.07k]
  ------------------
 3166|  1.28k|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3167|  1.28k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.28k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3168|  1.28k|			goto err;
 3169|  1.28k|		}
 3170|  2.07k|		*buf_len = (body - *buf) + bodylen;
 3171|  21.3k|	} else if (r == 0) {
  ------------------
  |  Branch (3171:13): [True: 95, False: 21.2k]
  ------------------
 3172|     95|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     95|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3173|     95|		goto err;
 3174|  21.2k|	} else {
 3175|  21.2k|		goto err;
 3176|  21.2k|	}
 3177|       |
 3178|  2.07k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3178:6): [True: 2.07k, False: 0]
  |  Branch (3178:19): [True: 2.07k, False: 0]
  ------------------
 3179|  2.07k|		tbuf = malloc(r);
 3180|  2.07k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3180:7): [True: 0, False: 2.07k]
  ------------------
 3181|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3182|      0|			goto err;
 3183|      0|		}
 3184|  2.07k|		memcpy(tbuf, *buf, r);
 3185|  2.07k|		free(*buf);
 3186|  2.07k|		alloc_buf = 0;
 3187|  2.07k|		*buf = tbuf;
 3188|  2.07k|	}
 3189|       |
 3190|  24.7k|err:
 3191|  24.7k|	if (alloc_buf) {
  ------------------
  |  Branch (3191:6): [True: 22.5k, False: 2.12k]
  ------------------
 3192|  22.5k|		free(*buf);
 3193|  22.5k|		*buf = NULL;
 3194|  22.5k|	}
 3195|  24.7k|	sc_unlock(card);
 3196|  24.7k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  24.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.7k|	int _ret = r; \
  |  |  |  |  155|  24.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.6k, False: 2.07k]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.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|  22.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.6k|	} else { \
  |  |  |  |  159|  2.07k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.07k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.07k|	} \
  |  |  |  |  162|  24.7k|	return _ret; \
  |  |  |  |  163|  24.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3197|  24.7k|}
card-piv.c:piv_general_io:
 1794|  24.7k|{
 1795|  24.7k|	int r;
 1796|  24.7k|	sc_apdu_t apdu;
 1797|       |
 1798|  24.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  24.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  24.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  24.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24.7k]
  |  |  ------------------
  ------------------
 1799|       |
 1800|  24.7k|	r = sc_lock(card);
 1801|  24.7k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  24.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1801:6): [True: 0, False: 24.7k]
  ------------------
 1802|  24.7k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1803|       |
 1804|  24.7k|	sc_format_apdu(card, &apdu,
 1805|  24.7k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  24.7k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1805:4): [True: 24.7k, False: 0]
  ------------------
 1806|  24.7k|			ins, p1, p2);
 1807|  24.7k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  24.7k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1808|       |#ifdef ENABLE_PIV_SM
 1809|       |	if (card->sm_ctx.sm_mode != SM_MODE_NONE && sendbuflen > 255) {
 1810|       |		/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1811|       |		apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1812|       |	}
 1813|       |#endif
 1814|  24.7k|	apdu.lc = sendbuflen;
 1815|  24.7k|	apdu.datalen = sendbuflen;
 1816|  24.7k|	apdu.data = sendbuf;
 1817|       |
 1818|  24.7k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1818:6): [True: 24.7k, False: 0]
  |  Branch (1818:17): [True: 24.7k, False: 0]
  ------------------
 1819|  24.7k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1819:13): [True: 24.6k, False: 51]
  ------------------
 1820|  24.7k|		apdu.resplen = recvbuflen;
 1821|  24.7k|	} else {
 1822|      0|		apdu.le = 0;
 1823|      0|		apdu.resplen = 0;
 1824|      0|	}
 1825|  24.7k|	apdu.resp = recvbuf;
 1826|       |
 1827|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1828|  24.7k|	r = sc_transmit_apdu(card, &apdu);
 1829|       |
 1830|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1831|  24.7k|	if (r < 0) {
  ------------------
  |  Branch (1831:6): [True: 263, False: 24.4k]
  ------------------
 1832|    263|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    263|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1833|    263|		goto err;
 1834|    263|	}
 1835|       |
 1836|  24.4k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1836:6): [True: 94, False: 24.3k]
  |  Branch (1836:26): [True: 8, False: 86]
  ------------------
 1837|      8|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|      8|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1838|  24.4k|	else
 1839|  24.4k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1840|       |
 1841|  24.4k|	if (r < 0) {
  ------------------
  |  Branch (1841:6): [True: 21.0k, False: 3.45k]
  ------------------
 1842|  21.0k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  21.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__
  |  |  ------------------
  ------------------
 1843|  21.0k|		goto err;
 1844|  21.0k|	}
 1845|       |
 1846|  3.45k|	r = (int)apdu.resplen;
 1847|       |
 1848|  24.7k|err:
 1849|  24.7k|	sc_unlock(card);
 1850|  24.7k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  24.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.7k|	int _ret = r; \
  |  |  |  |  155|  24.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21.3k, False: 3.35k]
  |  |  |  |  ------------------
  |  |  |  |  156|  21.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|  21.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21.2k, False: 95]
  |  |  |  |  ------------------
  |  |  |  |  157|  21.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  21.3k|	} else { \
  |  |  |  |  159|  3.35k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.35k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.35k|	} \
  |  |  |  |  162|  24.7k|	return _ret; \
  |  |  |  |  163|  24.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|  24.7k|}
card-piv.c:piv_obj_cache_free_entry:
 5455|   262k|{
 5456|   262k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|   262k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5457|       |
 5458|   262k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5458:6): [True: 1.86k, False: 260k]
  ------------------
 5459|  1.86k|		free(priv->obj_cache[enumtag].obj_data);
 5460|   262k|	priv->obj_cache[enumtag].obj_data = NULL;
 5461|   262k|	priv->obj_cache[enumtag].obj_len = 0;
 5462|       |
 5463|   262k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5463:6): [True: 426, False: 262k]
  ------------------
 5464|    426|		free(priv->obj_cache[enumtag].internal_obj_data);
 5465|   262k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5466|   262k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5467|   262k|	priv->obj_cache[enumtag].flags = flags;
 5468|       |
 5469|   262k|	return SC_SUCCESS;
  ------------------
  |  |   28|   262k|#define SC_SUCCESS				0
  ------------------
 5470|   262k|}
card-piv.c:piv_find_aid:
 2903|  4.48k|{
 2904|  4.48k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  4.48k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2905|  4.48k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2906|  4.48k|	int r, i, j;
 2907|  4.48k|	const u8 *tag;
 2908|  4.48k|	size_t taglen;
 2909|  4.48k|	const u8 *nextac;
 2910|  4.48k|	const u8 *next80;
 2911|  4.48k|	const u8 *pix;
 2912|  4.48k|	size_t pixlen;
 2913|  4.48k|	const u8 *al_label;
 2914|  4.48k|	size_t al_labellen;
 2915|  4.48k|	const u8 *actag; /* Cipher Suite */
 2916|  4.48k|	size_t actaglen;
 2917|  4.48k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2918|  4.48k|	size_t csailen;
 2919|  4.48k|	size_t resplen = sizeof(rbuf);
 2920|       |#ifdef ENABLE_PIV_SM
 2921|       |	int found_csai = 0;
 2922|       |#endif
 2923|       |
 2924|  4.48k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.48k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.48k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.48k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.48k]
  |  |  ------------------
  ------------------
 2925|       |
 2926|       |	/* first  see if the default application will return a template
 2927|       |	 * that we know about.
 2928|       |	 */
 2929|       |
 2930|  4.48k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2931|  4.48k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2931:6): [True: 0, False: 4.48k]
  |  Branch (2931:15): [True: 0, False: 0]
  |  Branch (2931:38): [True: 0, False: 0]
  |  Branch (2931:70): [True: 0, False: 0]
  ------------------
 2932|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2933|       |		/* no need to parse again, same as last time */
 2934|      0|	}
 2935|  4.48k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2935:6): [True: 711, False: 3.77k]
  |  Branch (2935:16): [True: 666, False: 45]
  ------------------
 2936|    666|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2937|    666|		if (tag != NULL) {
  ------------------
  |  Branch (2937:7): [True: 557, False: 109]
  ------------------
 2938|    557|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|    557|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2939|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2940|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2941|       |			 * where xx is the SM csID either 27 or 2E.
 2942|       |			 * Some vendors may include entries for supported Algorithms even when
 2943|       |			 * not required. We will use these if possible
 2944|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2945|       |			 */
 2946|    557|			nextac = tag;
 2947|    582|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2947:11): [True: 25, False: 557]
  ------------------
 2948|    582|						0xAC, &actaglen)) != NULL) {
 2949|     25|				nextac = actag + actaglen;
 2950|       |
 2951|     25|				next80 = actag;
 2952|    127|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2952:12): [True: 102, False: 25]
  ------------------
 2953|    127|							0x80, &csailen)) != NULL) {
 2954|    102|					next80 = csai + csailen;
 2955|    102|					if (csailen == 1) {
  ------------------
  |  Branch (2955:10): [True: 23, False: 79]
  ------------------
 2956|     23|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   71|     23|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2957|     23|						j = piv_ai_map_find_by_id(card, *csai);
 2958|     23|						if (j >= 0) {
  ------------------
  |  Branch (2958:11): [True: 12, False: 11]
  ------------------
 2959|     12|							priv->alg_ids |= ai_map[j].ai_flag;
 2960|     12|							continue;
 2961|     12|						}
 2962|       |#ifdef ENABLE_PIV_SM
 2963|       |						/* check if id is NIST SM */
 2964|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2965|       |							if (*csai != css[i].id)
 2966|       |								continue;
 2967|       |							if (found_csai) {
 2968|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2969|       |							} else {
 2970|       |								priv->cs = &css[i];
 2971|       |								priv->csID = *csai;
 2972|       |								found_csai++;
 2973|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2974|       |							}
 2975|       |						}
 2976|       |#endif /* ENABLE_PIV_SM */
 2977|     23|					}
 2978|    102|				}
 2979|     25|			}
 2980|       |
 2981|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2982|    557|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2983|    557|			if (al_label != NULL) {
  ------------------
  |  Branch (2983:8): [True: 6, False: 551]
  ------------------
 2984|      6|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|      6|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      6|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2985|      6|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2985:9): [True: 0, False: 6]
  ------------------
 2986|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2987|      0|				}
 2988|      6|				memcpy(priv->al_label, al_label, al_labellen);
 2989|      6|				priv->al_labellen = (int)al_labellen;
 2990|      6|			}
 2991|       |
 2992|    557|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2993|    557|			if (pix != NULL) {
  ------------------
  |  Branch (2993:8): [True: 526, False: 31]
  ------------------
 2994|    526|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2995|       |
 2996|       |				/* early cards returned full AID, rather then just the pix */
 2997|    583|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2997:17): [True: 557, False: 26]
  ------------------
 2998|    557|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (2998:11): [True: 551, False: 6]
  ------------------
 2999|    551|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2999:12): [True: 497, False: 54]
  ------------------
 3000|     60|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3000:10): [True: 39, False: 21]
  |  Branch (3000:45): [True: 3, False: 36]
  ------------------
 3001|    500|													     piv_aids[i].len_short) == 0))) {
 3002|    500|						free(priv->aid_der.value); /* free previous value if any */
 3003|    500|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3003:11): [True: 0, False: 500]
  ------------------
 3004|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3005|      0|						}
 3006|    500|						memcpy(priv->aid_der.value, rbuf, resplen);
 3007|    500|						priv->aid_der.len = resplen;
 3008|    500|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    500|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    500|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    500|	int _ret = r; \
  |  |  |  |  155|    500|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 495, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  156|    495|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 495]
  |  |  |  |  ------------------
  |  |  |  |  157|    495|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    495|	} 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|    500|	return _ret; \
  |  |  |  |  163|    500|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3009|    500|					}
 3010|    557|				}
 3011|    526|			}
 3012|    557|		}
 3013|    666|	}
 3014|       |
 3015|  3.98k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  3.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.98k|	int _ret = r; \
  |  |  |  |  155|  3.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.98k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.98k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.98k|	return _ret; \
  |  |  |  |  163|  3.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3016|  3.98k|}
card-piv.c:piv_ai_map_find_by_id:
 2886|     23|{
 2887|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2888|     23|	int i;
 2889|       |
 2890|    127|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2890:14): [True: 116, False: 11]
  ------------------
 2891|    116|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2891:7): [True: 12, False: 104]
  ------------------
 2892|     12|			return i;
 2893|    116|	}
 2894|     11|	return -1;
 2895|     23|}
card-piv.c:piv_process_ccc:
 5139|    114|{
 5140|    114|	int r = 0;
 5141|    114|	u8 *rbuf = NULL;
 5142|    114|	size_t rbuflen = 0;
 5143|       |
 5144|    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]
  |  |  ------------------
  ------------------
 5145|    114|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5146|       |
 5147|    114|	if (r < 0)
  ------------------
  |  Branch (5147:6): [True: 70, False: 44]
  ------------------
 5148|     70|		goto err;
 5149|       |
 5150|       |	/* the object is now cached, see what we have */
 5151|     44|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5152|    114|err:
 5153|    114|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|    100|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 100, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5154|    114|}
card-piv.c:piv_parse_ccc:
 5075|     44|{
 5076|     44|	int r = 0;
 5077|     44|	const u8 *body;
 5078|     44|	size_t bodylen;
 5079|     44|	unsigned int cla_out, tag_out;
 5080|       |
 5081|     44|	u8 tag;
 5082|     44|	const u8 *end;
 5083|     44|	size_t len;
 5084|       |
 5085|     44|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     44|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5086|       |
 5087|     44|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     44|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     44|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     44|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 44]
  |  |  ------------------
  ------------------
 5088|       |
 5089|     44|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5089:6): [True: 0, False: 44]
  |  Branch (5089:22): [True: 0, False: 44]
  ------------------
 5090|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 5091|      0|		goto err;
 5092|      0|	}
 5093|       |
 5094|       |	/* Outer layer is a DER tlv */
 5095|     44|	body = rbuf;
 5096|     44|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|     88|#define SC_SUCCESS				0
  ------------------
  |  Branch (5096:6): [True: 0, False: 44]
  ------------------
 5097|     44|			body == NULL ||
  ------------------
  |  Branch (5097:4): [True: 0, False: 44]
  ------------------
 5098|     44|			bodylen == 0 ||
  ------------------
  |  Branch (5098:4): [True: 1, False: 43]
  ------------------
 5099|     43|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5099:4): [True: 0, False: 43]
  ------------------
 5100|      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__
  |  |  ------------------
  ------------------
 5101|      1|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5102|      1|		goto err;
 5103|      1|	}
 5104|       |
 5105|     43|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     43|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5106|       |
 5107|       |	/* CCC  entries are simple tlv */
 5108|     43|	end = body + bodylen;
 5109|    393|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5109:9): [True: 379, False: 14]
  ------------------
 5110|    379|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5111|    379|		if (r < 0)
  ------------------
  |  Branch (5111:7): [True: 29, False: 350]
  ------------------
 5112|     29|			goto err;
 5113|    350|		switch (tag) {
  ------------------
  |  Branch (5113:11): [True: 67, False: 283]
  ------------------
 5114|     45|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|     45|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5114:3): [True: 45, False: 305]
  ------------------
 5115|     45|			if (len == 0x15) {
  ------------------
  |  Branch (5115:8): [True: 2, False: 43]
  ------------------
 5116|      2|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5116:9): [True: 0, False: 2]
  ------------------
 5117|      0|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|      0|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5118|      2|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5118:14): [True: 0, False: 2]
  ------------------
 5119|      0|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|      0|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5120|      2|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5120:9): [True: 1, False: 1]
  ------------------
 5121|      1|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|      1|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5122|      2|			}
 5123|     45|			break;
 5124|     22|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|     22|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5124:3): [True: 22, False: 328]
  ------------------
 5125|     22|			if (len == 0x10) {
  ------------------
  |  Branch (5125:8): [True: 6, False: 16]
  ------------------
 5126|      6|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5126:9): [True: 0, False: 6]
  ------------------
 5127|      0|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|      0|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5128|      6|			}
 5129|     22|			break;
 5130|    350|		}
 5131|    350|	}
 5132|       |
 5133|     44|err:
 5134|     44|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     44|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     44|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     44|	int _ret = r; \
  |  |  |  |  155|     44|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 44, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     44|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 14]
  |  |  |  |  ------------------
  |  |  |  |  157|     44|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     44|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     44|	return _ret; \
  |  |  |  |  163|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5135|     44|}
card-piv.c:piv_init:
 6012|  1.09k|{
 6013|  1.09k|	int r = 0;
 6014|  1.09k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.09k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6015|  1.09k|	unsigned long flags;
 6016|  1.09k|	unsigned long flags_eddsa;
 6017|  1.09k|	unsigned long flags_xeddsa;
 6018|  1.09k|	unsigned long ext_flags;
 6019|       |
 6020|  1.09k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 6021|       |
 6022|  1.09k|	r = sc_lock(card); /* hold until match or init is complete */
 6023|  1.09k|	LOG_TEST_RET(card->ctx, r, "sc_lock 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: 0, False: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  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.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6024|       |
 6025|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6026|  1.09k|	if (priv == NULL) {
  ------------------
  |  Branch (6026:6): [True: 0, False: 1.09k]
  ------------------
 6027|      0|		r = piv_match_card_continued(card);
 6028|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  440|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6029|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (6029:7): [True: 0, False: 0]
  |  Branch (6029:16): [True: 0, False: 0]
  ------------------
 6030|      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__
  |  |  ------------------
  ------------------
 6031|      0|			sc_unlock(card);
 6032|      0|			piv_finish(card);
 6033|       |			/* tell sc_connect_card to try other driver */
 6034|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6035|      0|		}
 6036|      0|	}
 6037|       |
 6038|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 6039|  1.09k|	piv_load_options(card);
 6040|       |
 6041|  1.09k|	priv->pstate = PIV_STATE_INIT;
 6042|       |
 6043|  1.09k|	sc_log(card->ctx, "Max send = %zu recv = %zu card->type:%d, CI:%08x AI:%08x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6044|  1.09k|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6045|  1.09k|	card->cla = 0x00;
 6046|  1.09k|	if (card->name == NULL)
  ------------------
  |  Branch (6046:6): [True: 1.09k, False: 0]
  ------------------
 6047|  1.09k|		card->name = card->driver->name;
 6048|       |
 6049|  1.09k|	priv->enumtag = piv_aids[0].enumtag;
 6050|       |
 6051|       |	/* PKCS#11 may try to generate session keys, and get confused
 6052|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 6053|       |	 * piv-tool can still do this, just don't tell PKCS#11
 6054|       |	 */
 6055|       |
 6056|  1.09k|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|  1.09k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6057|       |
 6058|  1.09k|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6058:6): [True: 0, False: 1.09k]
  ------------------
 6059|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6060|      0|	}
 6061|       |
 6062|  1.09k|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  600|  1.09k|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6062:6): [True: 1.09k, False: 0]
  ------------------
 6063|  1.09k|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6064|       |
 6065|  1.09k|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  601|  1.09k|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6065:6): [True: 1.09k, False: 0]
  ------------------
 6066|  1.09k|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6067|       |
 6068|  1.09k|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  602|  1.09k|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6068:6): [True: 1.09k, False: 0]
  ------------------
 6069|  1.09k|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6070|       |
 6071|  1.09k|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  603|  1.09k|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6071:6): [True: 442, False: 653]
  ------------------
 6072|    442|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6073|       |
 6074|  1.09k|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  597|  1.09k|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6074:6): [True: 1.09k, False: 0]
  ------------------
 6075|  1.09k|		int i;
 6076|  1.09k|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|  1.09k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|  1.09k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|  1.09k|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|  1.09k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 6077|  1.09k|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|  1.09k|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|  1.09k|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 6078|  1.09k|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|  1.09k|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6079|  1.09k|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  189|  1.09k|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|  1.09k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 6080|       |
 6081|  5.47k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6081:15): [True: 4.38k, False: 1.09k]
  ------------------
 6082|  4.38k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  4.38k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6082:8): [True: 2.19k, False: 2.19k]
  ------------------
 6083|  2.19k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  596|  4.38k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6083:11): [True: 778, False: 1.41k]
  |  Branch (6083:46): [True: 389, False: 389]
  ------------------
 6084|  1.80k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6085|  2.19k|			}
 6086|       |
 6087|  2.19k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  606|  4.38k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    874|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6087:13): [True: 874, False: 1.31k]
  |  Branch (6087:41): [True: 437, False: 437]
  ------------------
 6088|    437|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6089|       |
 6090|  1.75k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  607|  3.50k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|    437|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6090:13): [True: 437, False: 1.31k]
  |  Branch (6090:42): [True: 437, False: 0]
  ------------------
 6091|    437|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6092|  4.38k|		}
 6093|  1.09k|	}
 6094|       |
 6095|  1.09k|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  587|  1.09k|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6095:6): [True: 1.06k, False: 35]
  ------------------
 6096|  1.06k|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|  1.06k|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6097|       |
 6098|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6099|  1.09k|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|  1.09k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6100|       |
 6101|       |	/*
 6102|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6103|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6104|       |	 */
 6105|       |
 6106|       |#ifdef ENABLE_PIV_SM
 6107|       |	/*
 6108|       |	 * 800-73-4
 6109|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6110|       |	 */
 6111|       |	if (priv->csID && priv->cs != NULL) {
 6112|       |		/*
 6113|       |		 * Main point in SM and VCI is to allow contactless access
 6114|       |		 */
 6115|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6116|       |
 6117|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6118|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6119|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6120|       |			r = SC_SUCCESS; /* Users choice */
 6121|       |
 6122|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6123|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6124|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6125|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6126|       |
 6127|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6128|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6129|       |				(priv->pairing_code[0] == 0x00)) {
 6130|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6131|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6132|       |
 6133|       |		} else {
 6134|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6135|       |			r = piv_sm_open(card);
 6136|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6137|       |		}
 6138|       |
 6139|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6140|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6141|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6142|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6143|       |		}
 6144|       |
 6145|       |		/* user has wrong or no required pairing code */
 6146|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6147|       |			LOG_FUNC_RETURN(card->ctx, r);
 6148|       |
 6149|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6150|       |	}
 6151|       |#endif /* ENABLE_PIV_SM */
 6152|       |
 6153|       |	/*
 6154|       |	 * 800-73-3 cards may have a history object
 6155|       |	 * We want to process it now as this has information on what
 6156|       |	 * keys and certs. "piv like" cards may or may not have history
 6157|       |	 */
 6158|  1.09k|	piv_process_history(card);
 6159|       |
 6160|  1.09k|	priv->pstate = PIV_STATE_NORMAL;
 6161|  1.09k|	sc_unlock(card);
 6162|  1.09k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.09k|	int _ret = r; \
  |  |  |  |  155|  1.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.09k|	return _ret; \
  |  |  |  |  163|  1.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6163|  1.09k|}
card-piv.c:piv_load_options:
 1686|  1.09k|{
 1687|  1.09k|	int r;
 1688|  1.09k|	size_t i, j;
 1689|  1.09k|	scconf_block **found_blocks, *block;
 1690|       |
 1691|       |#ifdef ENABLE_PIV_SM
 1692|       |	piv_private_data_t *priv = PIV_DATA(card);
 1693|       |	const char *option = NULL;
 1694|       |	int piv_pairing_code_found = 0;
 1695|       |	int piv_use_sm_found = 0;
 1696|       |
 1697|       |	/* pairing code is 8 decimal digits and is card specific */
 1698|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1699|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1700|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1701|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1702|       |			piv_pairing_code_found = 1;
 1703|       |		}
 1704|       |	}
 1705|       |
 1706|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1707|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1708|       |		if (!strcmp(option, "never")) {
 1709|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1710|       |			piv_use_sm_found = 1;
 1711|       |		} else if (!strcmp(option, "always")) {
 1712|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1713|       |			piv_use_sm_found = 1;
 1714|       |		} else {
 1715|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1716|       |		}
 1717|       |	}
 1718|       |#endif
 1719|       |
 1720|  2.19k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1720:14): [True: 1.09k, False: 1.09k]
  ------------------
 1721|  1.09k|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1722|  1.09k|				"card_driver", "PIV-II");
 1723|  1.09k|		if (!found_blocks)
  ------------------
  |  Branch (1723:7): [True: 0, False: 1.09k]
  ------------------
 1724|      0|			continue;
 1725|       |
 1726|  1.09k|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1726:40): [True: 0, False: 1.09k]
  ------------------
 1727|       |
 1728|       |#ifdef ENABLE_PIV_SM
 1729|       |			/*
 1730|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1731|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1732|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1733|       |			 * this security risk
 1734|       |			 * always - Use even for contact interface.
 1735|       |			 * PINS, crypto and reading of object will not show up in logs
 1736|       |			 * or over network.
 1737|       |			 */
 1738|       |
 1739|       |			if (piv_use_sm_found == 0) {
 1740|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1741|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1742|       |				if (!strcmp(option, "default")) {
 1743|       |					/* no new flags */
 1744|       |				} else if (!strcmp(option, "never")) {
 1745|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1746|       |				} else if (!strcmp(option, "always")) {
 1747|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1748|       |				} else {
 1749|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1750|       |				}
 1751|       |			}
 1752|       |
 1753|       |			/* This is really a card specific value and should not be in the conf file */
 1754|       |			if (piv_pairing_code_found == 0) {
 1755|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1756|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1757|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1758|       |				}
 1759|       |			}
 1760|       |#endif
 1761|      0|		}
 1762|  1.09k|		free(found_blocks);
 1763|  1.09k|	}
 1764|  1.09k|	r = SC_SUCCESS;
  ------------------
  |  |   28|  1.09k|#define SC_SUCCESS				0
  ------------------
 1765|  1.09k|	return r;
 1766|  1.09k|}
card-piv.c:piv_process_history:
 5211|  1.09k|{
 5212|  1.09k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.09k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5213|  1.09k|	int r;
 5214|  1.09k|	int i, tmplen, tmplen2, tmplen3;
 5215|  1.09k|	int enumtag;
 5216|  1.09k|	u8 *rbuf = NULL;
 5217|  1.09k|	size_t rbuflen = 0;
 5218|  1.09k|	const u8 *body;
 5219|  1.09k|	size_t bodylen;
 5220|  1.09k|	const u8 *num;
 5221|  1.09k|	size_t numlen;
 5222|  1.09k|	const u8 *url = NULL;
 5223|  1.09k|	size_t urllen;
 5224|  1.09k|	u8 *ocfhfbuf = NULL;
 5225|  1.09k|	unsigned int cla_out, tag_out;
 5226|  1.09k|	size_t ocfhflen;
 5227|  1.09k|	const u8 *seq;
 5228|  1.09k|	const u8 *seqtag;
 5229|  1.09k|	size_t seqlen;
 5230|  1.09k|	const u8 *keyref;
 5231|  1.09k|	size_t keyreflen;
 5232|  1.09k|	const u8 *cert;
 5233|  1.09k|	size_t certlen;
 5234|  1.09k|	size_t certobjlen, i2;
 5235|  1.09k|	u8 *certobj;
 5236|  1.09k|	u8 *cp;
 5237|       |
 5238|  1.09k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 5239|       |
 5240|  1.09k|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5241|  1.09k|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  1.09k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5241:6): [True: 301, False: 794]
  ------------------
 5242|    301|		r = 0; /* OK if not found */
 5243|  1.09k|	if (r <= 0) {
  ------------------
  |  Branch (5243:6): [True: 898, False: 197]
  ------------------
 5244|    898|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    898|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5245|    898|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5246|    898|	}
 5247|       |
 5248|       |	/* the object is now cached, see what we have */
 5249|    197|	if (rbuflen != 0) {
  ------------------
  |  Branch (5249:6): [True: 197, False: 0]
  ------------------
 5250|    197|		body = rbuf;
 5251|    197|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    394|#define SC_SUCCESS				0
  ------------------
  |  Branch (5251:7): [True: 0, False: 197]
  ------------------
 5252|    197|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5252:5): [True: 0, False: 197]
  ------------------
 5253|      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__
  |  |  ------------------
  ------------------
 5254|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5255|      0|			goto err;
 5256|      0|		}
 5257|       |
 5258|    197|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5258:7): [True: 197, False: 0]
  |  Branch (5258:23): [True: 193, False: 4]
  ------------------
 5259|    193|			numlen = 0;
 5260|    193|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5261|    193|			if (num) {
  ------------------
  |  Branch (5261:8): [True: 75, False: 118]
  ------------------
 5262|     75|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5262:9): [True: 8, False: 67]
  |  Branch (5262:24): [True: 2, False: 65]
  ------------------
 5263|     10|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     10|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5264|     10|					goto err;
 5265|     10|				}
 5266|       |
 5267|     65|				priv->keysWithOnCardCerts = *num;
 5268|     65|			}
 5269|       |
 5270|    183|			numlen = 0;
 5271|    183|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5272|    183|			if (num) {
  ------------------
  |  Branch (5272:8): [True: 3, False: 180]
  ------------------
 5273|      3|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5273:9): [True: 1, False: 2]
  |  Branch (5273:24): [True: 1, False: 1]
  ------------------
 5274|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5275|      2|					goto err;
 5276|      2|				}
 5277|       |
 5278|      1|				priv->keysWithOffCardCerts = *num;
 5279|      1|			}
 5280|       |
 5281|    181|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5282|    181|			if (url) {
  ------------------
  |  Branch (5282:8): [True: 25, False: 156]
  ------------------
 5283|     25|				if (urllen > 118) {
  ------------------
  |  Branch (5283:9): [True: 0, False: 25]
  ------------------
 5284|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5285|      0|					goto err;
 5286|      0|				}
 5287|     25|				priv->offCardCertURL = calloc(1, urllen + 1);
 5288|     25|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5288:9): [True: 0, False: 25]
  ------------------
 5289|     25|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5290|     25|				memcpy(priv->offCardCertURL, url, urllen);
 5291|     25|			}
 5292|    181|		} else {
 5293|      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__
  |  |  ------------------
  ------------------
 5294|      4|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
 5295|      4|			goto err;
 5296|      4|		}
 5297|    197|	}
 5298|    181|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 25, False: 156]
  |  |  ------------------
  ------------------
 5299|    181|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5300|    181|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5301|       |
 5302|       |	/* now mark what objects are on the card */
 5303|  1.11k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5303:14): [True: 929, False: 181]
  ------------------
 5304|    929|		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
  ------------------
 5305|       |
 5306|       |	/*
 5307|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5308|       |	 * we will read in and add the certs to the cache as listed on
 5309|       |	 * the card. some of the certs may be on the card as well.
 5310|       |	 *
 5311|       |	 * Get file name from url. verify that the filename is valid
 5312|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5313|       |	 * in the directory used for the  PKCS15 cache
 5314|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5315|       |	 */
 5316|       |
 5317|    181|	r = 0;
 5318|    181|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5318:6): [True: 25, False: 156]
  ------------------
 5319|     25|		char *fp;
 5320|     25|		char filename[PATH_MAX];
 5321|       |
 5322|     25|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5322:7): [True: 25, False: 0]
  ------------------
 5323|     25|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     25|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5324|     25|			goto err;
 5325|     25|		}
 5326|       |		/* find the last /  so we have the filename part */
 5327|      0|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5328|      0|		if (fp == NULL) {
  ------------------
  |  Branch (5328:7): [True: 0, False: 0]
  ------------------
 5329|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5330|      0|			goto err;
 5331|      0|		}
 5332|      0|		fp++;
 5333|      0|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5333:7): [True: 0, False: 0]
  ------------------
 5334|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5335|      0|			goto err;
 5336|      0|		}
 5337|      0|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5337:15): [True: 0, False: 0]
  ------------------
 5338|      0|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5338:8): [True: 0, False: 0]
  ------------------
 5339|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5340|      0|				goto err;
 5341|      0|			}
 5342|      0|		}
 5343|       |
 5344|       |		/* Use the same directory as used for other OpenSC cached items */
 5345|      0|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5346|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5346:7): [True: 0, False: 0]
  ------------------
 5347|      0|			goto err;
 5348|       |#ifdef _WIN32
 5349|       |		strlcat(filename, "\\", PATH_MAX);
 5350|       |#else
 5351|      0|		strlcat(filename, "/", PATH_MAX);
 5352|      0|#endif
 5353|      0|		strlcat(filename, fp, PATH_MAX);
 5354|       |
 5355|      0|		r = piv_read_obj_from_file(card, filename,
 5356|      0|				&ocfhfbuf, &ocfhflen);
 5357|      0|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5357:7): [True: 0, False: 0]
  ------------------
 5358|      0|			r = 0;
 5359|      0|			goto err;
 5360|      0|		}
 5361|       |
 5362|       |		/*
 5363|       |		 * Its a seq of seq of a key ref and cert
 5364|       |		 */
 5365|       |
 5366|      0|		body = ocfhfbuf;
 5367|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5367:7): [True: 0, False: 0]
  ------------------
 5368|      0|				body == NULL ||
  ------------------
  |  Branch (5368:5): [True: 0, False: 0]
  ------------------
 5369|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5369:5): [True: 0, False: 0]
  ------------------
 5370|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5370:5): [True: 0, False: 0]
  ------------------
 5371|      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__
  |  |  ------------------
  ------------------
 5372|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5373|      0|			goto err;
 5374|      0|		}
 5375|      0|		seq = body;
 5376|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5376:10): [True: 0, False: 0]
  ------------------
 5377|      0|			seqtag = seq;
 5378|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5378:8): [True: 0, False: 0]
  ------------------
 5379|      0|					seq == 0 ||
  ------------------
  |  Branch (5379:6): [True: 0, False: 0]
  ------------------
 5380|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5380:6): [True: 0, False: 0]
  ------------------
 5381|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5381:6): [True: 0, False: 0]
  ------------------
 5382|      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__
  |  |  ------------------
  ------------------
 5383|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5384|      0|				goto err;
 5385|      0|			}
 5386|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5387|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5387:8): [True: 0, False: 0]
  |  Branch (5387:19): [True: 0, False: 0]
  ------------------
 5388|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5388:7): [True: 0, False: 0]
  |  Branch (5388:25): [True: 0, False: 0]
  ------------------
 5389|      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__
  |  |  ------------------
  ------------------
 5390|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5391|      0|				goto err;
 5392|      0|			}
 5393|      0|			cert = keyref + keyreflen;
 5394|      0|			certlen = seqlen - (cert - seq);
 5395|       |
 5396|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5397|       |			/* now add the cert like another object */
 5398|       |
 5399|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5399:8): [True: 0, False: 0]
  ------------------
 5400|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5400:6): [True: 0, False: 0]
  ------------------
 5401|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5401:6): [True: 0, False: 0]
  ------------------
 5402|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5403|      0|				goto err;
 5404|      0|			}
 5405|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5406|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5407|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5407:8): [True: 0, False: 0]
  ------------------
 5408|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5409|      0|				goto err;
 5410|      0|			}
 5411|       |
 5412|      0|			certobjlen = tmplen;
 5413|      0|			certobj = malloc(certobjlen);
 5414|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5414:8): [True: 0, False: 0]
  ------------------
 5415|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5416|      0|				goto err;
 5417|      0|			}
 5418|      0|			cp = certobj;
 5419|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5419:8): [True: 0, False: 0]
  ------------------
 5420|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5420:6): [True: 0, False: 0]
  ------------------
 5421|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5421:6): [True: 0, False: 0]
  ------------------
 5422|      0|				goto err;
 5423|      0|			}
 5424|      0|			*cp++ = 0x00;
 5425|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5426|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5426:8): [True: 0, False: 0]
  ------------------
 5427|      0|				goto err;
 5428|      0|			}
 5429|       |
 5430|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5431|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5432|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5433|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5434|       |
 5435|      0|			r = piv_cache_internal_data(card, enumtag);
 5436|      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__
  |  |  ------------------
  ------------------
 5437|       |
 5438|      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__
  |  |  ------------------
  ------------------
 5439|      0|					enumtag,
 5440|      0|					priv->obj_cache[enumtag].obj_data,
 5441|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5442|       |
 5443|      0|			bodylen -= (seqlen + seq - seqtag);
 5444|      0|			seq += seqlen;
 5445|      0|		}
 5446|      0|	}
 5447|  1.09k|err:
 5448|  1.09k|	if (ocfhfbuf)
  ------------------
  |  Branch (5448:6): [True: 0, False: 1.09k]
  ------------------
 5449|      0|		free(ocfhfbuf);
 5450|  1.09k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.09k|	int _ret = r; \
  |  |  |  |  155|  1.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|    634|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 634, False: 461]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.09k|	return _ret; \
  |  |  |  |  163|  1.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5451|  1.09k|}
card-piv.c:piv_cache_internal_data:
 3285|  1.01k|{
 3286|  1.01k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.01k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3287|  1.01k|	const u8 *tag;
 3288|  1.01k|	const u8 *body;
 3289|  1.01k|	size_t taglen;
 3290|  1.01k|	size_t bodylen;
 3291|  1.01k|	int compressed = 0;
 3292|  1.01k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.01k|#define SC_SUCCESS				0
  ------------------
 3293|       |#ifdef ENABLE_PIV_SM
 3294|       |	u8 *cvc_start = NULL;
 3295|       |	size_t cvc_len = 0;
 3296|       |#endif
 3297|       |
 3298|       |	/* if already cached */
 3299|  1.01k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3299:6): [True: 426, False: 586]
  |  Branch (3299:52): [True: 426, False: 0]
  ------------------
 3300|    426|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   71|    426|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3301|    426|				enumtag,
 3302|    426|				priv->obj_cache[enumtag].internal_obj_data,
 3303|    426|				priv->obj_cache[enumtag].internal_obj_len);
 3304|    426|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    426|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    426|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    426|	int _ret = r; \
  |  |  |  |  155|    426|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 426, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    426|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 426]
  |  |  |  |  ------------------
  |  |  |  |  157|    426|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    426|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    426|	return _ret; \
  |  |  |  |  163|    426|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3305|    426|	}
 3306|       |
 3307|    586|	body = sc_asn1_find_tag(card->ctx,
 3308|    586|			priv->obj_cache[enumtag].obj_data,
 3309|    586|			priv->obj_cache[enumtag].obj_len,
 3310|    586|			0x53, &bodylen);
 3311|       |
 3312|    586|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3312:6): [True: 0, False: 586]
  |  Branch (3312:22): [True: 0, False: 586]
  ------------------
 3313|    586|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3314|       |
 3315|       |	/* get the certificate out */
 3316|    586|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  644|    586|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3316:6): [True: 586, False: 0]
  ------------------
 3317|       |
 3318|    586|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3319|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3320|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3321|    586|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3321:7): [True: 253, False: 333]
  |  Branch (3321:14): [True: 250, False: 3]
  |  Branch (3321:29): [True: 4, False: 246]
  |  Branch (3321:48): [True: 6, False: 240]
  ------------------
 3322|     10|			compressed = 1;
 3323|       |
 3324|       |#ifdef ENABLE_PIV_SM
 3325|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3326|       |#endif
 3327|       |
 3328|    586|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3329|    586|		if (tag == NULL)
  ------------------
  |  Branch (3329:7): [True: 157, False: 429]
  ------------------
 3330|    586|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    157|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    157|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    157|	int _ret = r; \
  |  |  |  |  155|    157|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 157, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    157|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    157|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    157|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    157|	return _ret; \
  |  |  |  |  163|    157|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3331|       |
 3332|    429|		if (taglen == 0)
  ------------------
  |  Branch (3332:7): [True: 3, False: 426]
  ------------------
 3333|    429|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3334|       |
 3335|    426|		if (compressed) {
  ------------------
  |  Branch (3335:7): [True: 7, False: 419]
  ------------------
 3336|      7|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|      7|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3337|      7|		}
 3338|       |		/* internal certificate remains compressed */
 3339|    426|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3339:7): [True: 0, False: 426]
  ------------------
 3340|    426|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3341|       |
 3342|    426|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3343|    426|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3344|       |
 3345|       |#ifdef ENABLE_PIV_SM
 3346|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3347|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3348|       |			/* cvc if present should be at cvc_start.
 3349|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3350|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3351|       |			 * as the size of (L) depends on the length of value
 3352|       |			 */
 3353|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3354|       |					cvc_start &&
 3355|       |					cvc_start < tag &&
 3356|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3357|       |				cvc_len = tag - cvc_start + taglen;
 3358|       |				/* decode the intermediate CVC */
 3359|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3360|       |				if (r < 0) {
 3361|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3362|       |				}
 3363|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3364|       |			}
 3365|       |		}
 3366|       |#endif /* ENABLE_PIV_SM */
 3367|       |
 3368|       |		/* convert pub key to internal */
 3369|    426|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3369:13): [True: 0, False: 0]
  ------------------
 3370|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3371|      0|		if (tag == NULL)
  ------------------
  |  Branch (3371:7): [True: 0, False: 0]
  ------------------
 3372|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3373|       |
 3374|      0|		if (taglen == 0)
  ------------------
  |  Branch (3374:7): [True: 0, False: 0]
  ------------------
 3375|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3376|       |
 3377|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3377:7): [True: 0, False: 0]
  ------------------
 3378|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3379|       |
 3380|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3381|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3382|      0|	} else {
 3383|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3384|      0|	}
 3385|       |
 3386|    426|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   71|    426|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3387|    426|			enumtag,
 3388|    426|			priv->obj_cache[enumtag].internal_obj_data,
 3389|    426|			priv->obj_cache[enumtag].internal_obj_len);
 3390|       |
 3391|    426|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    426|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    426|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    426|	int _ret = r; \
  |  |  |  |  155|    426|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 426, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    426|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 426]
  |  |  |  |  ------------------
  |  |  |  |  157|    426|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    426|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    426|	return _ret; \
  |  |  |  |  163|    426|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3392|    426|}
card-piv.c:piv_finish:
 5474|  7.63k|{
 5475|  7.63k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  7.63k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5476|  7.63k|	int i;
 5477|       |
 5478|  7.63k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.63k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.63k]
  |  |  ------------------
  ------------------
 5479|  7.63k|	if (priv) {
  ------------------
  |  Branch (5479:6): [True: 4.36k, False: 3.27k]
  ------------------
 5480|  4.36k|		if (priv->context_specific) {
  ------------------
  |  Branch (5480:7): [True: 0, False: 4.36k]
  ------------------
 5481|      0|			sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC 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__
  |  |  ------------------
  ------------------
 5482|      0|			priv->context_specific = 0;
 5483|      0|			sc_unlock(card);
 5484|      0|		}
 5485|  4.36k|		free(priv->aid_der.value);
 5486|  4.36k|		free(priv->al_label);
 5487|  4.36k|		if (priv->w_buf)
  ------------------
  |  Branch (5487:7): [True: 0, False: 4.36k]
  ------------------
 5488|      0|			free(priv->w_buf);
 5489|  4.36k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5489:7): [True: 25, False: 4.34k]
  ------------------
 5490|     25|			free(priv->offCardCertURL);
 5491|   266k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5491:15): [True: 261k, False: 4.36k]
  ------------------
 5492|   261k|			piv_obj_cache_free_entry(card, i, 0);
 5493|   261k|		}
 5494|       |#ifdef ENABLE_PIV_SM
 5495|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5496|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5497|       |		piv_clear_sm_session(&priv->sm_session);
 5498|       |#endif /* ENABLE_PIV_SM */
 5499|       |
 5500|  4.36k|		free(priv);
 5501|       |		card->drv_data = NULL; /* priv */
 5502|  4.36k|	}
 5503|  7.63k|	return 0;
 5504|  7.63k|}
card-piv.c:piv_select_file:
 4908|  15.0k|{
 4909|  15.0k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  15.0k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4910|  15.0k|	int r;
 4911|  15.0k|	int i;
 4912|  15.0k|	const u8 *path;
 4913|  15.0k|	size_t pathlen;
 4914|  15.0k|	sc_file_t *file = NULL;
 4915|  15.0k|	u8 *rbuf = NULL;
 4916|  15.0k|	size_t rbuflen = 0;
 4917|       |
 4918|  15.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.0k]
  |  |  ------------------
  ------------------
 4919|       |
 4920|  15.0k|	path = in_path->value;
 4921|  15.0k|	pathlen = in_path->len;
 4922|       |
 4923|       |	/* only support single EF in current application */
 4924|       |	/*
 4925|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 4926|       |	 * select_file and read_binary. The emulation adds path emulated structures
 4927|       |	 * so piv_select_file will find it.
 4928|       |	 * there is no dir. Only direct access to emulated files
 4929|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 4930|       |	 */
 4931|       |
 4932|  15.0k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4932:6): [True: 689, False: 14.4k]
  ------------------
 4933|    689|		if (pathlen > 2) {
  ------------------
  |  Branch (4933:7): [True: 689, False: 0]
  ------------------
 4934|    689|			path += 2;
 4935|    689|			pathlen -= 2;
 4936|    689|		}
 4937|    689|	}
 4938|       |
 4939|  15.0k|	i = piv_find_obj_by_containerid(card, path);
 4940|       |
 4941|  15.0k|	if (i < 0)
  ------------------
  |  Branch (4941:6): [True: 1.25k, False: 13.8k]
  ------------------
 4942|  15.0k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  1.25k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.25k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.25k|	int _ret = r; \
  |  |  |  |  155|  1.25k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.25k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.25k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.25k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.25k|	} else { \
  |  |  |  |  159|      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.25k|	return _ret; \
  |  |  |  |  163|  1.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4943|       |
 4944|       |	/*
 4945|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 4946|       |	 * with cece added to path to request only the cert from the cert obj
 4947|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 4948|       |	 */
 4949|  13.8k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4949:28): [True: 6.37k, False: 7.46k]
  |  Branch (4949:44): [True: 6.37k, False: 0]
  |  Branch (4949:63): [True: 6.37k, False: 0]
  ------------------
 4950|       |
 4951|  13.8k|	priv->selected_obj = i;
 4952|  13.8k|	priv->rwb_state = -1;
 4953|       |
 4954|       |	/* make it look like the file was found. */
 4955|       |	/* We don't want to read it now  unless we need the length */
 4956|       |
 4957|  13.8k|	if (file_out) {
  ------------------
  |  Branch (4957:6): [True: 13.8k, False: 0]
  ------------------
 4958|       |		/* we need to read it now, to get length into cache */
 4959|  13.8k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4960|       |
 4961|  13.8k|		if (r < 0)
  ------------------
  |  Branch (4961:7): [True: 12.2k, False: 1.57k]
  ------------------
 4962|  13.8k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  12.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.2k|	int _ret = r; \
  |  |  |  |  155|  12.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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|  12.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.2k|	return _ret; \
  |  |  |  |  163|  12.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4963|       |
 4964|       |		/* get the cert or the pub key out and into the cache too */
 4965|  1.57k|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|    987|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (4965:7): [True: 586, False: 987]
  |  Branch (4965:33): [True: 0, False: 987]
  ------------------
 4966|    586|			r = piv_cache_internal_data(card, i);
 4967|    586|			if (r < 0)
  ------------------
  |  Branch (4967:8): [True: 160, False: 426]
  ------------------
 4968|    586|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    160|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    160|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    160|	int _ret = r; \
  |  |  |  |  155|    160|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 160, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    160|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    160|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 160, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    160|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    160|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    160|	return _ret; \
  |  |  |  |  163|    160|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4969|    586|		}
 4970|       |
 4971|  1.41k|		file = sc_file_new();
 4972|  1.41k|		if (file == NULL)
  ------------------
  |  Branch (4972:7): [True: 0, False: 1.41k]
  ------------------
 4973|  1.41k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4974|       |
 4975|  1.41k|		file->path = *in_path;
 4976|       |		/* this could be like the FCI */
 4977|  1.41k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  1.41k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4978|  1.41k|		file->shareable = 0;
 4979|  1.41k|		file->ef_structure = 0;
 4980|  1.41k|		if (priv->return_only_cert)
  ------------------
  |  Branch (4980:7): [True: 426, False: 987]
  ------------------
 4981|    426|			file->size = priv->obj_cache[i].internal_obj_len;
 4982|    987|		else
 4983|    987|			file->size = priv->obj_cache[i].obj_len;
 4984|       |
 4985|  1.41k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4986|       |
 4987|  1.41k|		*file_out = file;
 4988|  1.41k|	}
 4989|       |
 4990|  1.41k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.41k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4991|  1.41k|}
card-piv.c:piv_find_obj_by_containerid:
 1770|  82.6k|{
 1771|  82.6k|	int i;
 1772|       |
 1773|  82.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  82.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  82.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  82.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  82.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 82.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1774|  82.6k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  82.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__
  |  |  ------------------
  ------------------
 1775|       |
 1776|  1.63M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1776:14): [True: 1.63M, False: 2.34k]
  ------------------
 1777|  1.63M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1777:7): [True: 718k, False: 914k]
  |  Branch (1777:50): [True: 80.2k, False: 638k]
  ------------------
 1778|  1.63M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  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: 1.64k, False: 78.6k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.64k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  78.6k|	} else { \
  |  |  |  |  159|  78.6k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  78.6k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  78.6k|	} \
  |  |  |  |  162|  80.2k|	return _ret; \
  |  |  |  |  163|  80.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|  1.63M|	}
 1780|       |
 1781|  2.34k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.34k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.34k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.34k|	int _ret = r; \
  |  |  |  |  155|  2.34k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.34k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.34k|	} else { \
  |  |  |  |  159|      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.34k|	return _ret; \
  |  |  |  |  163|  2.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|  2.34k|}
card-piv.c:piv_read_binary:
 3401|  6.09k|{
 3402|  6.09k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  6.09k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3403|  6.09k|	int enumtag;
 3404|  6.09k|	int r;
 3405|  6.09k|	u8 *rbuf = NULL;
 3406|  6.09k|	size_t rbuflen = 0;
 3407|  6.09k|	const u8 *body;
 3408|  6.09k|	size_t bodylen;
 3409|       |
 3410|  6.09k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.09k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.09k]
  |  |  ------------------
  ------------------
 3411|  6.09k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3411:6): [True: 0, False: 6.09k]
  ------------------
 3412|  6.09k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3413|  6.09k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3414|       |
 3415|  6.09k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3415:6): [True: 1.41k, False: 4.68k]
  ------------------
 3416|  1.41k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3417|       |
 3418|  1.41k|		if (r >= 0) {
  ------------------
  |  Branch (3418:7): [True: 1.41k, False: 0]
  ------------------
 3419|       |			/* an object with no data will be considered not found */
 3420|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3421|  1.41k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3421:8): [True: 0, False: 1.41k]
  |  Branch (3421:17): [True: 0, False: 1.41k]
  |  Branch (3421:37): [True: 1.01k, False: 399]
  |  Branch (3421:65): [True: 7, False: 1.00k]
  ------------------
 3422|      7|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      7|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3423|      7|				goto err;
 3424|      7|			}
 3425|       |
 3426|  1.40k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3427|  1.40k|			if (body == NULL) {
  ------------------
  |  Branch (3427:8): [True: 0, False: 1.40k]
  ------------------
 3428|       |				/* if missing, assume its the body */
 3429|       |				/* DEE bug in the beta card */
 3430|      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__
  |  |  ------------------
  ------------------
 3431|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3432|      0|				goto err;
 3433|      0|			}
 3434|  1.40k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3434:8): [True: 0, False: 1.40k]
  ------------------
 3435|      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__
  |  |  ------------------
  ------------------
 3436|      0|						bodylen, body - rbuf, rbuflen);
 3437|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3438|      0|				goto err;
 3439|      0|			}
 3440|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3441|  1.40k|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|    980|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3441:8): [True: 426, False: 980]
  |  Branch (3441:34): [True: 0, False: 980]
  ------------------
 3442|    426|				r = piv_cache_internal_data(card, enumtag);
 3443|    426|				if (r < 0)
  ------------------
  |  Branch (3443:9): [True: 0, False: 426]
  ------------------
 3444|      0|					goto err;
 3445|    426|			}
 3446|  1.40k|		}
 3447|  1.40k|		priv->rwb_state = 0;
 3448|  1.40k|	}
 3449|       |
 3450|  6.08k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|  5.18k|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3450:6): [True: 897, False: 5.18k]
  |  Branch (3450:32): [True: 0, False: 5.18k]
  ------------------
 3451|    897|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3452|    897|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3453|    897|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|    897|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3453:7): [True: 13, False: 884]
  |  Branch (3453:70): [True: 13, False: 0]
  ------------------
 3454|     13|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     13|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3455|     13|		}
 3456|  5.18k|	} else {
 3457|  5.18k|		rbuf = priv->obj_cache[enumtag].obj_data;
 3458|  5.18k|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3459|  5.18k|	}
 3460|       |	/* rbuf rbuflen has pointer and length to cached data */
 3461|       |
 3462|  6.08k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3462:6): [True: 0, False: 6.08k]
  ------------------
 3463|      0|		count = rbuflen - idx;
 3464|  6.08k|	if (count <= 0) {
  ------------------
  |  Branch (3464:6): [True: 0, False: 6.08k]
  ------------------
 3465|      0|		r = 0;
 3466|      0|		priv->rwb_state = 1;
 3467|  6.08k|	} else {
 3468|  6.08k|		memcpy(buf, rbuf + idx, count);
 3469|  6.08k|		r = (int)count;
 3470|  6.08k|	}
 3471|       |
 3472|  6.09k|err:
 3473|  6.09k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.09k|	int _ret = r; \
  |  |  |  |  155|  6.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 6.08k]
  |  |  |  |  ------------------
  |  |  |  |  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|  6.08k|	} else { \
  |  |  |  |  159|  6.08k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  6.08k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  6.08k|	} \
  |  |  |  |  162|  6.09k|	return _ret; \
  |  |  |  |  163|  6.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3474|  6.09k|}
card-piv.c:piv_yk_get_metadata:
 4504|    381|{
 4505|    381|	sc_apdu_t apdu;
 4506|    381|	u8 resp[100];
 4507|    381|	size_t i;
 4508|    381|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    381|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4509|       |
 4510|       |	/* initialize with the default behaviour */
 4511|    381|	if (pin_policy)
  ------------------
  |  Branch (4511:6): [True: 381, False: 0]
  ------------------
 4512|    381|		*pin_policy = 0x00;
 4513|    381|	if (touch_policy)
  ------------------
  |  Branch (4513:6): [True: 0, False: 381]
  ------------------
 4514|      0|		*touch_policy = 0x00;
 4515|       |
 4516|    381|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4516:6): [True: 31, False: 350]
  ------------------
 4517|     31|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4517:7): [True: 25, False: 6]
  ------------------
 4518|     25|			sc_log(card->ctx, "Yubikey's PIN and touch policy not available");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4519|     31|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     31|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4520|     31|	}
 4521|       |
 4522|    355|	for (i = 0; i < (sizeof(priv->yk_pin) / sizeof(*priv->yk_pin) - 1); i++) {
  ------------------
  |  Branch (4522:14): [True: 355, False: 0]
  ------------------
 4523|    355|		if (priv->yk_pin[i].slot == 0x00)
  ------------------
  |  Branch (4523:7): [True: 350, False: 5]
  ------------------
 4524|       |			/* reached the last initialized entry */
 4525|    350|			break;
 4526|       |
 4527|      5|		if (priv->yk_pin[i].slot == slot)
  ------------------
  |  Branch (4527:7): [True: 0, False: 5]
  ------------------
 4528|       |			/* metadata already initialized */
 4529|      0|			break;
 4530|      5|	}
 4531|       |
 4532|    350|	if (priv->yk_pin[i].slot == 0x00) {
  ------------------
  |  Branch (4532:6): [True: 350, False: 0]
  ------------------
 4533|       |		/* initialize this entry */
 4534|    350|		sc_format_apdu_ex(&apdu, 0x00, 0xF7, 0x00, slot, NULL, 0, resp, sizeof resp);
 4535|    350|		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|    350|#define SC_SUCCESS				0
  ------------------
              		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|    340|#define SC_SUCCESS				0
  ------------------
              		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|     61|#define SC_SUCCESS				0
  ------------------
  |  Branch (4535:7): [True: 340, False: 10]
  |  Branch (4535:54): [True: 61, False: 279]
  |  Branch (4535:109): [True: 8, False: 53]
  ------------------
 4536|      8|			sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4537|      8|					slot, priv->yk_pin[i].policy, priv->yk_pin[i].touch);
 4538|      8|			priv->yk_pin[i].slot = slot;
 4539|    342|		} else {
 4540|    342|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4541|    342|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    342|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4542|    342|		}
 4543|    350|	} else if (priv->yk_pin[i].slot != slot) {
  ------------------
  |  Branch (4543:13): [True: 0, False: 0]
  ------------------
 4544|      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__
  |  |  ------------------
  ------------------
 4545|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4546|      0|	}
 4547|       |
 4548|      8|	if (pin_policy)
  ------------------
  |  Branch (4548:6): [True: 8, False: 0]
  ------------------
 4549|      8|		*pin_policy = priv->yk_pin[i].policy;
 4550|      8|	if (touch_policy)
  ------------------
  |  Branch (4550:6): [True: 0, False: 8]
  ------------------
 4551|      0|		*touch_policy = priv->yk_pin[i].touch;
 4552|       |
 4553|      8|	return SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 4554|    350|}
card-piv.c:piv_yk_metadata_get_policy:
 4489|     61|{
 4490|     61|	size_t policylen;
 4491|     61|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4492|     61|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4492:6): [True: 12, False: 49]
  |  Branch (4492:16): [True: 8, False: 4]
  ------------------
 4493|      8|		*pin = policy[0];
 4494|      8|		*touch = policy[1];
 4495|      8|		return SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 4496|     53|	} else {
 4497|     53|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4498|     53|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     53|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4499|     53|	}
 4500|     61|}
card-piv.c:piv_check_sw:
 6167|  41.4k|{
 6168|  41.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6169|       |
 6170|  41.4k|	int r;
 6171|       |#ifdef ENABLE_PIV_SM
 6172|       |	int i;
 6173|       |#endif
 6174|  41.4k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  41.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6175|       |
 6176|  41.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  41.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  41.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  41.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 41.4k]
  |  |  ------------------
  ------------------
 6177|       |
 6178|       |	/* may be called before piv_init has allocated priv */
 6179|  41.4k|	if (priv) {
  ------------------
  |  Branch (6179:6): [True: 41.4k, False: 0]
  ------------------
 6180|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6181|       |
 6182|  41.4k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6182:7): [True: 1.48k, False: 39.9k]
  ------------------
 6183|  1.48k|			priv->pin_cmd_verify_sw1 = sw1;
 6184|  1.48k|			priv->pin_cmd_verify_sw2 = sw2;
 6185|  39.9k|		} else {
 6186|       |			/* a command has completed and it is not verify
 6187|       |			 * If we are in a context_specific sequence, unlock
 6188|       |			 * This just decrements the extra lock count
 6189|       |			 */
 6190|  39.9k|			if (priv->context_specific) {
  ------------------
  |  Branch (6190:8): [True: 0, False: 39.9k]
  ------------------
 6191|      0|				sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC 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__
  |  |  ------------------
  ------------------
 6192|      0|				priv->context_specific = 0;
 6193|      0|				sc_unlock(card);
 6194|      0|			}
 6195|  39.9k|		}
 6196|       |
 6197|  41.4k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  584|  41.4k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6197:7): [True: 13.6k, False: 27.7k]
  ------------------
 6198|       |
 6199|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6200|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6201|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6202|       |			 */
 6203|  13.6k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6203:8): [True: 599, False: 13.0k]
  |  Branch (6203:32): [True: 19, False: 580]
  ------------------
 6204|     19|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6205|     19|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6205:9): [True: 14, False: 5]
  ------------------
 6206|     14|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6207|     14|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     14|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6208|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6209|     14|				}
 6210|     19|			}
 6211|  13.6k|		}
 6212|  41.4k|	}
 6213|       |#ifdef ENABLE_PIV_SM
 6214|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6215|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6216|       |	/* we stashed the sw1 and sw2 above for verify */
 6217|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6218|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6219|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6220|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6221|       |			return piv_sm_errors[i].errorno;
 6222|       |		}
 6223|       |	}
 6224|       |#endif
 6225|  41.3k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6226|  41.3k|	return r;
 6227|  41.4k|}
card-piv.c:piv_card_ctl:
 4565|  70.1k|{
 4566|  70.1k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  70.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4567|  70.1k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4568|       |
 4569|  70.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  70.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  70.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  70.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  70.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 70.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4570|       |
 4571|  70.1k|	if (priv == NULL) {
  ------------------
  |  Branch (4571:6): [True: 0, False: 70.1k]
  ------------------
 4572|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4573|      0|	}
 4574|  70.1k|	switch (cmd) {
  ------------------
  |  Branch (4574:10): [True: 70.1k, False: 0]
  ------------------
 4575|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4575:2): [True: 0, False: 70.1k]
  ------------------
 4576|      0|		opts = (u8 *)ptr;
 4577|      0|		switch (*opts) {
  ------------------
  |  Branch (4577:11): [True: 0, False: 0]
  ------------------
 4578|      0|		case 'A':
  ------------------
  |  Branch (4578:3): [True: 0, False: 0]
  ------------------
 4579|      0|			return piv_general_external_authenticate(card,
 4580|      0|					*(opts + 1), *(opts + 2));
 4581|      0|			break;
 4582|      0|		case 'M':
  ------------------
  |  Branch (4582:3): [True: 0, False: 0]
  ------------------
 4583|      0|			return piv_general_mutual_authenticate(card,
 4584|      0|					*(opts + 1), *(opts + 2));
 4585|      0|			break;
 4586|      0|		}
 4587|      0|		break;
 4588|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4588:2): [True: 0, False: 70.1k]
  ------------------
 4589|      0|		return piv_generate_key(card,
 4590|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4591|      0|		break;
 4592|  1.20k|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4592:2): [True: 1.20k, False: 68.9k]
  ------------------
 4593|  1.20k|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4594|      0|		break;
 4595|  1.08k|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4595:2): [True: 1.08k, False: 69.1k]
  ------------------
 4596|  1.08k|		return piv_get_pin_preference(card, ptr);
 4597|      0|		break;
 4598|  67.5k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4598:2): [True: 67.5k, False: 2.67k]
  ------------------
 4599|  67.5k|		return piv_is_object_present(card, ptr);
 4600|      0|		break;
 4601|    381|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4601:2): [True: 381, False: 69.8k]
  ------------------
 4602|    381|		return piv_yk_pin_policy(card, ptr);
 4603|      0|		break;
 4604|  70.1k|	}
 4605|       |
 4606|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4607|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4369|  1.20k|{
 4370|  1.20k|	int r;
 4371|  1.20k|	int i;
 4372|  1.20k|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4373|  1.20k|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4374|  1.20k|	u8 *rbuf = NULL;
 4375|  1.20k|	const u8 *body;
 4376|  1.20k|	const u8 *fascn;
 4377|  1.20k|	const u8 *guid;
 4378|  1.20k|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4379|       |
 4380|  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]
  |  |  ------------------
  ------------------
 4381|  1.20k|	if (card->serialnr.len) {
  ------------------
  |  Branch (4381:6): [True: 49, False: 1.15k]
  ------------------
 4382|     49|		*serial = card->serialnr;
 4383|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4384|     49|	}
 4385|       |
 4386|       |	/*
 4387|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4388|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4389|       |	 * based on RFC 4122. If GUID present and not zero
 4390|       |	 * we will use the GUID as the serial number.
 4391|       |	 */
 4392|       |
 4393|  1.15k|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4394|  1.15k|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|  1.15k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.15k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.15k|	int _ret = (r); \
  |  |  |  |  168|  1.15k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 986, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  169|    986|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    986|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    986|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    986|		return _ret; \
  |  |  |  |  172|    986|	} \
  |  |  |  |  173|  1.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 169]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4395|       |
 4396|    169|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    169|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4397|    169|	if (rbuflen != 0) {
  ------------------
  |  Branch (4397:6): [True: 169, False: 0]
  ------------------
 4398|    169|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4399|    169|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4399:7): [True: 169, False: 0]
  |  Branch (4399:23): [True: 167, False: 2]
  |  Branch (4399:39): [True: 167, False: 0]
  ------------------
 4400|    167|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4401|       |
 4402|    167|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4402:8): [True: 124, False: 43]
  |  Branch (4402:17): [True: 119, False: 5]
  ------------------
 4403|  3.09k|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4403:17): [True: 2.97k, False: 119]
  ------------------
 4404|  2.97k|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4404:14): [True: 2.71k, False: 257]
  |  Branch (4404:23): [True: 118, False: 139]
  ------------------
 4405|  2.97k|				}
 4406|    119|			}
 4407|       |
 4408|    167|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4409|       |
 4410|    167|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4410:8): [True: 24, False: 143]
  |  Branch (4410:16): [True: 21, False: 3]
  ------------------
 4411|    357|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4411:17): [True: 336, False: 21]
  ------------------
 4412|    336|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4413|    336|				}
 4414|     21|			}
 4415|    167|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   71|    167|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4416|    167|					fascn, fascnlen, guid, guidlen, gbits);
 4417|       |
 4418|    167|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4418:8): [True: 124, False: 43]
  |  Branch (4418:17): [True: 119, False: 5]
  |  Branch (4418:35): [True: 118, False: 1]
  ------------------
 4419|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4420|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4421|    118|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4421:11): [True: 20, False: 98]
  |  Branch (4421:20): [True: 13, False: 7]
  |  Branch (4421:40): [True: 7, False: 6]
  ------------------
 4422|    115|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4422:11): [True: 4, False: 3]
  |  Branch (4422:31): [True: 3, False: 1]
  ------------------
 4423|       |					/* fascnlen is 25 */
 4424|    115|					serial->len = fascnlen;
 4425|    115|					memcpy(serial->value, fascn, serial->len);
 4426|    115|					r = SC_SUCCESS;
  ------------------
  |  |   28|    115|#define SC_SUCCESS				0
  ------------------
 4427|    115|					gbits = 0; /* set to skip using guid below */
 4428|    115|				}
 4429|    118|			}
 4430|    167|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4430:8): [True: 24, False: 143]
  |  Branch (4430:16): [True: 21, False: 3]
  |  Branch (4430:33): [True: 4, False: 17]
  ------------------
 4431|      4|				serial->len = guidlen;
 4432|      4|				memcpy(serial->value, guid, serial->len);
 4433|      4|				r = SC_SUCCESS;
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
 4434|      4|			}
 4435|    167|		}
 4436|    169|	}
 4437|       |
 4438|    169|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4438:6): [True: 51, False: 118]
  |  Branch (4438:20): [True: 50, False: 1]
  ------------------
 4439|     50|		serial->len = 16;
 4440|     50|		memset(serial->value, 0x00, serial->len);
 4441|     50|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     50|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4442|     50|	}
 4443|       |
 4444|    169|	card->serialnr = *serial;
 4445|    169|	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|     50|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 50, False: 119]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4446|    169|}
card-piv.c:piv_get_pin_preference:
 4480|  1.08k|{
 4481|  1.08k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.08k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4482|       |
 4483|  1.08k|	*pin_ref = priv->pin_preference;
 4484|  1.08k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4485|  1.08k|}
card-piv.c:piv_is_object_present:
 4461|  67.5k|{
 4462|  67.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  67.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4463|  67.5k|	int r = 0;
 4464|  67.5k|	int enumtag;
 4465|       |
 4466|  67.5k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4467|  67.5k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  66.4k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4467:6): [True: 66.4k, False: 1.08k]
  |  Branch (4467:22): [True: 42.9k, False: 23.5k]
  ------------------
 4468|  42.9k|		r = 1;
 4469|       |
 4470|  67.5k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  67.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  67.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  67.5k|	int _ret = r; \
  |  |  |  |  155|  67.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24.6k, False: 42.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|  24.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: 24.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  24.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  42.9k|	} else { \
  |  |  |  |  159|  42.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  42.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  42.9k|	} \
  |  |  |  |  162|  67.5k|	return _ret; \
  |  |  |  |  163|  67.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4471|  67.5k|}
card-piv.c:piv_yk_pin_policy:
 4558|    381|{
 4559|    381|	u8 slot = *ptr;
 4560|    381|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL));
  ------------------
  |  |  164|    381|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|    373|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 373, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4561|    381|}
card-piv.c:piv_pin_cmd:
 6300|    943|{
 6301|    943|	int r = 0;
 6302|    943|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    943|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6303|       |
 6304|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6305|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6306|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6307|       |	 */
 6308|    943|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6309|       |
 6310|    943|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    943|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    943|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    943|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 943]
  |  |  ------------------
  ------------------
 6311|    943|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6312|    943|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|    943|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6312:6): [True: 124, False: 819]
  ------------------
 6313|    124|		size_t i = 0;
 6314|    124|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6314:7): [True: 24, False: 100]
  ------------------
 6315|     24|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     24|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6316|     24|		}
 6317|    648|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6317:15): [True: 561, False: 87]
  ------------------
 6318|    561|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6318:8): [True: 13, False: 548]
  ------------------
 6319|     13|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     13|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6320|     13|			}
 6321|    561|		}
 6322|    100|	}
 6323|       |
 6324|    906|	priv->pin_cmd_verify_sw1 = 0x00U;
 6325|       |
 6326|    906|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|    906|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6326:6): [True: 768, False: 138]
  ------------------
 6327|    768|		data->pin1.logged_in = priv->logged_in;
 6328|    768|		data->pin1.tries_left = priv->tries_left;
 6329|       |
 6330|       |		/*
 6331|       |		 * If called to check on the login state for a context specific login
 6332|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6333|       |		 */
 6334|    768|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    768|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6334:7): [True: 0, False: 768]
  ------------------
 6335|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6336|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6337|      0|		}
 6338|       |
 6339|    768|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|    768|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6339:7): [True: 23, False: 745]
  ------------------
 6340|       |			/* Avoid status requests when the user is logged in to handle NIST
 6341|       |			 * 800-73-4 Part 2:
 6342|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6343|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6344|       |			 * PIN or OCC data must be submitted and verified every time
 6345|       |			 * immediately before a digital signature key operation.  This
 6346|       |			 * ensures cardholder participation every time the private key is
 6347|       |			 * used for digital signature generation */
 6348|     23|			LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6349|     23|		}
 6350|    768|	}
 6351|       |
 6352|       |	/*
 6353|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6354|       |	 * to avoid any interference from other applications.
 6355|       |	 * Sc_unlock will be called at a later time after the next card command
 6356|       |	 * that should be a crypto operation. If its not then it is a error by the
 6357|       |	 * calling application.
 6358|       |	 */
 6359|    883|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|  1.76k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|     50|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6359:6): [True: 50, False: 833]
  |  Branch (6359:40): [True: 0, False: 50]
  ------------------
 6360|      0|		priv->context_specific = 1;
 6361|      0|		sc_log(card->ctx, "Starting CONTEXT_SPECIFIC verify");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6362|      0|		r = sc_lock(card);
 6363|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6363:7): [True: 0, False: 0]
  ------------------
 6364|      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__
  |  |  ------------------
  ------------------
 6365|      0|			return r;
 6366|      0|		}
 6367|      0|	}
 6368|       |
 6369|    883|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6370|    883|	r = iso_drv->ops->pin_cmd(card, data);
 6371|    883|	priv->pin_cmd_verify = 0;
 6372|       |
 6373|       |	/* tell user verify not supported on contactless without VCI */
 6374|    883|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6374:6): [True: 12, False: 871]
  |  Branch (6374:42): [True: 3, False: 9]
  ------------------
 6375|      3|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|    886|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6375:4): [True: 0, False: 3]
  ------------------
 6376|      0|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6376:4): [True: 0, False: 0]
  ------------------
 6377|      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__
  |  |  ------------------
  ------------------
 6378|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6379|      0|	}
 6380|       |
 6381|       |	/* if verify failed, release the lock */
 6382|    883|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|  1.76k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6382:6): [True: 50, False: 833]
  |  Branch (6382:40): [True: 46, False: 4]
  |  Branch (6382:49): [True: 0, False: 46]
  ------------------
 6383|      0|		sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6384|      0|		priv->context_specific = 0;
 6385|      0|		sc_unlock(card);
 6386|      0|	}
 6387|       |
 6388|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6389|    883|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  593|  1.76k|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6389:6): [True: 788, False: 95]
  |  Branch (6389:53): [True: 642, False: 146]
  ------------------
 6390|    642|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|    642|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6391|    642|		piv_find_aid(card);
 6392|       |
 6393|    642|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6394|    642|		r = iso_drv->ops->pin_cmd(card, data);
 6395|    642|		priv->pin_cmd_verify = 0;
 6396|    642|	}
 6397|       |
 6398|       |	/* If verify worked, we are logged_in */
 6399|    883|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|    883|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6399:6): [True: 50, False: 833]
  ------------------
 6400|     50|		if (r >= 0)
  ------------------
  |  Branch (6400:7): [True: 6, False: 44]
  ------------------
 6401|      6|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      6|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6402|     44|		else
 6403|     44|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     44|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6404|     50|	}
 6405|       |
 6406|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6407|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6408|       |
 6409|    883|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|    883|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6409:6): [True: 745, False: 138]
  ------------------
 6410|    745|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  588|    745|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6410:7): [True: 20, False: 725]
  ------------------
 6411|     20|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6412|     20|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6413|    725|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  585|  1.45k|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6413:14): [True: 357, False: 368]
  ------------------
 6414|    357|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6414:5): [True: 22, False: 335]
  ------------------
 6415|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6416|     22|			r = piv_check_protected_objects(card);
 6417|     22|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  |  Branch (6417:8): [True: 0, False: 22]
  ------------------
 6418|      0|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6419|     22|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     22|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6419:13): [True: 19, False: 3]
  ------------------
 6420|     19|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  588|     19|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6420:9): [True: 11, False: 8]
  ------------------
 6421|       |
 6422|     11|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6423|     11|				} else {
 6424|      8|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      8|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6425|      8|				}
 6426|     19|				r = SC_SUCCESS;
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
 6427|     19|			}
 6428|     22|		}
 6429|    745|		priv->logged_in = data->pin1.logged_in;
 6430|    745|		priv->tries_left = data->pin1.tries_left;
 6431|    745|	}
 6432|       |
 6433|    883|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|    883|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6434|    883|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    883|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    883|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    883|	int _ret = r; \
  |  |  |  |  155|    883|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 883, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    883|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    820|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 820, False: 63]
  |  |  |  |  ------------------
  |  |  |  |  157|    883|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    883|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    883|	return _ret; \
  |  |  |  |  163|    883|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6435|    883|}
card-piv.c:piv_check_protected_objects:
 6231|     22|{
 6232|     22|	int r = 0;
 6233|     22|	int i;
 6234|     22|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     22|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6235|     22|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6236|     22|	u8 *rbuf;
 6237|     22|	size_t buf_len;
 6238|     22|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6239|       |
 6240|     22|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6241|       |	/*
 6242|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6243|       |	 * We will test for a protected object using GET DATA.
 6244|       |	 *
 6245|       |	 * Based on observations, of cards using the GET DATA APDU,
 6246|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6247|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6248|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6249|       |	 * about the state of the PIN and we will try the next object.
 6250|       |	 *
 6251|       |	 * If we can't determine the security state from this process,
 6252|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6253|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6254|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6255|       |	 * so we will have an object to test.
 6256|       |	 *
 6257|       |	 * We save the object's number to use in the future.
 6258|       |	 *
 6259|       |	 */
 6260|     22|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6260:6): [True: 17, False: 5]
  ------------------
 6261|     57|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6261:15): [True: 46, False: 11]
  ------------------
 6262|     46|			buf_len = sizeof(buf);
 6263|     46|			rbuf = buf;
 6264|     46|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6265|     46|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     46|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6265:8): [True: 0, False: 46]
  |  Branch (6265:18): [True: 6, False: 40]
  ------------------
 6266|       |
 6267|       |				/* we can use this object next time if needed */
 6268|      6|				priv->object_test_verify = protected_objects[i];
 6269|      6|				break;
 6270|      6|			}
 6271|     46|		}
 6272|     17|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6272:7): [True: 11, False: 6]
  ------------------
 6273|       |			/*
 6274|       |			 * none of the objects returned acceptable sw1, sw2
 6275|       |			 */
 6276|     11|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6277|     11|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  588|     11|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6278|     11|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     11|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6279|     11|		}
 6280|     17|	} else {
 6281|       |		/* use the one object we found earlier. Test is security status has changed */
 6282|      5|		buf_len = sizeof(buf);
 6283|      5|		rbuf = buf;
 6284|      5|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6285|      5|	}
 6286|     22|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|     22|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6286:6): [True: 1, False: 21]
  ------------------
 6287|      1|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6288|     21|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|     21|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6288:11): [True: 7, False: 14]
  ------------------
 6289|      7|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      7|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6290|     14|	else if (r > 0)
  ------------------
  |  Branch (6290:11): [True: 0, False: 14]
  ------------------
 6291|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 6292|       |
 6293|     22|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\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__
  |  |  ------------------
  ------------------
 6294|     22|			card->type, priv->card_issues, r, priv->alg_ids);
 6295|     22|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6296|     22|}
card-piv.c:piv_card_reader_lock_obtained:
 6474|  15.5k|{
 6475|  15.5k|	int r = 0;
 6476|  15.5k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6477|  15.5k|	size_t templen = sizeof(temp);
 6478|  15.5k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  440|  15.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6479|       |
 6480|  15.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.5k]
  |  |  ------------------
  ------------------
 6481|       |
 6482|       |	/* We have a PCSC transaction and sc_lock */
 6483|  15.5k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6483:6): [True: 4.36k, False: 11.2k]
  |  Branch (6483:22): [True: 1.09k, False: 10.1k]
  ------------------
 6484|  5.46k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  10.9k|#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: 1.09k, False: 4.36k]
  |  |  ------------------
  ------------------
 6485|  5.46k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6486|  5.46k|		r = 0; /* do nothing, piv_match will take care of it */
 6487|  5.46k|		goto err;
 6488|  5.46k|	}
 6489|       |
 6490|  10.1k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  10.1k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6491|       |
 6492|       |	/* make sure our application is active */
 6493|       |
 6494|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6495|       |	/* If not try selecting AID */
 6496|       |
 6497|       |	/* but if card does not support DISCOVERY object we can not use it */
 6498|  10.1k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  590|  10.1k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6498:6): [True: 1.49k, False: 8.63k]
  ------------------
 6499|  1.49k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  1.49k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6500|  8.63k|	} else {
 6501|  8.63k|		r = piv_find_discovery(card);
 6502|       |#ifdef ENABLE_PIV_SM
 6503|       |		/*
 6504|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6505|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6506|       |		 * Discovery object can be read with contact or contactless
 6507|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6508|       |		 * sm.c will close the SM connectrion, and set defer
 6509|       |		 */
 6510|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6511|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6512|       |			piv_sm_open(card);
 6513|       |			r = piv_find_discovery(card);
 6514|       |		}
 6515|       |#endif /* ENABLE_PIV_SM */
 6516|  8.63k|	}
 6517|       |
 6518|  10.1k|	if (r < 0) {
  ------------------
  |  Branch (6518:6): [True: 10.0k, False: 112]
  ------------------
 6519|  10.0k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  591|  10.0k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6519:7): [True: 0, False: 10.0k]
  |  Branch (6519:24): [True: 9.58k, False: 437]
  ------------------
 6520|  9.58k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6521|  9.58k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  9.58k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6522|  9.58k|		} else {
 6523|    437|			r = 0; /* can't do anything with this card, hope there was no interference */
 6524|    437|		}
 6525|  10.0k|	}
 6526|       |
 6527|  10.1k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6527:6): [True: 8.98k, False: 1.14k]
  ------------------
 6528|  8.98k|		goto err;
 6529|       |
 6530|  1.14k|	if (was_reset > 0)
  ------------------
  |  Branch (6530:6): [True: 0, False: 1.14k]
  ------------------
 6531|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6532|       |
 6533|  1.14k|	r = 0;
 6534|       |
 6535|  15.5k|err:
 6536|  15.5k|	if (priv)
  ------------------
  |  Branch (6536:6): [True: 11.2k, False: 4.36k]
  ------------------
 6537|  11.2k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  11.2k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6538|  15.5k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  15.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.5k|	int _ret = r; \
  |  |  |  |  155|  15.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.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|  8.98k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.98k, False: 6.60k]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.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|  15.5k|	return _ret; \
  |  |  |  |  163|  15.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6539|  15.5k|}

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

sc_get_rutoken_driver:
 1320|  8.50k|{
 1321|  8.50k|	return get_rutoken_driver();
 1322|  8.50k|}
card-rutoken.c:get_rutoken_driver:
 1281|  8.50k|{
 1282|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1282:6): [True: 1, False: 8.49k]
  ------------------
 1283|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1284|  8.50k|	rutoken_ops = *iso_ops;
 1285|       |
 1286|  8.50k|	rutoken_ops.match_card = rutoken_match_card;
 1287|  8.50k|	rutoken_ops.init = rutoken_init;
 1288|  8.50k|	rutoken_ops.finish = rutoken_finish;
 1289|       |	/* read_binary */
 1290|  8.50k|	rutoken_ops.write_binary = NULL;
 1291|       |	/* update_binary */
 1292|  8.50k|	rutoken_ops.read_record = NULL;
 1293|  8.50k|	rutoken_ops.write_record = NULL;
 1294|  8.50k|	rutoken_ops.append_record = NULL;
 1295|  8.50k|	rutoken_ops.update_record = NULL;
 1296|  8.50k|	rutoken_ops.select_file = rutoken_select_file;
 1297|  8.50k|	rutoken_ops.get_response = NULL;
 1298|  8.50k|	rutoken_ops.get_challenge = rutoken_get_challenge;
 1299|  8.50k|	rutoken_ops.verify = rutoken_verify;
 1300|  8.50k|	rutoken_ops.logout = rutoken_logout;
 1301|  8.50k|	rutoken_ops.restore_security_env = rutoken_restore_security_env;
 1302|  8.50k|	rutoken_ops.set_security_env = rutoken_set_security_env;
 1303|  8.50k|	rutoken_ops.decipher = NULL;
 1304|  8.50k|	rutoken_ops.compute_signature = rutoken_compute_signature;
 1305|  8.50k|	rutoken_ops.change_reference_data = rutoken_change_reference_data;
 1306|  8.50k|	rutoken_ops.reset_retry_counter = rutoken_reset_retry_counter;
 1307|  8.50k|	rutoken_ops.create_file = rutoken_create_file;
 1308|  8.50k|	rutoken_ops.delete_file = rutoken_delete_file;
 1309|  8.50k|	rutoken_ops.list_files = rutoken_list_files;
 1310|  8.50k|	rutoken_ops.check_sw = rutoken_check_sw;
 1311|  8.50k|	rutoken_ops.card_ctl = rutoken_card_ctl;
 1312|  8.50k|	rutoken_ops.process_fci = rutoken_process_fci;
 1313|  8.50k|	rutoken_ops.construct_fci = rutoken_construct_fci;
 1314|  8.50k|	rutoken_ops.pin_cmd = NULL;
 1315|       |
 1316|  8.50k|	return &rutoken_drv;
 1317|  8.50k|}
card-rutoken.c:rutoken_match_card:
  103|  6.54k|{
  104|  6.54k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.54k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.54k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.54k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.54k]
  |  |  ------------------
  ------------------
  105|  6.54k|	if (_sc_match_atr(card, rutoken_atrs, &card->type) >= 0)
  ------------------
  |  Branch (105:6): [True: 0, False: 6.54k]
  ------------------
  106|      0|	{
  107|      0|		sc_log(card->ctx,  "ATR recognized as Rutoken\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__
  |  |  ------------------
  ------------------
  108|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|      0|	}
  110|  6.54k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  6.54k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.54k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.54k|	int _ret = r; \
  |  |  |  |  155|  6.54k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.54k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.54k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.54k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.54k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.54k|	} else { \
  |  |  |  |  159|      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.54k|	return _ret; \
  |  |  |  |  163|  6.54k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  111|  6.54k|}

sc_get_sc_hsm_driver:
 1978|  8.50k|{
 1979|  8.50k|	return sc_get_driver();
 1980|  8.50k|}
card-sc-hsm.c:sc_get_driver:
 1942|  8.50k|{
 1943|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1944|       |
 1945|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1945:6): [True: 1, False: 8.49k]
  ------------------
 1946|      1|		iso_ops = iso_drv->ops;
 1947|       |
 1948|  8.50k|	sc_hsm_ops                   = *iso_drv->ops;
 1949|  8.50k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1950|  8.50k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1951|  8.50k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1952|  8.50k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1953|  8.50k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1954|  8.50k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1955|  8.50k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1956|  8.50k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1957|  8.50k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1958|  8.50k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1959|  8.50k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1960|  8.50k|	sc_hsm_ops.init              = sc_hsm_init;
 1961|  8.50k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1962|  8.50k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1963|  8.50k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1964|  8.50k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1965|       |
 1966|       |	/* no record oriented file services */
 1967|  8.50k|	sc_hsm_ops.read_record       = NULL;
 1968|  8.50k|	sc_hsm_ops.write_record      = NULL;
 1969|  8.50k|	sc_hsm_ops.append_record     = NULL;
 1970|  8.50k|	sc_hsm_ops.update_record     = NULL;
 1971|       |
 1972|  8.50k|	return &sc_hsm_drv;
 1973|  8.50k|}
card-sc-hsm.c:sc_hsm_match_card:
  267|  4.66k|{
  268|  4.66k|	sc_path_t path;
  269|  4.66k|	int i, r, type = 0;
  270|  4.66k|	sc_file_t *file = NULL;
  271|       |
  272|  4.66k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  273|  4.66k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (273:6): [True: 132, False: 4.53k]
  |  Branch (273:16): [True: 131, False: 1]
  ------------------
  274|    131|		card->type = type;
  275|    131|		return 1;
  276|    131|	}
  277|       |
  278|  4.53k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  4.53k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  279|  4.53k|	r = sc_hsm_select_file(card, &path, &file);
  280|  4.53k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  4.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.53k|	int _ret = (r); \
  |  |  |  |  168|  4.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.40k, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.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|  4.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.40k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.40k|		return _ret; \
  |  |  |  |  172|  4.40k|	} \
  |  |  |  |  173|  4.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|       |
  282|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  283|    130|	if (file != NULL) {
  ------------------
  |  Branch (283:6): [True: 130, False: 0]
  ------------------
  284|    130|		size_t sz = file->prop_attr_len;
  285|    130|		sc_file_free(file);
  286|    130|		if (sz < 2) {
  ------------------
  |  Branch (286:7): [True: 128, False: 2]
  ------------------
  287|    128|			return 0;
  288|    128|		}
  289|    130|	}
  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|    130|}
card-sc-hsm.c:sc_hsm_select_file:
  247|  5.52k|{
  248|  5.52k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  249|  5.52k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  149|  6.16k|{
  150|  6.16k|	int rv;
  151|  6.16k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  152|  6.16k|	sc_file_t *file = NULL;
  153|  6.16k|	sc_path_t cpath;
  154|  6.16k|	size_t card_max_recv_size = card->max_recv_size;
  155|  6.16k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  156|       |
  157|  6.16k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (157:6): [True: 502, False: 5.65k]
  ------------------
  158|    502|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  159|    502|		sc_file_free(file);
  160|    502|		return rv;
  161|    502|	}
  162|       |
  163|  5.65k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  5.65k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (163:6): [True: 74, False: 5.58k]
  |  Branch (163:49): [True: 0, False: 74]
  ------------------
  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|  5.65k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  11.3k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (180:6): [True: 5.02k, False: 638]
  ------------------
  181|    638|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  1.27k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (181:8): [True: 564, False: 74]
  ------------------
  182|    564|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (182:8): [True: 0, False: 564]
  ------------------
  183|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (183:8): [True: 0, False: 0]
  ------------------
  184|    638|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  1.27k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:8): [True: 564, False: 74]
  ------------------
  185|    564|				&& in_path->len == 0
  ------------------
  |  Branch (185:8): [True: 0, False: 564]
  ------------------
  186|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  5.02k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (187:8): [True: 0, False: 0]
  ------------------
  188|  5.02k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (188:7): [True: 4.53k, False: 489]
  |  Branch (188:16): [True: 370, False: 119]
  |  Branch (188:41): [True: 0, False: 119]
  ------------------
  189|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  190|  4.90k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|  4.90k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  191|  4.90k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  192|  4.90k|			card->max_recv_size = card_max_recv_size;
  193|  4.90k|			card->reader->max_recv_size = reader_max_recv_size;
  194|  4.90k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  4.90k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.90k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.90k|	int _ret = (r); \
  |  |  |  |  168|  4.90k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.66k, False: 237]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.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|  4.66k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.66k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.66k|		return _ret; \
  |  |  |  |  172|  4.66k|	} \
  |  |  |  |  173|  4.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 237]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    237|			if (priv) {
  ------------------
  |  Branch (196:8): [True: 107, False: 130]
  ------------------
  197|    107|				sc_file_free(priv->dffcp);
  198|       |				// Cache the FCP returned when selecting the applet
  199|    107|				sc_file_dup(&priv->dffcp, *file_out);
  200|    107|			}
  201|    237|		} else {
  202|    119|			sc_file_dup(file_out, priv->dffcp);
  203|    119|			rv = SC_SUCCESS;
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
  204|    119|		}
  205|    356|		return rv;
  206|  5.02k|	}
  207|       |
  208|    638|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (208:6): [True: 638, False: 0]
  |  Branch (208:29): [True: 385, False: 253]
  |  Branch (208:60): [True: 385, False: 0]
  ------------------
  209|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  210|    385|		if (in_path->len == 2) {
  ------------------
  |  Branch (210:7): [True: 0, False: 385]
  ------------------
  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;
  ------------------
  |  |   57|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  218|       |
  219|      0|			*file_out = file;
  220|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  221|    385|		} else {
  222|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  223|    385|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    385|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  224|    385|			sc_path_t truncated;
  225|    385|			memcpy(&truncated, in_path, sizeof truncated);
  226|    385|			truncated.len = in_path->len - 2;
  227|    385|			memcpy(truncated.value, in_path->value+2, truncated.len);
  228|    385|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  229|    385|			card->max_recv_size = card_max_recv_size;
  230|    385|			card->reader->max_recv_size = reader_max_recv_size;
  231|    385|			return rv;
  232|    385|		}
  233|    385|	}
  234|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  235|    253|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    253|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  236|    253|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  237|    253|	card->max_recv_size = card_max_recv_size;
  238|    253|	card->reader->max_recv_size = reader_max_recv_size;
  239|    253|	return rv;
  240|    638|}
card-sc-hsm.c:sc_hsm_read_binary:
  799|    392|{
  800|    392|	sc_context_t *ctx = card->ctx;
  801|    392|	sc_apdu_t apdu;
  802|    392|	u8 cmdbuff[4];
  803|    392|	int r;
  804|       |
  805|    392|	if (idx > 0xffff) {
  ------------------
  |  Branch (805:6): [True: 0, False: 392]
  ------------------
  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|    392|	cmdbuff[0] = 0x54;
  811|    392|	cmdbuff[1] = 0x02;
  812|    392|	cmdbuff[2] = (idx >> 8) & 0xFF;
  813|    392|	cmdbuff[3] = idx & 0xFF;
  814|       |
  815|    392|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (815:6): [True: 0, False: 392]
  ------------------
  816|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  817|    392|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    392|#define SC_APDU_CASE_4			0x24
  ------------------
  818|    392|	apdu.data = cmdbuff;
  819|    392|	apdu.datalen = 4;
  820|    392|	apdu.lc = 4;
  821|    392|	apdu.le = count;
  822|    392|	apdu.resplen = count;
  823|    392|	apdu.resp = buf;
  824|       |
  825|    392|	r = sc_transmit_apdu(card, &apdu);
  826|    392|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    392|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    392|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    392|	int _ret = (r); \
  |  |  |  |  168|    392|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 379]
  |  |  |  |  ------------------
  |  |  |  |  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|    392|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 379]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    379|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  829|    379|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    379|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (829:6): [True: 373, False: 6]
  ------------------
  830|    373|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    373|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    373|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    373|	int _ret = (r); \
  |  |  |  |  168|    373|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 334]
  |  |  |  |  ------------------
  |  |  |  |  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|    373|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 334]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|    373|	}
  832|       |
  833|    340|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 6, False: 334]
  |  |  |  |  ------------------
  |  |  |  |  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|    334|	} else { \
  |  |  |  |  159|    334|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    334|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    334|	} \
  |  |  |  |  162|    340|	return _ret; \
  |  |  |  |  163|    340|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    340|}
card-sc-hsm.c:sc_hsm_init:
 1777|    133|{
 1778|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1779|       |	char expanded_val[PATH_MAX];
 1780|       |	size_t expanded_len = PATH_MAX;
 1781|       |#endif
 1782|    133|	int flags,ext_flags;
 1783|    133|	sc_file_t *file = NULL;
 1784|    133|	sc_path_t path;
 1785|    133|	sc_hsm_private_data_t *priv = NULL;
 1786|       |
 1787|    133|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    133|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    133|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    133|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    133|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 133]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1788|       |
 1789|    133|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    133|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  107|    133|#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|    133|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1790|    133|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  134|    133|#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|    133|#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|    133|#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|    133|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1791|    133|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  146|    133|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  147|    133|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  148|    133|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1792|       |
 1793|    133|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1794|    133|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1795|    133|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1796|    133|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1797|    133|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1798|       |
 1799|    133|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|    133|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1800|    133|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|    133|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1801|    133|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|    133|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    133|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1802|    133|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  176|    133|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    133|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1803|    133|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  177|    133|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|    133|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1804|    133|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  178|    133|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    133|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1805|    133|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  179|    133|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|    133|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1806|    133|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  180|    133|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|    133|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1807|    133|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    133|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1808|       |
 1809|    133|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  198|    133|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1810|    133|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  200|    133|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1811|    133|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  201|    133|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1812|    133|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  202|    133|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1813|    133|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    133|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1814|    133|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1815|    133|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1816|    133|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1817|    133|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1818|    133|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1819|    133|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1820|    133|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1821|       |
 1822|    133|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    133|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|    133|#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|    133|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1823|       |
 1824|       |	// APDU Size limits
 1825|       |	//   JCOP 2.4.1r3           1462
 1826|       |	//   JCOP 2.4.2r3           1454
 1827|       |	//   JCOP 3                 1232
 1828|       |	//   JCOP 4                 1454
 1829|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1830|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1831|       |	//
 1832|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1833|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1834|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1835|       |	// class 3 APDU
 1836|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1837|       |
 1838|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1839|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1840|    133|	card->max_send_size = 1232 - 9;
 1841|       |	// Assume that card supports sending with extended length APDU and without limit
 1842|    133|	card->max_recv_size = 0;
 1843|       |
 1844|    133|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1844:6): [True: 0, False: 133]
  ------------------
 1845|    133|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1845:7): [True: 131, False: 2]
  ------------------
 1846|    131|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1847|    131|	} else {
 1848|       |		// Adjust to the limits set by the reader
 1849|      2|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1849:7): [True: 2, False: 0]
  ------------------
 1850|      2|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1850:8): [True: 2, False: 0]
  ------------------
 1851|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1852|       |
 1853|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1854|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1855|      0|		}
 1856|       |
 1857|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1857:7): [True: 0, False: 0]
  ------------------
 1858|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1858:8): [True: 0, False: 0]
  ------------------
 1859|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1860|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1861|      0|		}
 1862|      0|	}
 1863|       |
 1864|    131|	priv = card->drv_data;
 1865|    131|	if (!priv) {
  ------------------
  |  Branch (1865:6): [True: 131, False: 0]
  ------------------
 1866|    131|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1867|    131|		if (!priv)
  ------------------
  |  Branch (1867:7): [True: 0, False: 131]
  ------------------
 1868|    131|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1869|    131|		card->drv_data = priv;
 1870|    131|	}
 1871|       |
 1872|    131|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    131|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1873|    131|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    262|#define SC_SUCCESS				0
  ------------------
  |  Branch (1873:6): [True: 18, False: 113]
  ------------------
 1874|     18|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1874:7): [True: 18, False: 0]
  |  Branch (1874:15): [True: 10, False: 8]
  |  Branch (1874:34): [True: 9, False: 1]
  ------------------
 1875|      9|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1876|      9|		u8 type = 0xFF;
 1877|      9|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1878|      9|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1879|      9|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1880|      9|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1881|      9|		char *p = "SmartCard-HSM";
 1882|      9|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1882:7): [True: 8, False: 1]
  ------------------
 1883|      8|			type = file->prop_attr[file->prop_attr_len - 3];
 1884|      8|		}
 1885|      9|		switch (type) {
 1886|      5|			case 0x00:
  ------------------
  |  Branch (1886:4): [True: 5, False: 4]
  ------------------
 1887|      5|				p = p00;
 1888|      5|				break;
 1889|      1|			case 0x01:
  ------------------
  |  Branch (1889:4): [True: 1, False: 8]
  ------------------
 1890|      1|				p = p01;
 1891|      1|				break;
 1892|      3|			default:
  ------------------
  |  Branch (1892:4): [True: 3, False: 6]
  ------------------
 1893|      3|				break;
 1894|      9|		}
 1895|      9|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1896|      9|		card->name = card_name;
 1897|       |
 1898|      9|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1898:7): [True: 5, False: 4]
  ------------------
 1899|      5|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  563|      5|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1900|      5|		}
 1901|      9|	}
 1902|    131|	sc_file_free(file);
 1903|       |
 1904|    131|	priv->EF_C_DevAut = NULL;
 1905|    131|	priv->EF_C_DevAut_len = 0;
 1906|       |
 1907|    131|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1908|    131|	EAC_init();
 1909|       |#ifdef _WIN32
 1910|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1911|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1912|       |		EAC_set_cvc_default_dir(expanded_val);
 1913|       |#else
 1914|    131|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    131|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1915|    131|#endif
 1916|    131|#endif
 1917|       |
 1918|    131|	return 0;
 1919|    131|}
card-sc-hsm.c:sc_hsm_finish:
 1924|    131|{
 1925|    131|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1926|    131|#ifdef ENABLE_SM
 1927|    131|	sc_sm_stop(card);
 1928|    131|#endif
 1929|    131|	if (priv) {
  ------------------
  |  Branch (1929:6): [True: 131, False: 0]
  ------------------
 1930|    131|		free(priv->serialno);
 1931|    131|		sc_file_free(priv->dffcp);
 1932|    131|		free(priv->EF_C_DevAut);
 1933|    131|	}
 1934|    131|	free(priv);
 1935|       |
 1936|    131|	return SC_SUCCESS;
  ------------------
  |  |   28|    131|#define SC_SUCCESS				0
  ------------------
 1937|    131|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1748|     71|{
 1749|     71|	switch (cmd) {
  ------------------
  |  Branch (1749:10): [True: 71, False: 0]
  ------------------
 1750|     71|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1750:2): [True: 71, False: 0]
  ------------------
 1751|     71|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1752|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1752:2): [True: 0, False: 71]
  ------------------
 1753|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1754|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1754:2): [True: 0, False: 71]
  ------------------
 1755|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1756|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1756:2): [True: 0, False: 71]
  ------------------
 1757|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1758|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1758:2): [True: 0, False: 71]
  ------------------
 1759|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1760|      0|	case SC_CARDCTL_SC_HSM_IMPORT_DKEK_SHARE:
  ------------------
  |  Branch (1760:2): [True: 0, False: 71]
  ------------------
 1761|      0|		return sc_hsm_import_dkek_share(card, (sc_cardctl_sc_hsm_dkek_t *)ptr);
 1762|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1762:2): [True: 0, False: 71]
  ------------------
 1763|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1764|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1764:2): [True: 0, False: 71]
  ------------------
 1765|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1766|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1766:2): [True: 0, False: 71]
  ------------------
 1767|      0|		return sc_hsm_register_public_key(card, ptr);
 1768|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1768:2): [True: 0, False: 71]
  ------------------
 1769|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1770|     71|	}
 1771|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1772|     71|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1195|     71|{
 1196|     71|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1197|       |
 1198|     71|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     71|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     71|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     71|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     71|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|       |
 1200|     71|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1200:6): [True: 71, False: 0]
  |  Branch (1200:25): [True: 0, False: 71]
  ------------------
 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|     71|	if (!priv->serialno) {
  ------------------
  |  Branch (1210:6): [True: 71, False: 0]
  ------------------
 1211|     71|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|     71|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1212|     71|	}
 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|    115|{
  621|    115|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|    115|	sc_apdu_t apdu;
  623|    115|	u8 cmdbuff[16];
  624|    115|#ifdef ENABLE_SM
  625|    115|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|    115|#endif
  627|    115|	int r;
  628|    115|	int cmd = data->cmd;
  629|    115|	size_t pin2_len = data->pin2.len;
  630|       |
  631|    115|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|    115|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 115]
  ------------------
  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|    115|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    115|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 115]
  ------------------
  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|    115|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    115|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 115]
  ------------------
  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|    115|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|    115|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 115]
  ------------------
  655|    115|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 115, 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|    115|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  418|    115|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 11, False: 104]
  ------------------
  658|     11|		struct sc_pin_cmd_data check_sm_pin_data;
  659|     11|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|     11|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     11|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|     11|		check_sm_pin_data.pin_type = data->pin_type;
  662|     11|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|     11|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     11|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|     11|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|     11|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 11]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  668|      0|		}
  669|     11|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|     22|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|     11|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 11]
  |  Branch (669:46): [True: 11, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|     11|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|     11|					sc_hsm_perform_chip_authentication(card),
  673|     11|					"Could not perform chip authentication");
  674|     11|		}
  675|     11|	}
  676|    104|#endif
  677|       |
  678|    104|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    104|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 104]
  ------------------
  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|    104|	} else {
  684|    104|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  415|    104|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 104]
  |  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|    104|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  416|    104|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 104]
  |  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|    104|#ifdef ENABLE_SM
  714|    104|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|    104|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 104, False: 0]
  ------------------
  715|    104|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|    104|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 104]
  ------------------
  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|    104|#endif
  723|       |
  724|    104|		data->pin1.offset = 5;
  725|    104|		data->pin2.offset = 5;
  726|       |
  727|    104|		r = (*iso_ops->pin_cmd)(card, data);
  728|    104|		data->apdu = NULL;
  729|    104|	}
  730|    104|	LOG_TEST_RET(card->ctx, r, "Verification 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: 57, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  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|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|     47|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|     47|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (732:6): [True: 0, False: 47]
  ------------------
  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|     47|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     47|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     47|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     47|	int _ret = r; \
  |  |  |  |  155|     47|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  157|     47|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     47|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|     47|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  492|     11|{
  493|     11|	int r, protocol;
  494|     11|	sc_path_t path;
  495|     11|	u8 all_certs[1024];
  496|     11|	EAC_CTX *ctx = NULL;
  497|     11|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  498|     11|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  499|     11|	BUF_MEM *comp_pub_key = NULL;
  500|     11|	sc_cvc_t cvc_device, cvc_issuer;
  501|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  502|     11|	sc_pkcs15_card_t p15card;
  503|     11|	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|     11|	p15card.card = card;
  507|       |
  508|     11|	memset(&cvc_device, 0, sizeof(cvc_device));
  509|     11|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  510|       |
  511|       |
  512|     11|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (512:6): [True: 0, False: 11]
  |  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|     11|	} else {
  516|       |		/* get issuer and device certificate from the card */
  517|     11|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|     11|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  518|     11|		if (r < 0)
  ------------------
  |  Branch (518:7): [True: 0, False: 11]
  ------------------
  519|      0|			goto err;
  520|     11|		r = sc_select_file(card, &path, NULL);
  521|     11|		if (r < 0)
  ------------------
  |  Branch (521:7): [True: 4, False: 7]
  ------------------
  522|      4|			goto err;
  523|      7|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  524|      7|		if (r < 0)
  ------------------
  |  Branch (524:7): [True: 3, False: 4]
  ------------------
  525|      3|			goto err;
  526|      4|		if (r == 0) {
  ------------------
  |  Branch (526:7): [True: 1, False: 3]
  ------------------
  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|      3|		all_certs_len = r;
  532|       |
  533|       |		/* save EF_C_DevAut for further use */
  534|      3|		cert = realloc(priv->EF_C_DevAut, all_certs_len);
  535|      3|		if (cert) {
  ------------------
  |  Branch (535:7): [True: 3, False: 0]
  ------------------
  536|      3|			memcpy((unsigned char *) cert, all_certs, all_certs_len);
  537|      3|			priv->EF_C_DevAut = (unsigned char *) cert;
  538|      3|			priv->EF_C_DevAut_len = all_certs_len;
  539|      3|		}
  540|       |
  541|      3|		cert = all_certs;
  542|      3|	}
  543|      3|	left = all_certs_len;
  544|       |
  545|      3|	device_cert = cert;
  546|      3|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_device);
  547|      3|	if (r < 0)
  ------------------
  |  Branch (547:6): [True: 3, False: 0]
  ------------------
  548|      3|		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|     11|err:
  599|     11|	if (r < 0)
  ------------------
  |  Branch (599:6): [True: 11, False: 0]
  ------------------
  600|     11|		EAC_CTX_clear_free(ctx);
  601|     11|	if (comp_pub_key)
  ------------------
  |  Branch (601:6): [True: 0, False: 11]
  ------------------
  602|      0|		BUF_MEM_free(comp_pub_key);
  603|     11|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  604|     11|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  605|       |
  606|     11|	return r;
  607|      0|}

sc_get_setcos_driver:
 1136|  8.50k|{
 1137|  8.50k|	return sc_get_driver();
 1138|  8.50k|}
card-setcos.c:sc_get_driver:
 1116|  8.50k|{
 1117|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1118|       |
 1119|  8.50k|	setcos_ops = *iso_drv->ops;
 1120|  8.50k|	setcos_ops.match_card = setcos_match_card;
 1121|  8.50k|	setcos_ops.init = setcos_init;
 1122|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1122:6): [True: 1, False: 8.49k]
  ------------------
 1123|      1|		iso_ops = iso_drv->ops;
 1124|  8.50k|	setcos_ops.create_file = setcos_create_file;
 1125|  8.50k|	setcos_ops.set_security_env = setcos_set_security_env;
 1126|  8.50k|	setcos_ops.select_file = setcos_select_file;
 1127|  8.50k|	setcos_ops.list_files = setcos_list_files;
 1128|  8.50k|	setcos_ops.process_fci = setcos_process_fci;
 1129|  8.50k|	setcos_ops.construct_fci = setcos_construct_fci;
 1130|  8.50k|	setcos_ops.card_ctl = setcos_card_ctl;
 1131|       |
 1132|  8.50k|	return &setcos_drv;
 1133|  8.50k|}
card-setcos.c:setcos_match_card:
   83|  4.52k|{
   84|  4.52k|	sc_apdu_t apdu;
   85|  4.52k|	u8 buf[6];
   86|  4.52k|	int i;
   87|       |
   88|  4.52k|	i = _sc_match_atr(card, setcos_atrs, &card->type);
   89|  4.52k|	if (i < 0) {
  ------------------
  |  Branch (89:6): [True: 4.44k, False: 84]
  ------------------
   90|  4.44k|		if (match_hist_bytes(card, "FISE", 0)) {
  ------------------
  |  Branch (90:7): [True: 48, False: 4.39k]
  ------------------
   91|     48|			card->type = SC_CARD_TYPE_SETCOS_GENERIC;
   92|     48|			return 1;
   93|     48|		}
   94|       |		/* Check if it's a EID2.x applet by reading the version info */
   95|  4.39k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  292|  4.39k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   96|  4.39k|		apdu.cla = 0x00;
   97|  4.39k|		apdu.resp = buf;
   98|  4.39k|		apdu.resplen = 5;
   99|  4.39k|		apdu.le = 5;
  100|  4.39k|		i = sc_transmit_apdu(card, &apdu);
  101|  4.39k|		if (i == 0 && apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && apdu.resplen == 5) {
  ------------------
  |  Branch (101:7): [True: 4.36k, False: 33]
  |  Branch (101:17): [True: 540, False: 3.82k]
  |  Branch (101:37): [True: 531, False: 9]
  |  Branch (101:57): [True: 464, False: 67]
  ------------------
  102|    464|			if (memcmp(buf, "v2.0", 4) == 0)
  ------------------
  |  Branch (102:8): [True: 10, False: 454]
  ------------------
  103|     10|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_0;
  104|    454|			else if (memcmp(buf, "v2.1", 4) == 0)
  ------------------
  |  Branch (104:13): [True: 21, False: 433]
  ------------------
  105|     21|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_1;
  106|    433|			else {
  107|    433|				buf[sizeof(buf) - 1] = '\0';
  108|    433|				sc_log(card->ctx,  "SetCOS EID applet %s is not supported", (char *) buf);
  ------------------
  |  |   71|    433|#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|    433|				return 0;
  110|    433|			}
  111|     31|			return 1;
  112|    464|		}
  113|       |
  114|  3.93k|		return 0;
  115|  4.39k|	}
  116|     84|	card->flags = setcos_atrs[i].flags;
  117|     84|	return 1;
  118|  4.52k|}
card-setcos.c:match_hist_bytes:
   64|  4.44k|{
   65|  4.44k|	const char *src = (const char *) card->reader->atr_info.hist_bytes;
   66|  4.44k|	size_t srclen = card->reader->atr_info.hist_bytes_len;
   67|  4.44k|	size_t offset = 0;
   68|       |
   69|  4.44k|	if (len == 0)
  ------------------
  |  Branch (69:6): [True: 4.44k, False: 0]
  ------------------
   70|  4.44k|		len = strlen(str);
   71|  4.44k|	if (srclen < len)
  ------------------
  |  Branch (71:6): [True: 2.50k, False: 1.93k]
  ------------------
   72|  2.50k|		return 0;
   73|  17.8k|	while (srclen - offset > len) {
  ------------------
  |  Branch (73:9): [True: 15.9k, False: 1.89k]
  ------------------
   74|  15.9k|		if (memcmp(src + offset, str, len) == 0) {
  ------------------
  |  Branch (74:7): [True: 48, False: 15.9k]
  ------------------
   75|     48|			return 1;
   76|     48|		}
   77|  15.9k|		offset++;
   78|  15.9k|	}
   79|  1.89k|	return 0;
   80|  1.93k|}
card-setcos.c:setcos_init:
  133|    163|{
  134|    163|	card->name = "SetCOS";
  135|       |
  136|       |	/* Handle unknown or forced cards */
  137|    163|	if (card->type < 0) {
  ------------------
  |  Branch (137:6): [True: 0, False: 163]
  ------------------
  138|      0|		card->type = SC_CARD_TYPE_SETCOS_GENERIC;
  139|      0|	}
  140|       |
  141|    163|	switch (card->type) {
  142|      0|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (142:2): [True: 0, False: 163]
  ------------------
  143|      0|		card->cla = 0x00;
  144|      0|		select_pkcs15_app(card);
  145|      0|		if (card->flags & SC_CARD_FLAG_RNG)
  ------------------
  |  |  536|      0|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  |  Branch (145:7): [True: 0, False: 0]
  ------------------
  146|      0|			card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|      0|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  147|      0|		break;
  148|     84|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (148:2): [True: 84, False: 79]
  ------------------
  149|     94|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (149:2): [True: 10, False: 153]
  ------------------
  150|    115|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (150:2): [True: 21, False: 142]
  ------------------
  151|    115|		card->cla = 0x00;
  152|    115|		card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    115|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  153|    115|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    115|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  154|    115|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    115|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  155|    115|		break;
  156|     48|	default:
  ------------------
  |  Branch (156:2): [True: 48, False: 115]
  ------------------
  157|       |		/* XXX: Get SetCOS version */
  158|     48|		card->cla = 0x80;	/* SetCOS 4.3.x */
  159|       |		/* State that we have an RNG */
  160|     48|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     48|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  161|     48|		break;
  162|    163|	}
  163|       |
  164|    163|	switch (card->type) {
  ------------------
  |  Branch (164:10): [True: 115, False: 48]
  ------------------
  165|      0|	case SC_CARD_TYPE_SETCOS_PKI: {
  ------------------
  |  Branch (165:2): [True: 0, False: 163]
  ------------------
  166|      0|		unsigned long flags;
  167|       |
  168|      0|		flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              		flags = SC_ALGORITHM_RSA_RAW | 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 */
  |  |  ------------------
  ------------------
  169|      0|		flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              		flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  170|       |
  171|      0|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  172|      0|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  173|      0|	} break;
  174|     84|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (174:2): [True: 84, False: 79]
  ------------------
  175|     84|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (175:2): [True: 0, False: 163]
  ------------------
  176|     94|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (176:2): [True: 10, False: 153]
  ------------------
  177|    115|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (177:2): [True: 21, False: 142]
  ------------------
  178|    115|		{
  179|    115|			unsigned long flags;
  180|       |
  181|    115|			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  102|    115|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    115|#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|    115|#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|    115|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  182|    115|			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  133|    115|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|    115|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  183|    115|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    115|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  184|       |
  185|    115|			_sc_card_add_rsa_alg(card, 512, flags, 0);
  186|    115|			_sc_card_add_rsa_alg(card, 768, flags, 0);
  187|    115|			_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|    115|			_sc_card_add_rsa_alg(card, 2048, flags, 0);
  189|    115|		}
  190|    115|		break;
  191|    163|	}
  192|    163|	return 0;
  193|    163|}
card-setcos.c:setcos_select_file:
  901|    796|{
  902|    796|	int r;
  903|       |
  904|    796|	r = iso_ops->select_file(card, in_path, file);
  905|    796|	if (r)
  ------------------
  |  Branch (905:6): [True: 558, False: 238]
  ------------------
  906|    558|		return r;
  907|    238|	if (file != NULL) {
  ------------------
  |  Branch (907:6): [True: 175, False: 63]
  ------------------
  908|    175|		if (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (908:7): [True: 87, False: 88]
  ------------------
  909|     88|		    card->type == SC_CARD_TYPE_SETCOS_NIDEL ||
  ------------------
  |  Branch (909:7): [True: 0, False: 88]
  ------------------
  910|     88|		    SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|     88|#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: 19, False: 69]
  |  |  |  Branch (46:85): [True: 34, False: 35]
  |  |  ------------------
  ------------------
  911|    140|			parse_sec_attr_44(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  912|     35|		else
  913|     35|			parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  914|    175|	}
  915|    238|	return 0;
  916|    796|}
card-setcos.c:parse_sec_attr_44:
  746|    140|{
  747|       |	/* OpenSc Operation values for each command operation-type */
  748|    140|	const int df_idx[8] = {	 /* byte 1 = OpenSC type of AC Bit0,  byte 2 = OpenSC type of AC Bit1 ...*/
  749|    140|		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  168|    140|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    140|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    140|#define SC_AC_OP_CREATE			3
  ------------------
  750|    140|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    140|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    140|#define SC_AC_OP_REHABILITATE		4
  ------------------
  751|    140|		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  167|    140|#define SC_AC_OP_LOCK			1
  ------------------
              		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  168|    140|#define SC_AC_OP_DELETE			2
  ------------------
  752|    140|	const int ef_idx[8] = {
  753|    140|		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|    140|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|    140|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|    140|#define SC_AC_OP_WRITE			24
  ------------------
  754|    140|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    140|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    140|#define SC_AC_OP_REHABILITATE		4
  ------------------
  755|    140|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    140|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    140|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  756|    140|	const int efi_idx[8] = { /* internal EF used for RSA keys */
  757|    140|		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  188|    140|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  202|    140|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    140|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|    140|#define SC_AC_OP_UPDATE			23
  ------------------
  758|    140|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    140|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    140|#define SC_AC_OP_REHABILITATE		4
  ------------------
  759|    140|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    140|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    140|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  760|       |
  761|    140|	u8		bValue;
  762|    140|	int		i;
  763|    140|	int		iKeyRef = 0;
  764|    140|	int		iMethod;
  765|    140|	int		iPinCount;
  766|    140|	int		iOffset = 0;
  767|    140|	int		iOperation;
  768|    140|	const int*	p_idx;
  769|       |
  770|       |	/* Check all sub-AC definitions within the total AC */
  771|    763|	while (len > 1 && (size_t)iOffset < len) {	/* minimum length = 2 */
  ------------------
  |  Branch (771:9): [True: 702, False: 61]
  |  Branch (771:20): [True: 635, False: 67]
  ------------------
  772|    635|		size_t iACLen   = buf[iOffset] & 0x0F;
  773|    635|		if (iACLen >= len)
  ------------------
  |  Branch (773:7): [True: 7, False: 628]
  ------------------
  774|      7|			break;
  775|       |
  776|    628|		iMethod = SC_AC_NONE;		/* default no authentication required */
  ------------------
  |  |  150|    628|#define SC_AC_NONE			0x00000000
  ------------------
  777|       |
  778|    628|		if (buf[iOffset] & 0X80) { /* AC in adaptive coding */
  ------------------
  |  Branch (778:7): [True: 272, False: 356]
  ------------------
  779|       |			/* Evaluates only the command-byte, not the optional P1/P2/Option bytes */
  780|    272|			size_t	iParmLen = 1;			/* command-byte is always present */
  781|    272|			size_t	iKeyLen  = 0;			/* Encryption key is optional */
  782|       |
  783|    272|			if (buf[iOffset]   & 0x20) iKeyLen++;
  ------------------
  |  Branch (783:8): [True: 184, False: 88]
  ------------------
  784|    272|			if (buf[iOffset+1] & 0x40) iParmLen++;
  ------------------
  |  Branch (784:8): [True: 112, False: 160]
  ------------------
  785|    272|			if (buf[iOffset+1] & 0x20) iParmLen++;
  ------------------
  |  Branch (785:8): [True: 175, False: 97]
  ------------------
  786|    272|			if (buf[iOffset+1] & 0x10) iParmLen++;
  ------------------
  |  Branch (786:8): [True: 104, False: 168]
  ------------------
  787|    272|			if (buf[iOffset+1] & 0x08) iParmLen++;
  ------------------
  |  Branch (787:8): [True: 31, False: 241]
  ------------------
  788|       |
  789|       |			/* Get KeyNumber if available */
  790|    272|			if(iKeyLen) {
  ------------------
  |  Branch (790:7): [True: 184, False: 88]
  ------------------
  791|    184|				int iSC;
  792|    184|				if (len < 1 + iACLen)
  ------------------
  |  Branch (792:9): [True: 0, False: 184]
  ------------------
  793|      0|					break;
  794|    184|				iSC = buf[iOffset+iACLen];
  795|       |
  796|    184|				switch( (iSC>>5) & 0x03 ){
  ------------------
  |  Branch (796:13): [True: 184, False: 0]
  ------------------
  797|     21|				case 0:
  ------------------
  |  Branch (797:5): [True: 21, False: 163]
  ------------------
  798|     21|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     21|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  799|     21|					break;
  800|     85|				case 1:
  ------------------
  |  Branch (800:5): [True: 85, False: 99]
  ------------------
  801|     85|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|     85|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  802|     85|					break;
  803|     11|				case 2:
  ------------------
  |  Branch (803:5): [True: 11, False: 173]
  ------------------
  804|     78|				case 3:
  ------------------
  |  Branch (804:5): [True: 67, False: 117]
  ------------------
  805|     78|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|     78|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  806|     78|					break;
  807|    184|				}
  808|    184|				iKeyRef = iSC & 0x1F;			/* get key number */
  809|    184|			}
  810|       |
  811|       |			/* Get PinNumber if available */
  812|    272|			if (iACLen > (1+iParmLen+iKeyLen)) {  /* check via total length if pin is present */
  ------------------
  |  Branch (812:8): [True: 42, False: 230]
  ------------------
  813|     42|				if (len < 1+1+1+(size_t)iParmLen)
  ------------------
  |  Branch (813:9): [True: 0, False: 42]
  ------------------
  814|      0|					break;
  815|     42|				iKeyRef = buf[iOffset+1+1+iParmLen];  /* PTL + AM-header + parameter-bytes */
  816|     42|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     42|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  817|     42|			}
  818|       |
  819|       |			/* Convert SETCOS command to OpenSC command group */
  820|    272|			if (len < 1+2)
  ------------------
  |  Branch (820:8): [True: 5, False: 267]
  ------------------
  821|      5|				break;
  822|    267|			switch(buf[iOffset+2]){
  823|      3|			case 0x2A:			/* crypto operation */
  ------------------
  |  Branch (823:4): [True: 3, False: 264]
  ------------------
  824|      3|				iOperation = SC_AC_OP_CRYPTO;
  ------------------
  |  |  173|      3|#define SC_AC_OP_CRYPTO			7
  ------------------
  825|      3|				break;
  826|      4|			case 0x46:			/* key-generation operation */
  ------------------
  |  Branch (826:4): [True: 4, False: 263]
  ------------------
  827|      4|				iOperation = SC_AC_OP_UPDATE;
  ------------------
  |  |  189|      4|#define SC_AC_OP_UPDATE			23
  ------------------
  828|      4|				break;
  829|    260|			default:
  ------------------
  |  Branch (829:4): [True: 260, False: 7]
  ------------------
  830|    260|				iOperation = SC_AC_OP_SELECT;
  ------------------
  |  |  166|    260|#define SC_AC_OP_SELECT			0
  ------------------
  831|    260|				break;
  832|    267|			}
  833|    267|			sc_file_add_acl_entry(file, iOperation, iMethod, iKeyRef);
  834|    267|		}
  835|    356|		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|    356|			switch (file->type) {
  840|     11|			case SC_FILE_TYPE_DF:            /* DF */
  ------------------
  |  |  214|     11|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (840:4): [True: 11, False: 345]
  ------------------
  841|     11|				p_idx = df_idx;
  842|     11|				break;
  843|     13|			case SC_FILE_TYPE_INTERNAL_EF:   /* EF for RSA keys */
  ------------------
  |  |  215|     13|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (843:4): [True: 13, False: 343]
  ------------------
  844|     13|				p_idx = efi_idx;
  845|     13|				break;
  846|    332|			default:                         /* EF */
  ------------------
  |  Branch (846:4): [True: 332, False: 24]
  ------------------
  847|    332|				p_idx = ef_idx;
  848|    332|				break;
  849|    356|			}
  850|       |
  851|       |			/* Encryption key present ? */
  852|    356|			iPinCount = iACLen > 0 ? (int)iACLen - 1 : 0;
  ------------------
  |  Branch (852:16): [True: 139, False: 217]
  ------------------
  853|       |
  854|    356|			if (buf[iOffset] & 0x20) {
  ------------------
  |  Branch (854:8): [True: 146, False: 210]
  ------------------
  855|    146|				int iSC;
  856|    146|				if (len < 1 + (size_t)iACLen)
  ------------------
  |  Branch (856:9): [True: 0, False: 146]
  ------------------
  857|      0|					break;
  858|    146|				iSC = buf[iOffset + iACLen];
  859|       |
  860|    146|				switch( (iSC>>5) & 0x03 ) {
  ------------------
  |  Branch (860:13): [True: 146, False: 0]
  ------------------
  861|     23|				case 0:
  ------------------
  |  Branch (861:5): [True: 23, False: 123]
  ------------------
  862|     23|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     23|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  863|     23|					break;
  864|     42|				case 1:
  ------------------
  |  Branch (864:5): [True: 42, False: 104]
  ------------------
  865|     42|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|     42|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  866|     42|					break;
  867|     14|				case 2:
  ------------------
  |  Branch (867:5): [True: 14, False: 132]
  ------------------
  868|     81|				case 3:
  ------------------
  |  Branch (868:5): [True: 67, False: 79]
  ------------------
  869|     81|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|     81|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  870|     81|					break;
  871|    146|				}
  872|    146|				iKeyRef = iSC & 0x1F;			/* get key number */
  873|       |
  874|    146|				iPinCount--;				/* one byte used for keyReference  */
  875|    146|			}
  876|       |
  877|       |			/* Pin present ? */
  878|    356|			if ( iPinCount > 0 ) {
  ------------------
  |  Branch (878:9): [True: 91, False: 265]
  ------------------
  879|     91|				if (len < 1 + 2)
  ------------------
  |  Branch (879:9): [True: 0, False: 91]
  ------------------
  880|      0|					break;
  881|     91|				iKeyRef = buf[iOffset + 2];	/* pin ref */
  882|     91|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     91|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  883|     91|			}
  884|       |
  885|       |			/* Add AC for each command-operationType into OpenSc structure */
  886|    356|			bValue = buf[iOffset + 1];
  887|  3.20k|			for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (887:16): [True: 2.84k, False: 356]
  ------------------
  888|  2.84k|				if((bValue & 1) && (p_idx[i] >= 0))
  ------------------
  |  Branch (888:8): [True: 667, False: 2.18k]
  |  Branch (888:24): [True: 468, False: 199]
  ------------------
  889|    468|					sc_file_add_acl_entry(file, p_idx[i], iMethod, iKeyRef);
  890|  2.84k|				bValue >>= 1;
  891|  2.84k|			}
  892|    356|		}
  893|       |		/* Current field treated, get next AC sub-field */
  894|    623|		iOffset += iACLen +1;		/* AC + PTL-byte */
  895|    623|		len     -= iACLen +1;
  896|    623|	}
  897|    140|}
card-setcos.c:parse_sec_attr:
  718|     35|{
  719|     35|	int i;
  720|     35|	int idx[6];
  721|       |
  722|     35|	if (len < 6)
  ------------------
  |  Branch (722:6): [True: 14, False: 21]
  ------------------
  723|     14|		return;
  724|     21|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|     21|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (724:6): [True: 1, False: 20]
  ------------------
  725|      1|		const int df_idx[6] = {
  726|      1|			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  166|      1|#define SC_AC_OP_SELECT			0
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  167|      1|#define SC_AC_OP_LOCK			1
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  168|      1|#define SC_AC_OP_DELETE			2
  ------------------
  727|      1|			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  169|      1|#define SC_AC_OP_CREATE			3
  ------------------
              			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|      1|#define SC_AC_OP_REHABILITATE		4
  ------------------
  728|      1|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|      1|#define SC_AC_OP_INVALIDATE		5
  ------------------
  729|      1|		};
  730|      7|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (730:15): [True: 6, False: 1]
  ------------------
  731|      6|			idx[i] = df_idx[i];
  732|     20|	} else {
  733|     20|		const int ef_idx[6] = {
  734|     20|			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|     20|#define SC_AC_OP_READ			22
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|     20|#define SC_AC_OP_UPDATE			23
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     20|#define SC_AC_OP_WRITE			24
  ------------------
  735|     20|			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  202|     20|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     20|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     20|#define SC_AC_OP_REHABILITATE		4
  ------------------
  736|     20|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|     20|#define SC_AC_OP_INVALIDATE		5
  ------------------
  737|     20|		};
  738|    140|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (738:15): [True: 120, False: 20]
  ------------------
  739|    120|			idx[i] = ef_idx[i];
  740|     20|	}
  741|    147|	for (i = 0; i < 6; i++)
  ------------------
  |  Branch (741:14): [True: 126, False: 21]
  ------------------
  742|    126|		add_acl_entry(file, idx[i], buf[i]);
  743|     21|}
card-setcos.c:add_acl_entry:
  689|    126|{
  690|    126|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    126|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  691|       |
  692|    126|	switch (byte >> 4) {
  693|     38|	case 0:
  ------------------
  |  Branch (693:2): [True: 38, False: 88]
  ------------------
  694|     38|		method = SC_AC_NONE;
  ------------------
  |  |  150|     38|#define SC_AC_NONE			0x00000000
  ------------------
  695|     38|		break;
  696|     16|	case 1:
  ------------------
  |  Branch (696:2): [True: 16, False: 110]
  ------------------
  697|     16|		method = SC_AC_CHV;
  ------------------
  |  |  151|     16|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  698|     16|		key_ref = 1;
  699|     16|		break;
  700|     14|	case 2:
  ------------------
  |  Branch (700:2): [True: 14, False: 112]
  ------------------
  701|     14|		method = SC_AC_CHV;
  ------------------
  |  |  151|     14|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  702|     14|		key_ref = 2;
  703|     14|		break;
  704|     15|	case 4:
  ------------------
  |  Branch (704:2): [True: 15, False: 111]
  ------------------
  705|     15|		method = SC_AC_TERM;
  ------------------
  |  |  152|     15|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  706|     15|		break;
  707|     12|	case 15:
  ------------------
  |  Branch (707:2): [True: 12, False: 114]
  ------------------
  708|     12|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     12|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  709|     12|		break;
  710|     31|	default:
  ------------------
  |  Branch (710:2): [True: 31, False: 95]
  ------------------
  711|     31|		method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     31|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  712|     31|		break;
  713|    126|	}
  714|    126|	sc_file_add_acl_entry(file, op, method, key_ref);
  715|    126|}
card-setcos.c:setcos_process_fci:
  942|    167|{
  943|    167|	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|    167|	if (r >= 0 && (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (947:6): [True: 167, False: 0]
  |  Branch (947:17): [True: 84, False: 83]
  ------------------
  948|    133|	               SETCOS_IS_EID_APPLET(card))) {
  ------------------
  |  |   46|     83|#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: 16, False: 67]
  |  |  |  Branch (46:85): [True: 33, False: 34]
  |  |  ------------------
  ------------------
  949|    133|		const u8 *tag;
  950|    133|		size_t taglen = 1;
  951|    133|		tag = (u8 *) sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &taglen);
  952|    133|		if (tag != NULL && taglen == 1 && *tag == 0x11)
  ------------------
  |  Branch (952:7): [True: 48, False: 85]
  |  Branch (952:22): [True: 37, False: 11]
  |  Branch (952:37): [True: 4, False: 33]
  ------------------
  953|      4|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      4|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  954|    133|	}
  955|       |
  956|    167|	return r;
  957|    167|}
card-setcos.c:setcos_card_ctl:
 1092|      5|{
 1093|      5|	if (card->type != SC_CARD_TYPE_SETCOS_44 && !SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|      3|#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: 1, False: 2]
  |  |  |  Branch (46:85): [True: 1, False: 1]
  |  |  ------------------
  ------------------
  |  Branch (1093:6): [True: 3, False: 2]
  ------------------
 1094|      1|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1095|       |
 1096|      4|	switch(cmd) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 4]
  ------------------
 1097|      0|	case SC_CARDCTL_SETCOS_PUTDATA:
  ------------------
  |  Branch (1097:2): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 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: 4]
  ------------------
 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: 4]
  ------------------
 1109|      0|		return setcos_activate_file(card);
 1110|      4|	}
 1111|       |
 1112|      4|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      4|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1113|      4|}

sc_get_skeid_driver:
  179|  8.50k|{
  180|  8.50k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 8.49k]
  ------------------
  181|  8.50k|	skeid_ops = *iso_ops;
  182|  8.50k|	skeid_ops.match_card = skeid_match_card;
  183|  8.50k|	skeid_ops.init = skeid_init;
  184|  8.50k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  8.50k|	skeid_ops.logout = skeid_logout;
  186|  8.50k|	return &skeid_drv;
  187|  8.50k|}
card-skeid.c:skeid_match_card:
   73|  8.10k|{
   74|  8.10k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 8.10k, False: 3]
  |  Branch (74:58): [True: 3, False: 0]
  ------------------
   75|  8.10k|		return 0;
   76|       |
   77|      0|	sc_log(card->ctx,  "Slovak eID card v3 (CardOS 5.4)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   78|       |
   79|      0|	return 1;
   80|  8.10k|}
card-skeid.c:skeid_known_url:
   53|      3|{
   54|      3|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|      3|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|      3|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|      3|	sc_path_t url_path;
   59|       |
   60|      3|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      3|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|      3|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|      3|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|      3|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 2, False: 1]
  ------------------
   65|      2|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|      2|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|      5|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 1, False: 1]
  ------------------
   66|      1|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|      1|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 0, False: 1]
  ------------------
   67|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|      3|	return r;
   70|      3|}

sc_get_srbeid_driver:
  305|  8.50k|{
  306|       |	/* Save ISO ops for delegation, then override what we handle. */
  307|  8.50k|	iso_ops = sc_get_iso7816_driver()->ops;
  308|  8.50k|	srbeid_ops = *iso_ops;
  309|  8.50k|	srbeid_ops.match_card = srbeid_match_card;
  310|  8.50k|	srbeid_ops.init = srbeid_init;
  311|  8.50k|	srbeid_ops.select_file = srbeid_select_file;
  312|  8.50k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  313|  8.50k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  314|  8.50k|	srbeid_ops.decipher = srbeid_decipher;
  315|       |
  316|  8.50k|	return &srbeid_drv;
  317|  8.50k|}
card-srbeid.c:srbeid_match_card:
   72|  5.08k|{
   73|  5.08k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  5.08k|	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: 5.08k]
  |  Branch (74:16): [True: 0, False: 0]
  ------------------
   75|      0|		card->name = srbeid_atrs[i].name;
   76|      0|		return 1;
   77|      0|	}
   78|  5.08k|	return 0;
   79|  5.08k|}

sc_get_starcos_driver:
 2120|  8.50k|{
 2121|  8.50k|	return sc_get_driver();
 2122|  8.50k|}
card-starcos.c:sc_get_driver:
 2095|  8.50k|{
 2096|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2097|  8.50k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2097:6): [True: 1, False: 8.49k]
  ------------------
 2098|      1|		iso_ops = iso_drv->ops;
 2099|       |
 2100|  8.50k|	starcos_ops = *iso_drv->ops;
 2101|  8.50k|	starcos_ops.match_card = starcos_match_card;
 2102|  8.50k|	starcos_ops.init   = starcos_init;
 2103|  8.50k|	starcos_ops.finish = starcos_finish;
 2104|  8.50k|	starcos_ops.select_file = starcos_select_file;
 2105|  8.50k|	starcos_ops.get_challenge = starcos_get_challenge;
 2106|  8.50k|	starcos_ops.check_sw    = starcos_check_sw;
 2107|  8.50k|	starcos_ops.create_file = starcos_create_file;
 2108|  8.50k|	starcos_ops.delete_file = NULL;
 2109|  8.50k|	starcos_ops.set_security_env  = starcos_set_security_env;
 2110|  8.50k|	starcos_ops.compute_signature = starcos_compute_signature;
 2111|  8.50k|	starcos_ops.decipher = starcos_decipher;
 2112|  8.50k|	starcos_ops.card_ctl    = starcos_card_ctl;
 2113|  8.50k|	starcos_ops.logout      = starcos_logout;
 2114|  8.50k|	starcos_ops.pin_cmd     = starcos_pin_cmd;
 2115|       |
 2116|  8.50k|	return &starcos_drv;
 2117|  8.50k|}
card-starcos.c:starcos_match_card:
  125|  7.70k|{
  126|  7.70k|	int i;
  127|       |
  128|  7.70k|	i = _sc_match_atr(card, starcos_atrs, &card->type);
  129|  7.70k|	if (i < 0)
  ------------------
  |  Branch (129:6): [True: 7.70k, False: 0]
  ------------------
  130|  7.70k|		return 0;
  131|      0|	return 1;
  132|  7.70k|}

sc_get_tcos_driver:
  735|  8.50k|{
  736|  8.50k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  737|       |
  738|  8.50k|	if (iso_ops == NULL) iso_ops = iso_drv->ops;
  ------------------
  |  Branch (738:6): [True: 1, False: 8.49k]
  ------------------
  739|  8.50k|	tcos_ops = *iso_drv->ops;
  740|       |
  741|  8.50k|	tcos_ops.match_card           = tcos_match_card;
  742|  8.50k|	tcos_ops.init                 = tcos_init;
  743|  8.50k|	tcos_ops.finish               = tcos_finish;
  744|  8.50k|	tcos_ops.create_file          = tcos_create_file;
  745|  8.50k|	tcos_ops.set_security_env     = tcos_set_security_env;
  746|  8.50k|	tcos_ops.select_file          = tcos_select_file;
  747|  8.50k|	tcos_ops.list_files           = tcos_list_files;
  748|  8.50k|	tcos_ops.delete_file          = tcos_delete_file;
  749|  8.50k|	tcos_ops.compute_signature    = tcos_compute_signature;
  750|  8.50k|	tcos_ops.decipher             = tcos_decipher;
  751|  8.50k|	tcos_ops.restore_security_env = tcos_restore_security_env;
  752|  8.50k|	tcos_ops.card_ctl             = tcos_card_ctl;
  753|       |
  754|  8.50k|	return &tcos_drv;
  755|  8.50k|}
card-tcos.c:tcos_match_card:
   77|  7.70k|{
   78|  7.70k|	int i;
   79|       |
   80|  7.70k|	i = _sc_match_atr(card, tcos_atrs, &card->type);
   81|  7.70k|	if (i < 0)
  ------------------
  |  Branch (81:6): [True: 7.21k, False: 485]
  ------------------
   82|  7.21k|		return 0;
   83|    485|	return 1;
   84|  7.70k|}
card-tcos.c:tcos_init:
   88|    485|{
   89|    485|	unsigned long flags;
   90|       |
   91|    485|	tcos_data *data = malloc(sizeof(tcos_data));
   92|    485|	if (!data) return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  |  Branch (92:6): [True: 0, False: 485]
  ------------------
   93|       |
   94|    485|	card->name = "TCOS";
   95|    485|	card->drv_data = (void *)data;
   96|    485|	card->cla = 0x00;
   97|       |
   98|    485|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    485|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   99|    485|	flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    485|#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|    485|#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|    485|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  100|    485|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    485|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  101|       |
  102|    485|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  103|    485|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  104|    485|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  105|       |
  106|    485|	if (card->type == SC_CARD_TYPE_TCOS_V3) {
  ------------------
  |  Branch (106:6): [True: 0, False: 485]
  ------------------
  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|    485|	return 0;
  115|    485|}
card-tcos.c:tcos_finish:
   70|    485|{
   71|    485|	free(card->drv_data);
   72|    485|	return 0;
   73|    485|}
card-tcos.c:tcos_select_file:
  336|  3.48k|{
  337|  3.48k|	sc_context_t *ctx;
  338|  3.48k|	sc_apdu_t apdu;
  339|  3.48k|	sc_file_t *file=NULL;
  340|  3.48k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE], pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  341|  3.48k|	int r;
  342|  3.48k|	size_t pathlen;
  343|       |
  344|  3.48k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (344:6): [True: 0, False: 3.48k]
  |  Branch (344:22): [True: 0, False: 3.48k]
  ------------------
  345|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  346|  3.48k|	ctx=card->ctx;
  347|  3.48k|	memcpy(path, in_path->value, in_path->len);
  348|  3.48k|	pathlen = in_path->len;
  349|       |
  350|  3.48k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0x04);
  ------------------
  |  |  294|  3.48k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  351|       |
  352|  3.48k|	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: 3.48k]
  ------------------
  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: 3.48k]
  ------------------
  357|      0|		apdu.p1 = 9;
  358|      0|		break;
  359|  1.00k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  1.00k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (359:2): [True: 1.00k, False: 2.48k]
  ------------------
  360|  1.00k|		apdu.p1 = 4;
  361|  1.00k|		break;
  362|  2.48k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  2.48k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (362:2): [True: 2.48k, False: 1.00k]
  ------------------
  363|  2.48k|		apdu.p1 = 8;
  364|  2.48k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) path += 2, pathlen -= 2;
  ------------------
  |  Branch (364:7): [True: 2.48k, False: 0]
  |  Branch (364:23): [True: 1.99k, False: 485]
  ------------------
  365|  2.48k|		if (pathlen == 0) apdu.p1 = 0;
  ------------------
  |  Branch (365:7): [True: 0, False: 2.48k]
  ------------------
  366|  2.48k|		break;
  367|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (367:2): [True: 0, False: 3.48k]
  ------------------
  368|      0|		apdu.p1 = 3;
  369|      0|		pathlen = 0;
  370|      0|		break;
  371|      0|	default:
  ------------------
  |  Branch (371:2): [True: 0, False: 3.48k]
  ------------------
  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|  3.48k|	}
  374|  3.48k|	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: 3.48k]
  ------------------
  375|       |
  376|  3.48k|	apdu.lc = pathlen;
  377|  3.48k|	apdu.data = path;
  378|  3.48k|	apdu.datalen = pathlen;
  379|       |
  380|  3.48k|	if (file_out != NULL) {
  ------------------
  |  Branch (380:6): [True: 1.79k, False: 1.69k]
  ------------------
  381|  1.79k|		apdu.resp = buf;
  382|  1.79k|		apdu.resplen = sizeof(buf);
  383|  1.79k|		apdu.le = 256;
  384|  1.79k|	} else {
  385|  1.69k|		apdu.resplen = 0;
  386|  1.69k|		apdu.le = 0;
  387|  1.69k|		apdu.p2 = 0x0C;
  388|  1.69k|		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|  3.38k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (388:14): [True: 0, False: 1.69k]
  ------------------
  389|  1.69k|	}
  390|       |
  391|  3.48k|	r = sc_transmit_apdu(card, &apdu);
  392|  3.48k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  3.48k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.48k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.48k|	int _ret = (r); \
  |  |  |  |  168|  3.48k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 3.46k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  393|  3.46k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  394|  3.46k|	if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.92k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.92k|	int _ret = r; \
  |  |  155|  2.92k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.92k, False: 0]
  |  |  ------------------
  |  |  156|  2.92k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.79k, False: 129]
  |  |  ------------------
  |  |  157|  2.92k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.92k|	} else { \
  |  |  159|      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.92k|	return _ret; \
  |  |  163|  2.92k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (394:6): [True: 2.79k, False: 674]
  |  Branch (394:11): [True: 129, False: 545]
  ------------------
  395|       |
  396|    545|	if (apdu.resplen < 1 || apdu.resp[0] != 0x62) {
  ------------------
  |  Branch (396:6): [True: 20, False: 525]
  |  Branch (396:26): [True: 67, False: 458]
  ------------------
  397|     87|		sc_log(ctx, "received invalid template %02X\n", apdu.resp[0]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  398|     87|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|     87|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 87, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  399|     87|	}
  400|       |
  401|    458|	file = sc_file_new();
  402|    458|	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: 458]
  ------------------
  403|    458|	*file_out = file;
  404|    458|	file->path = *in_path;
  405|       |
  406|    458|	iso_ops->process_fci(card, file, apdu.resp, apdu.resplen);
  407|       |
  408|    458|	parse_sec_attr(card, file, file->sec_attr, file->sec_attr_len);
  409|       |
  410|    458|	return 0;
  411|    458|}
card-tcos.c:parse_sec_attr:
  271|    458|{
  272|    458|	unsigned int op;
  273|       |
  274|       |	/* list directory is not covered by ACLs - so always add an entry */
  275|    458|	sc_file_add_acl_entry (file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|    458|#define SC_AC_OP_LIST_FILES		6
  ------------------
  276|    458|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    458|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    458|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  277|       |	/* FIXME: check for what LOCK is used */
  278|    458|	sc_file_add_acl_entry (file, SC_AC_OP_LOCK,
  ------------------
  |  |  167|    458|#define SC_AC_OP_LOCK			1
  ------------------
  279|    458|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    458|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    458|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  280|  4.49k|	for (; len >= 6; len -= 6, buf += 6) {
  ------------------
  |  Branch (280:9): [True: 4.03k, False: 458]
  ------------------
  281|       |		/* FIXME: temporary hacks */
  282|  4.03k|		if (!memcmp(buf, "\xa4\x00\x00\x00\xff\xff", 6)) {/* select */
  ------------------
  |  Branch (282:7): [True: 12, False: 4.02k]
  ------------------
  283|     12|			sc_file_add_acl_entry (file, SC_AC_OP_SELECT,
  ------------------
  |  |  166|     12|#define SC_AC_OP_SELECT			0
  ------------------
  284|     12|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     12|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     12|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  285|  4.02k|		} else if (!memcmp(buf, "\xb0\x00\x00\x00\xff\xff", 6)) {/*read*/
  ------------------
  |  Branch (285:14): [True: 18, False: 4.00k]
  ------------------
  286|     18|			sc_file_add_acl_entry (file, SC_AC_OP_READ,
  ------------------
  |  |  188|     18|#define SC_AC_OP_READ			22
  ------------------
  287|     18|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     18|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     18|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  288|  4.00k|		} else if (!memcmp(buf, "\xd6\x00\x00\x00\xff\xff", 6)) {/*upd*/
  ------------------
  |  Branch (288:14): [True: 17, False: 3.98k]
  ------------------
  289|     17|			sc_file_add_acl_entry (file, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|     17|#define SC_AC_OP_UPDATE			23
  ------------------
  290|     17|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     17|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     17|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  291|  3.98k|		} else if (!memcmp(buf, "\x60\x00\x00\x00\xff\xff", 6)) {/*adm */
  ------------------
  |  Branch (291:14): [True: 11, False: 3.97k]
  ------------------
  292|     11|			sc_file_add_acl_entry (file, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     11|#define SC_AC_OP_WRITE			24
  ------------------
  293|     11|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     11|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     11|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  294|     11|			sc_file_add_acl_entry (file, SC_AC_OP_CREATE,
  ------------------
  |  |  169|     11|#define SC_AC_OP_CREATE			3
  ------------------
  295|     11|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     11|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     11|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  296|     11|			sc_file_add_acl_entry (file, SC_AC_OP_INVALIDATE,
  ------------------
  |  |  171|     11|#define SC_AC_OP_INVALIDATE		5
  ------------------
  297|     11|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     11|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     11|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  298|     11|			sc_file_add_acl_entry (file, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     11|#define SC_AC_OP_REHABILITATE		4
  ------------------
  299|     11|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     11|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     11|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  300|  3.97k|		} 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|  3.97k|			op = map_operations (buf[0]);
  306|  3.97k|			if (op == (unsigned int)-1) {
  ------------------
  |  Branch (306:8): [True: 1.74k, False: 2.22k]
  ------------------
  307|  1.74k|				sc_log(card->ctx,
  ------------------
  |  |   71|  1.74k|#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|  1.74k|					"Unknown security command byte %02x\n",
  309|  1.74k|					buf[0]);
  310|  1.74k|				continue;
  311|  1.74k|			}
  312|  2.22k|			if (!buf[1])
  ------------------
  |  Branch (312:8): [True: 109, False: 2.11k]
  ------------------
  313|    109|				sc_file_add_acl_entry (file, op,
  314|    109|                                                       SC_AC_NONE,
  ------------------
  |  |  150|    109|#define SC_AC_NONE			0x00000000
  ------------------
  315|    109|                                                       SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    109|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  316|  2.11k|			else
  317|  2.11k|				sc_file_add_acl_entry (file, op,
  318|  2.11k|                                                       SC_AC_CHV, buf[1]);
  ------------------
  |  |  151|  2.11k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  319|       |
  320|  2.22k|			if (!buf[2] && !buf[3])
  ------------------
  |  Branch (320:8): [True: 183, False: 2.04k]
  |  Branch (320:19): [True: 68, False: 115]
  ------------------
  321|     68|				sc_file_add_acl_entry (file, op,
  322|     68|                                                       SC_AC_NONE,
  ------------------
  |  |  150|     68|#define SC_AC_NONE			0x00000000
  ------------------
  323|     68|                                                       SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     68|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  324|  2.16k|			else
  325|  2.16k|				sc_file_add_acl_entry (file, op,
  326|  2.16k|                                                       SC_AC_TERM,
  ------------------
  |  |  152|  2.16k|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  327|  2.16k|                                                       (buf[2]<<8)|buf[3]);
  328|  2.22k|		}
  329|  4.03k|	}
  330|    458|}
card-tcos.c:map_operations:
  236|  3.97k|{
  237|  3.97k|	unsigned int op = (unsigned int)-1;
  238|       |
  239|  3.97k|	switch ( (commandbyte & 0xfe) ) {
  ------------------
  |  Branch (239:11): [True: 2.22k, False: 1.74k]
  ------------------
  240|    104|		case 0xe2: /* append record */   op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|    104|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (240:3): [True: 104, False: 3.87k]
  ------------------
  241|     99|		case 0x24: /* change password */ op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|     99|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (241:3): [True: 99, False: 3.87k]
  ------------------
  242|     80|		case 0xe0: /* create */          op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     80|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (242:3): [True: 80, False: 3.89k]
  ------------------
  243|     75|		case 0xe4: /* delete */          op = SC_AC_OP_DELETE; break;
  ------------------
  |  |  168|     75|#define SC_AC_OP_DELETE			2
  ------------------
  |  Branch (243:3): [True: 75, False: 3.89k]
  ------------------
  244|    274|		case 0xe8: /* exclude sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|    274|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (244:3): [True: 274, False: 3.70k]
  ------------------
  245|     93|		case 0x82: /* external auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     93|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (245:3): [True: 93, False: 3.88k]
  ------------------
  246|     90|		case 0xe6: /* include sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     90|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (246:3): [True: 90, False: 3.88k]
  ------------------
  247|     74|		case 0x88: /* internal auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     74|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (247:3): [True: 74, False: 3.90k]
  ------------------
  248|     91|		case 0x04: /* invalidate */      op = SC_AC_OP_INVALIDATE; break;
  ------------------
  |  |  171|     91|#define SC_AC_OP_INVALIDATE		5
  ------------------
  |  Branch (248:3): [True: 91, False: 3.88k]
  ------------------
  249|    136|		case 0x2a: /* perform sec. op */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|    136|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (249:3): [True: 136, False: 3.83k]
  ------------------
  250|     94|		case 0xb0: /* read binary */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     94|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (250:3): [True: 94, False: 3.88k]
  ------------------
  251|     96|		case 0xb2: /* read record */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     96|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (251:3): [True: 96, False: 3.87k]
  ------------------
  252|    101|		case 0x44: /* rehabilitate */    op = SC_AC_OP_REHABILITATE; break;
  ------------------
  |  |  170|    101|#define SC_AC_OP_REHABILITATE		4
  ------------------
  |  Branch (252:3): [True: 101, False: 3.87k]
  ------------------
  253|     86|		case 0xa4: /* select */          op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     86|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (253:3): [True: 86, False: 3.88k]
  ------------------
  254|     73|		case 0xee: /* set permanent */   op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     73|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (254:3): [True: 73, False: 3.90k]
  ------------------
  255|    154|		case 0x2c: /* unblock password */op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|    154|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (255:3): [True: 154, False: 3.82k]
  ------------------
  256|    131|		case 0xd6: /* update binary */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|    131|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (256:3): [True: 131, False: 3.84k]
  ------------------
  257|     77|		case 0xdc: /* update record */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     77|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (257:3): [True: 77, False: 3.89k]
  ------------------
  258|    104|		case 0x20: /* verify password */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|    104|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (258:3): [True: 104, False: 3.87k]
  ------------------
  259|    196|		case 0x60: /* admin group */     op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|    196|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (259:3): [True: 196, False: 3.77k]
  ------------------
  260|  3.97k|	}
  261|  3.97k|	return op;
  262|  3.97k|}
card-tcos.c:tcos_card_ctl:
  723|    487|{
  724|    487|	switch (cmd) {
  ------------------
  |  Branch (724:10): [True: 487, False: 0]
  ------------------
  725|      0|	case SC_CARDCTL_TCOS_SETPERM:
  ------------------
  |  Branch (725:2): [True: 0, False: 487]
  ------------------
  726|      0|		return tcos_setperm(card, !!ptr);
  727|    487|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (727:2): [True: 487, False: 0]
  ------------------
  728|    487|		return tcos_get_serialnr(card, (sc_serial_number_t *)ptr);
  729|    487|	}
  730|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  731|    487|}
card-tcos.c:tcos_get_serialnr:
  696|    487|{
  697|    487|	int r;
  698|       |
  699|    487|	if (!serial)
  ------------------
  |  Branch (699:6): [True: 0, False: 487]
  ------------------
  700|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  701|       |
  702|       |	/* see if we have cached serial number */
  703|    487|	if (card->serialnr.len) {
  ------------------
  |  Branch (703:6): [True: 0, False: 487]
  ------------------
  704|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  705|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  706|      0|	}
  707|       |
  708|    487|	card->serialnr.len = sizeof card->serialnr.value;
  709|    487|	r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
  710|    487|	if (r < 0) {
  ------------------
  |  Branch (710:6): [True: 440, False: 47]
  ------------------
  711|    440|		card->serialnr.len = 0;
  712|    440|		return r;
  713|    440|	}
  714|       |
  715|       |	/* copy and return serial number */
  716|     47|	memcpy(serial, &card->serialnr, sizeof(*serial));
  717|       |
  718|     47|	return SC_SUCCESS;
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
  719|    487|}

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

sc_decompress_alloc:
  254|     96|{
  255|     96|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (255:6): [True: 0, False: 96]
  |  Branch (255:20): [True: 0, False: 96]
  ------------------
  256|      0|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      0|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  257|      0|	}
  258|       |
  259|     96|	if (method == COMPRESSION_AUTO) {
  ------------------
  |  |   26|     96|#define COMPRESSION_AUTO	0
  ------------------
  |  Branch (259:6): [True: 96, False: 0]
  ------------------
  260|     96|		method = detect_method(in, inLen);
  261|     96|		if (method == COMPRESSION_UNKNOWN) {
  ------------------
  |  |   29|     96|#define COMPRESSION_UNKNOWN (-1)
  ------------------
  |  Branch (261:7): [True: 69, False: 27]
  ------------------
  262|     69|			return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     69|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  263|     69|		}
  264|     96|	}
  265|       |
  266|     27|	switch (method) {
  267|     27|	case COMPRESSION_ZLIB:
  ------------------
  |  |   27|     27|#define COMPRESSION_ZLIB	1
  ------------------
  |  Branch (267:2): [True: 27, False: 0]
  ------------------
  268|     27|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 0);
  269|      0|	case COMPRESSION_GZIP:
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
  |  Branch (269:2): [True: 0, False: 27]
  ------------------
  270|      0|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 1);
  271|      0|	default:
  ------------------
  |  Branch (271:2): [True: 0, False: 27]
  ------------------
  272|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  273|     27|	}
  274|     27|}
compression.c:zerr_to_opensc:
   34|     27|static int zerr_to_opensc(int err) {
   35|     27|	switch(err) {
   36|      0|	case Z_OK:
  ------------------
  |  Branch (36:2): [True: 0, False: 27]
  ------------------
   37|      0|	case Z_STREAM_END:
  ------------------
  |  Branch (37:2): [True: 0, False: 27]
  ------------------
   38|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
   39|      0|	case Z_UNKNOWN:
  ------------------
  |  Branch (39:2): [True: 0, False: 27]
  ------------------
   40|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
   41|     27|	case Z_DATA_ERROR:
  ------------------
  |  Branch (41:2): [True: 27, False: 0]
  ------------------
   42|     27|	case Z_BUF_ERROR:
  ------------------
  |  Branch (42:2): [True: 0, False: 27]
  ------------------
   43|     27|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     27|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   44|      0|	case Z_MEM_ERROR:
  ------------------
  |  Branch (44:2): [True: 0, False: 27]
  ------------------
   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: 27]
  ------------------
   47|      0|	case Z_STREAM_ERROR:
  ------------------
  |  Branch (47:2): [True: 0, False: 27]
  ------------------
   48|       |	/* case Z_NEED_DICT: */
   49|      0|	default:
  ------------------
  |  Branch (49:2): [True: 0, False: 27]
  ------------------
   50|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   51|     27|	}
   52|     27|}
compression.c:detect_method:
   53|     96|static int detect_method(const u8* in, size_t inLen) {
   54|     96|	if (in != NULL && inLen > 1) {
  ------------------
  |  Branch (54:6): [True: 96, False: 0]
  |  Branch (54:20): [True: 91, False: 5]
  ------------------
   55|     91|		if (in[0] == 0x1f && in[1] == 0x8b)
  ------------------
  |  Branch (55:7): [True: 1, False: 90]
  |  Branch (55:24): [True: 0, False: 1]
  ------------------
   56|      0|			return COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#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|     91|		if ((((uint16_t) in[0])*256 + in[1]) % 31 == 0)
  ------------------
  |  Branch (75:7): [True: 27, False: 64]
  ------------------
   76|     27|			return COMPRESSION_ZLIB;
  ------------------
  |  |   27|     27|#define COMPRESSION_ZLIB	1
  ------------------
   77|     91|	}
   78|     69|	return COMPRESSION_UNKNOWN;
  ------------------
  |  |   29|     69|#define COMPRESSION_UNKNOWN (-1)
  ------------------
   79|     96|}
compression.c:sc_decompress_zlib_alloc:
  185|     27|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|     27|	z_stream gz;
  188|     27|	int err;
  189|     27|	int window_size = 15;
  190|     27|	const size_t startSize = inLen < 1024 ? 2048 : inLen * 2;
  ------------------
  |  Branch (190:27): [True: 17, False: 10]
  ------------------
  191|     27|	const size_t blockSize = inLen < 1024 ? 512 : inLen / 2;
  ------------------
  |  Branch (191:27): [True: 17, False: 10]
  ------------------
  192|     27|	size_t bufferSize = startSize;
  193|     27|	if (gzip)
  ------------------
  |  Branch (193:6): [True: 0, False: 27]
  ------------------
  194|      0|		window_size += 0x20;
  195|     27|	memset(&gz, 0, sizeof(gz));
  196|       |
  197|     27|	if (!out || !outLen)
  ------------------
  |  Branch (197:6): [True: 0, False: 27]
  |  Branch (197:14): [True: 0, False: 27]
  ------------------
  198|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  199|       |
  200|     27|	gz.next_in = (u8*)in;
  201|     27|	gz.avail_in = (unsigned)inLen;
  202|       |
  203|     27|	err = inflateInit2(&gz, window_size);
  204|     27|	if (err != Z_OK)
  ------------------
  |  Branch (204:6): [True: 0, False: 27]
  ------------------
  205|      0|		return zerr_to_opensc(err);
  206|       |
  207|     27|	*outLen = 0;
  208|       |
  209|     27|	while (1) {
  ------------------
  |  Branch (209:9): [True: 27, Folded]
  ------------------
  210|       |		/* Setup buffer... */
  211|     27|		size_t num;
  212|     27|		u8* buf = realloc(*out, bufferSize);
  213|     27|		if (!buf) {
  ------------------
  |  Branch (213:7): [True: 0, False: 27]
  ------------------
  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|     27|		*out = buf;
  220|     27|		gz.next_out = buf + *outLen;
  221|     27|		gz.avail_out = (unsigned)(bufferSize - *outLen);
  222|       |
  223|     27|		err = inflate(&gz, Z_FULL_FLUSH);
  224|     27|		if (err != Z_STREAM_END && err != Z_OK) {
  ------------------
  |  Branch (224:7): [True: 27, False: 0]
  |  Branch (224:30): [True: 27, False: 0]
  ------------------
  225|     27|			free(*out);
  226|     27|			*out = NULL;
  227|     27|			break;
  228|     27|		}
  229|      0|		num = *outLen + gz.avail_out;
  230|      0|		if (bufferSize > num) {
  ------------------
  |  Branch (230:7): [True: 0, False: 0]
  ------------------
  231|      0|			*outLen += bufferSize - num;
  232|      0|			bufferSize += bufferSize - num + blockSize;
  233|      0|		}
  234|      0|		if (err == Z_STREAM_END) {
  ------------------
  |  Branch (234:7): [True: 0, False: 0]
  ------------------
  235|      0|			if (*outLen > 0) {
  ------------------
  |  Branch (235:8): [True: 0, False: 0]
  ------------------
  236|       |				/* Shrink it down, if it fails, just use old data */
  237|      0|				buf = realloc(buf, *outLen);
  238|      0|				if (buf) {
  ------------------
  |  Branch (238:9): [True: 0, False: 0]
  ------------------
  239|      0|					*out = buf;
  240|      0|				}
  241|      0|			} else {
  242|      0|				free(*out);
  243|      0|				*out = NULL;
  244|      0|				err = Z_DATA_ERROR;
  245|      0|			}
  246|      0|			break;
  247|      0|		}
  248|      0|	}
  249|     27|	inflateEnd(&gz);
  250|     27|	return zerr_to_opensc(err);
  251|     27|}

_sc_delete_reader:
   86|  8.49k|{
   87|  8.49k|	if (reader == NULL) {
  ------------------
  |  Branch (87:6): [True: 0, False: 8.49k]
  ------------------
   88|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   89|      0|	}
   90|  8.49k|	if (reader->ops->release)
  ------------------
  |  Branch (90:6): [True: 8.49k, False: 0]
  ------------------
   91|  8.49k|			reader->ops->release(reader);
   92|  8.49k|	free(reader->name);
   93|  8.49k|	free(reader->vendor);
   94|  8.49k|	list_delete(&ctx->readers, reader);
   95|  8.49k|	free(reader);
   96|  8.49k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.49k|#define SC_SUCCESS				0
  ------------------
   97|  8.49k|}
sc_ctx_detect_readers:
  782|  8.50k|{
  783|  8.50k|	int r = 0;
  784|  8.50k|	const struct sc_reader_driver *drv = ctx->reader_driver;
  785|       |
  786|  8.50k|	sc_mutex_lock(ctx, ctx->mutex);
  787|       |
  788|  8.50k|	if (drv->ops->detect_readers != NULL)
  ------------------
  |  Branch (788:6): [True: 0, False: 8.50k]
  ------------------
  789|      0|		r = drv->ops->detect_readers(ctx);
  790|       |
  791|  8.50k|	sc_mutex_unlock(ctx, ctx->mutex);
  792|       |
  793|  8.50k|	return r;
  794|  8.50k|}
sc_ctx_get_reader:
  797|  8.49k|{
  798|  8.49k|	return list_get_at(&ctx->readers, i);
  799|  8.49k|}
sc_context_create:
  946|  8.50k|{
  947|  8.50k|	sc_context_t		*ctx;
  948|  8.50k|	struct _sc_ctx_options	opts;
  949|  8.50k|	int			r;
  950|  8.50k|	char			*driver;
  951|       |
  952|  8.50k|	if (ctx_out == NULL || parm == NULL)
  ------------------
  |  Branch (952:6): [True: 0, False: 8.50k]
  |  Branch (952:25): [True: 0, False: 8.50k]
  ------------------
  953|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  954|       |
  955|  8.50k|	ctx = calloc(1, sizeof(sc_context_t));
  956|  8.50k|	if (ctx == NULL)
  ------------------
  |  Branch (956:6): [True: 0, False: 8.50k]
  ------------------
  957|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  958|  8.50k|	memset(&opts, 0, sizeof(opts));
  959|       |
  960|       |	/* set the application name if set in the parameter options */
  961|  8.50k|	if (parm->app_name != NULL)
  ------------------
  |  Branch (961:6): [True: 8.50k, False: 0]
  ------------------
  962|  8.50k|		ctx->app_name = strdup(parm->app_name);
  963|      0|	else
  964|      0|		ctx->app_name = strdup("default");
  965|  8.50k|	if (ctx->app_name == NULL) {
  ------------------
  |  Branch (965:6): [True: 0, False: 8.50k]
  ------------------
  966|      0|		sc_release_context(ctx);
  967|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  968|      0|	}
  969|       |
  970|  8.50k|	ctx->exe_path = get_exe_path();
  971|  8.50k|	if (ctx->exe_path == NULL) {
  ------------------
  |  Branch (971:6): [True: 0, False: 8.50k]
  ------------------
  972|      0|		sc_release_context(ctx);
  973|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  974|      0|	}
  975|       |
  976|  8.50k|	ctx->flags = parm->flags;
  977|  8.50k|	set_defaults(ctx, &opts);
  978|       |
  979|  8.50k|	if (0 != list_init(&ctx->readers)) {
  ------------------
  |  Branch (979:6): [True: 0, False: 8.50k]
  ------------------
  980|      0|		del_drvs(&opts);
  981|      0|		sc_release_context(ctx);
  982|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  983|      0|	}
  984|  8.50k|	list_attributes_seeker(&ctx->readers, reader_list_seeker);
  985|       |	/* set thread context and create mutex object (if specified) */
  986|  8.50k|	if (parm->thread_ctx != NULL)
  ------------------
  |  Branch (986:6): [True: 0, False: 8.50k]
  ------------------
  987|      0|		ctx->thread_ctx = parm->thread_ctx;
  988|  8.50k|	r = sc_mutex_create(ctx, &ctx->mutex);
  989|  8.50k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
  |  Branch (989:6): [True: 0, False: 8.50k]
  ------------------
  990|      0|		del_drvs(&opts);
  991|      0|		sc_release_context(ctx);
  992|      0|		return r;
  993|      0|	}
  994|       |
  995|       |#if defined(ENABLE_OPENSSL) && defined(OPENSSL_SECURE_MALLOC_SIZE) && !defined(LIBRESSL_VERSION_NUMBER)
  996|       |	if (!CRYPTO_secure_malloc_initialized()) {
  997|       |		CRYPTO_secure_malloc_init(OPENSSL_SECURE_MALLOC_SIZE, OPENSSL_SECURE_MALLOC_SIZE/8);
  998|       |	}
  999|       |#endif
 1000|       |
 1001|  8.50k|	process_config_file(ctx, &opts);
 1002|       |
 1003|       |	/* overwrite with caller's parameters if explicitly given */
 1004|  8.50k|	if (parm->debug) {
  ------------------
  |  Branch (1004:6): [True: 2.26k, False: 6.23k]
  ------------------
 1005|  2.26k|		ctx->debug = parm->debug;
 1006|  2.26k|	}
 1007|  8.50k|	if (parm->debug_file) {
  ------------------
  |  Branch (1007:6): [True: 2.26k, False: 6.23k]
  ------------------
 1008|  2.26k|		if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (1008:7): [True: 2.26k, False: 0]
  |  Branch (1008:27): [True: 0, False: 2.26k]
  |  Branch (1008:56): [True: 0, False: 0]
  ------------------
 1009|      0|			fclose(ctx->debug_file);
 1010|  2.26k|		ctx->debug_file = parm->debug_file;
 1011|  2.26k|	}
 1012|       |
 1013|  8.50k|	sc_log(ctx, "==================================="); /* first thing in the log */
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
 1014|  8.50k|	sc_log(ctx, "OpenSC version: %s", sc_get_version());
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
 1015|  8.50k|	sc_log(ctx, "Configured for %s (%s)", ctx->app_name, ctx->exe_path);
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
 1016|       |
 1017|       |#ifdef USE_OPENSSL3_LIBCTX
 1018|       |	r = sc_openssl3_init(ctx);
 1019|       |	if (r != SC_SUCCESS) {
 1020|       |		del_drvs(&opts);
 1021|       |		sc_release_context(ctx);
 1022|       |		return r;
 1023|       |	}
 1024|       |#endif
 1025|       |
 1026|       |#ifdef ENABLE_PCSC
 1027|       |	ctx->reader_driver = sc_get_pcsc_driver();
 1028|       |#elif defined(ENABLE_CRYPTOTOKENKIT)
 1029|       |	ctx->reader_driver = sc_get_cryptotokenkit_driver();
 1030|       |#elif defined(ENABLE_CTAPI)
 1031|       |	ctx->reader_driver = sc_get_ctapi_driver();
 1032|       |#elif defined(ENABLE_OPENCT)
 1033|       |	ctx->reader_driver = sc_get_openct_driver();
 1034|       |#else
 1035|       |	ctx->reader_driver = sc_get_empty_driver();
 1036|       |#endif
 1037|       |
 1038|  8.50k|	r = ctx->reader_driver->ops->init(ctx);
 1039|  8.50k|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1039:6): [True: 0, False: 8.50k]
  ------------------
 1040|      0|		del_drvs(&opts);
 1041|      0|		sc_release_context(ctx);
 1042|      0|		return r;
 1043|      0|	}
 1044|       |
 1045|  8.50k|	driver = getenv("OPENSC_DRIVER");
 1046|  8.50k|	if (driver) {
  ------------------
  |  Branch (1046:6): [True: 0, False: 8.50k]
  ------------------
 1047|      0|		scconf_list *list = NULL;
 1048|      0|		scconf_list_add(&list, driver);
 1049|      0|		set_drivers(&opts, list);
 1050|      0|		scconf_list_destroy(list);
 1051|      0|	}
 1052|       |
 1053|  8.50k|	load_card_drivers(ctx, &opts);
 1054|  8.50k|	load_card_atrs(ctx);
 1055|       |
 1056|  8.50k|	del_drvs(&opts);
 1057|  8.50k|	sc_ctx_detect_readers(ctx);
 1058|  8.50k|	*ctx_out = ctx;
 1059|       |
 1060|  8.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
 1061|  8.50k|}
sc_release_context:
 1094|  8.50k|{
 1095|  8.50k|	unsigned int i;
 1096|       |
 1097|  8.50k|	if (ctx == NULL) {
  ------------------
  |  Branch (1097:6): [True: 0, False: 8.50k]
  ------------------
 1098|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1099|      0|	}
 1100|  8.50k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  8.50k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  8.50k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  8.50k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8.50k]
  |  |  ------------------
  ------------------
 1101|  16.9k|	while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (1101:9): [True: 8.49k, False: 8.50k]
  ------------------
 1102|  8.49k|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
 1103|  8.49k|		_sc_delete_reader(ctx, rdr);
 1104|  8.49k|	}
 1105|       |
 1106|  8.50k|	if (ctx->reader_driver != NULL && ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (1106:6): [True: 8.50k, False: 0]
  |  Branch (1106:36): [True: 9, False: 8.49k]
  ------------------
 1107|      9|		ctx->reader_driver->ops->finish(ctx);
 1108|       |
 1109|   391k|	for (i = 0; ctx->card_drivers[i]; i++) {
  ------------------
  |  Branch (1109:14): [True: 382k, False: 8.50k]
  ------------------
 1110|   382k|		struct sc_card_driver *drv = ctx->card_drivers[i];
 1111|       |
 1112|   382k|		if (drv->atr_map)
  ------------------
  |  Branch (1112:7): [True: 0, False: 382k]
  ------------------
 1113|      0|			_sc_free_atr(ctx, drv);
 1114|   382k|		if (drv->dll)
  ------------------
  |  Branch (1114:7): [True: 0, False: 382k]
  ------------------
 1115|      0|			sc_dlclose(drv->dll);
 1116|   382k|	}
 1117|       |#ifdef USE_OPENSSL3_LIBCTX
 1118|       |	sc_openssl3_deinit(ctx);
 1119|       |#endif
 1120|  8.50k|	if (ctx->preferred_language != NULL)
  ------------------
  |  Branch (1120:6): [True: 0, False: 8.50k]
  ------------------
 1121|      0|		free(ctx->preferred_language);
 1122|  8.50k|	if (ctx->mutex != NULL) {
  ------------------
  |  Branch (1122:6): [True: 0, False: 8.50k]
  ------------------
 1123|      0|		int r = sc_mutex_destroy(ctx, ctx->mutex);
 1124|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1124:7): [True: 0, False: 0]
  ------------------
 1125|      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__
  |  |  ------------------
  ------------------
 1126|      0|			return r;
 1127|      0|		}
 1128|      0|	}
 1129|  8.50k|	if (ctx->conf != NULL)
  ------------------
  |  Branch (1129:6): [True: 8.50k, False: 0]
  ------------------
 1130|  8.50k|		scconf_free(ctx->conf);
 1131|  8.50k|	if (ctx->debug_file && (ctx->debug_file != stdout && ctx->debug_file != stderr))
  ------------------
  |  Branch (1131:6): [True: 8.50k, False: 0]
  |  Branch (1131:26): [True: 6.23k, False: 2.26k]
  |  Branch (1131:55): [True: 0, False: 6.23k]
  ------------------
 1132|      0|		fclose(ctx->debug_file);
 1133|  8.50k|	free(ctx->debug_filename);
 1134|  8.50k|	free(ctx->app_name);
 1135|  8.50k|	free(ctx->exe_path);
 1136|  8.50k|	list_destroy(&ctx->readers);
 1137|  8.50k|	sc_mem_clear(ctx, sizeof(*ctx));
 1138|  8.50k|	free(ctx);
 1139|  8.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
 1140|  8.50k|}
sc_get_cache_dir:
 1167|  1.08k|{
 1168|  1.08k|	char *homedir;
 1169|  1.08k|	const char *cache_dir;
 1170|  1.08k|        scconf_block *conf_block = NULL;
 1171|       |#ifdef _WIN32
 1172|       |	char temp_path[PATH_MAX];
 1173|       |#endif
 1174|  1.08k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1175|  1.08k|	cache_dir = scconf_get_str(conf_block, "file_cache_dir", NULL);
 1176|  1.08k|	if (cache_dir != NULL) {
  ------------------
  |  Branch (1176:6): [True: 0, False: 1.08k]
  ------------------
 1177|      0|		strlcpy(buf, cache_dir, bufsize);
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1178|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1179|      0|	}
 1180|       |
 1181|  1.08k|#ifndef _WIN32
 1182|       |#ifdef __APPLE__
 1183|       |	cache_dir = getenv("Caches");
 1184|       |#else
 1185|  1.08k|	cache_dir = getenv("XDG_CACHE_HOME");
 1186|  1.08k|#endif
 1187|  1.08k|	if (cache_dir != NULL && cache_dir[0] != '\0') {
  ------------------
  |  Branch (1187:6): [True: 0, False: 1.08k]
  |  Branch (1187:27): [True: 0, False: 0]
  ------------------
 1188|      0|		snprintf(buf, bufsize, "%s/%s", cache_dir, "opensc");
 1189|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1190|      0|	}
 1191|  1.08k|	cache_dir = ".cache/opensc";
 1192|  1.08k|	homedir = getenv("HOME");
 1193|       |#else
 1194|       |	cache_dir = "eid-cache";
 1195|       |	homedir = getenv("USERPROFILE");
 1196|       |	/* If USERPROFILE isn't defined, assume it's a single-user OS
 1197|       |	 * and put the cache dir in the Windows dir (usually C:\\WINDOWS) */
 1198|       |	if (homedir == NULL || homedir[0] == '\0') {
 1199|       |		GetWindowsDirectoryA(temp_path, sizeof(temp_path));
 1200|       |		homedir = temp_path;
 1201|       |	}
 1202|       |#endif
 1203|  1.08k|	if (homedir == NULL || homedir[0] == '\0')
  ------------------
  |  Branch (1203:6): [True: 0, False: 1.08k]
  |  Branch (1203:25): [True: 0, False: 1.08k]
  ------------------
 1204|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1205|  1.08k|	if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
  ------------------
  |  Branch (1205:6): [True: 0, False: 1.08k]
  ------------------
 1206|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1207|  1.08k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.08k|#define SC_SUCCESS				0
  ------------------
 1208|  1.08k|}
sc_make_cache_dir:
 1211|     68|{
 1212|     68|	char dirname[PATH_MAX], *sp;
 1213|     68|	int    r, mkdir_checker;
 1214|     68|	size_t j, namelen;
 1215|       |
 1216|     68|	if ((r = sc_get_cache_dir(ctx, dirname, sizeof(dirname))) < 0)
  ------------------
  |  Branch (1216:6): [True: 0, False: 68]
  ------------------
 1217|      0|		return r;
 1218|     68|	namelen = strlen(dirname);
 1219|       |
 1220|     68|	while (1) {
  ------------------
  |  Branch (1220:9): [True: 68, Folded]
  ------------------
 1221|       |#ifdef _WIN32
 1222|       |		mkdir_checker = mkdir(dirname) >= 0;
 1223|       |#else
 1224|     68|		mkdir_checker = mkdir(dirname, 0700) >= 0;
 1225|     68|#endif
 1226|     68|		if (mkdir_checker)
  ------------------
  |  Branch (1226:7): [True: 5, False: 63]
  ------------------
 1227|      5|			break;
 1228|       |
 1229|     63|		if (errno != ENOENT || (sp = strrchr(dirname, '/')) == NULL
  ------------------
  |  Branch (1229:7): [True: 63, False: 0]
  |  Branch (1229:26): [True: 0, False: 0]
  ------------------
 1230|      0|				|| sp == dirname)
  ------------------
  |  Branch (1230:8): [True: 0, False: 0]
  ------------------
 1231|     63|			goto failed;
 1232|      0|		*sp = '\0';
 1233|      0|	}
 1234|       |
 1235|       |	/* We may have stripped one or more path components from
 1236|       |	 * the directory name. Restore them */
 1237|      5|	while (1) {
  ------------------
  |  Branch (1237:9): [True: 5, Folded]
  ------------------
 1238|      5|		j = strlen(dirname);
 1239|      5|		if (j >= namelen)
  ------------------
  |  Branch (1239:7): [True: 5, False: 0]
  ------------------
 1240|      5|			break;
 1241|      0|		dirname[j] = '/';
 1242|       |#ifdef _WIN32
 1243|       |		mkdir_checker = mkdir(dirname) < 0;
 1244|       |#else
 1245|      0|		mkdir_checker = mkdir(dirname, 0700) < 0;
 1246|      0|#endif
 1247|      0|		if (mkdir_checker)
  ------------------
  |  Branch (1247:7): [True: 0, False: 0]
  ------------------
 1248|      0|			goto failed;
 1249|      0|	}
 1250|      5|	return SC_SUCCESS;
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
 1251|       |
 1252|       |	/* for lack of a better return code */
 1253|     63|failed:
 1254|     63|	sc_log(ctx, "failed to create cache directory");
  ------------------
  |  |   71|     63|#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|     63|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     63|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1256|      5|}
ctx.c:load_card_atrs:
  630|  8.50k|{
  631|  8.50k|	struct sc_card_driver *driver;
  632|  8.50k|	scconf_block **blocks;
  633|  8.50k|	int i, j, k;
  634|       |
  635|  17.0k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (635:14): [True: 8.50k, False: 8.50k]
  ------------------
  636|  8.50k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "card_atr", NULL);
  637|  8.50k|		if (!blocks)
  ------------------
  |  Branch (637:7): [True: 0, False: 8.50k]
  ------------------
  638|      0|			continue;
  639|  8.50k|		for (j = 0; blocks[j] != NULL; j++) {
  ------------------
  |  Branch (639:15): [True: 0, False: 8.50k]
  ------------------
  640|      0|			scconf_block *b = blocks[j];
  641|      0|			char *atr = b->name->data;
  642|      0|			const scconf_list *list;
  643|      0|			struct sc_atr_table t;
  644|      0|			const char *dname;
  645|       |
  646|      0|			driver = NULL;
  647|       |
  648|      0|			if (strlen(atr) < 4)
  ------------------
  |  Branch (648:8): [True: 0, False: 0]
  ------------------
  649|      0|				continue;
  650|       |
  651|       |			/* The interesting part. If there's no card
  652|       |			 * driver assigned for the ATR, add it to
  653|       |			 * the default driver. This will reduce the
  654|       |			 * amount of code required to process things
  655|       |			 * related to card_atr blocks in situations,
  656|       |			 * where the code is not exactly related to
  657|       |			 * card driver settings, but for example
  658|       |			 * forcing a protocol at the reader driver.
  659|       |			 */
  660|      0|			dname = scconf_get_str(b, "driver", "default");
  661|       |
  662|       |			/* Find the card driver structure according to dname */
  663|      0|			for (k = 0; ctx->card_drivers[k] != NULL; k++) {
  ------------------
  |  Branch (663:16): [True: 0, False: 0]
  ------------------
  664|      0|				driver = ctx->card_drivers[k];
  665|      0|				if (!strcmp(dname, driver->short_name))
  ------------------
  |  Branch (665:9): [True: 0, False: 0]
  ------------------
  666|      0|					break;
  667|      0|				driver = NULL;
  668|      0|			}
  669|       |
  670|      0|			if (!driver)
  ------------------
  |  Branch (670:8): [True: 0, False: 0]
  ------------------
  671|      0|				continue;
  672|       |
  673|      0|			memset(&t, 0, sizeof(struct sc_atr_table));
  674|      0|			t.atr = atr;
  675|      0|			t.atrmask = (char *) scconf_get_str(b, "atrmask", NULL);
  676|      0|			t.name = (char *) scconf_get_str(b, "name", NULL);
  677|      0|			t.type = scconf_get_int(b, "type", SC_CARD_TYPE_UNKNOWN);
  678|      0|			list = scconf_find_list(b, "flags");
  679|      0|			while (list != NULL) {
  ------------------
  |  Branch (679:11): [True: 0, False: 0]
  ------------------
  680|      0|				unsigned int flags = 0;
  681|       |
  682|      0|				if (!list->data) {
  ------------------
  |  Branch (682:9): [True: 0, False: 0]
  ------------------
  683|      0|					list = list->next;
  684|      0|					continue;
  685|      0|				}
  686|       |
  687|      0|				if (!strcmp(list->data, "rng"))
  ------------------
  |  Branch (687:9): [True: 0, False: 0]
  ------------------
  688|      0|					flags = SC_CARD_FLAG_RNG;
  ------------------
  |  |  536|      0|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  689|      0|				else if (!strcmp(list->data, "keep_alive"))
  ------------------
  |  Branch (689:14): [True: 0, False: 0]
  ------------------
  690|      0|					flags = SC_CARD_FLAG_KEEP_ALIVE;
  ------------------
  |  |  537|      0|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  691|      0|				else if (sscanf(list->data, "%x", &flags) != 1)
  ------------------
  |  Branch (691:14): [True: 0, False: 0]
  ------------------
  692|      0|					flags = 0;
  693|       |
  694|      0|				t.flags |= flags;
  695|      0|				list = list->next;
  696|      0|			}
  697|      0|			t.card_atr = b;
  698|      0|			_sc_add_atr(ctx, driver, &t);
  699|      0|		}
  700|  8.50k|		free(blocks);
  701|  8.50k|	}
  702|  8.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
  703|  8.50k|}
ctx.c:get_exe_path:
  911|  8.50k|{
  912|       |	/* Find the executable's path which runs this code.
  913|       |	 * See https://github.com/gpakosz/whereami/ for
  914|       |	 * potentially more platforms */
  915|  8.50k|	char exe_path[PATH_MAX] = "unknown executable path";
  916|  8.50k|	int path_found = 0;
  917|       |
  918|       |#if   defined(_WIN32)
  919|       |	if (0 < GetModuleFileNameA(NULL, exe_path, sizeof exe_path))
  920|       |		path_found = 1;
  921|       |#elif defined(__APPLE__)
  922|       |	if (0 < proc_pidpath(getpid(), exe_path, sizeof exe_path))
  923|       |		path_found = 1;
  924|       |#elif defined(__linux__) || defined(__CYGWIN__)
  925|  8.50k|	if (NULL != realpath("/proc/self/exe", exe_path))
  ------------------
  |  Branch (925:6): [True: 8.50k, False: 0]
  ------------------
  926|  8.50k|		path_found = 1;
  927|  8.50k|#endif
  928|       |
  929|       |#if defined(HAVE_GETPROGNAME)
  930|       |	if (!path_found) {
  931|       |		/* getprogname is unreliable and typically only returns the basename.
  932|       |		 * However, this should be enough for our purposes */
  933|       |		const char *prog = getprogname();
  934|       |		if (prog)
  935|       |			strlcpy(exe_path, prog, sizeof exe_path);
  936|       |	}
  937|       |#else
  938|       |	/* avoid warning "set but not used" */
  939|  8.50k|	(void) path_found;
  940|  8.50k|#endif
  941|       |
  942|  8.50k|	return strdup(exe_path);
  943|  8.50k|}
ctx.c:set_defaults:
  322|  8.50k|{
  323|  8.50k|	ctx->debug = 0;
  324|  8.50k|	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (324:6): [True: 0, False: 8.50k]
  |  Branch (324:26): [True: 0, False: 0]
  |  Branch (324:55): [True: 0, False: 0]
  ------------------
  325|      0|		fclose(ctx->debug_file);
  326|  8.50k|	ctx->debug_file = stderr;
  327|  8.50k|	ctx->flags = 0;
  328|       |	ctx->forced_driver = NULL;
  329|  8.50k|	add_internal_drvs(opts);
  330|  8.50k|}
ctx.c:add_internal_drvs:
  296|  17.0k|{
  297|  17.0k|	const struct _sc_driver_entry *lst;
  298|  17.0k|	int i;
  299|       |
  300|  17.0k|	lst = internal_card_drivers;
  301|  17.0k|	i = 0;
  302|   697k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (302:9): [True: 680k, False: 17.0k]
  ------------------
  303|   680k|		add_drv(opts, lst[i].name);
  304|   680k|		i++;
  305|   680k|	}
  306|  17.0k|}
ctx.c:add_drv:
  278|   722k|{
  279|   722k|	struct _sc_driver_entry *lst;
  280|   722k|	int *cp, max, i;
  281|       |
  282|   722k|	lst = opts->cdrv;
  283|   722k|	cp = &opts->ccount;
  284|   722k|	max = SC_MAX_CARD_DRIVERS;
  ------------------
  |  |   31|   722k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  285|   722k|	if (*cp == max) /* No space for more drivers... */
  ------------------
  |  Branch (285:6): [True: 0, False: 722k]
  ------------------
  286|      0|		return;
  287|  15.7M|	for (i = 0; i < *cp; i++)
  ------------------
  |  Branch (287:14): [True: 15.0M, False: 722k]
  ------------------
  288|  15.0M|		if (strcmp(name, lst[i].name) == 0)
  ------------------
  |  Branch (288:7): [True: 0, False: 15.0M]
  ------------------
  289|      0|			return;
  290|   722k|	lst[*cp].name = strdup(name);
  291|       |
  292|   722k|	*cp = *cp + 1;
  293|   722k|}
ctx.c:del_drvs:
  264|  17.0k|{
  265|  17.0k|	struct _sc_driver_entry *lst;
  266|  17.0k|	int *cp, i;
  267|       |
  268|  17.0k|	lst = opts->cdrv;
  269|  17.0k|	cp = &opts->ccount;
  270|       |
  271|   739k|	for (i = 0; i < *cp; i++) {
  ------------------
  |  Branch (271:14): [True: 722k, False: 17.0k]
  ------------------
  272|   722k|		free((void *)lst[i].name);
  273|   722k|	}
  274|  17.0k|	*cp = 0;
  275|  17.0k|}
ctx.c:process_config_file:
  706|  8.50k|{
  707|  8.50k|	int i, r, count = 0;
  708|  8.50k|	scconf_block **blocks;
  709|  8.50k|	const char *conf_path = NULL;
  710|  8.50k|	const char *debug = NULL;
  711|       |#ifdef _WIN32
  712|       |	char temp_path[PATH_MAX];
  713|       |	size_t temp_len;
  714|       |#endif
  715|       |
  716|       |	/* Takes effect even when no config around */
  717|  8.50k|	debug = getenv("OPENSC_DEBUG");
  718|  8.50k|	if (debug)
  ------------------
  |  Branch (718:6): [True: 0, False: 8.50k]
  ------------------
  719|      0|		ctx->debug = atoi(debug);
  720|       |
  721|  8.50k|	memset(ctx->conf_blocks, 0, sizeof(ctx->conf_blocks));
  722|       |#ifdef _WIN32
  723|       |	temp_len = PATH_MAX-1;
  724|       |	r = sc_ctx_win32_get_config_value("OPENSC_CONF", "ConfigFile", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
  725|       |			temp_path, &temp_len);
  726|       |	if (r)   {
  727|       |		sc_log(ctx, "process_config_file doesn't find opensc config file. Please set the registry key.");
  728|       |		return;
  729|       |	}
  730|       |	temp_path[temp_len] = '\0';
  731|       |	conf_path = temp_path;
  732|       |#else
  733|  8.50k|	conf_path = getenv("OPENSC_CONF");
  734|  8.50k|	if (!conf_path)
  ------------------
  |  Branch (734:6): [True: 8.50k, False: 0]
  ------------------
  735|  8.50k|		conf_path = OPENSC_CONF_PATH;
  736|  8.50k|#endif
  737|  8.50k|	ctx->conf = scconf_new(conf_path);
  738|  8.50k|	if (ctx->conf == NULL)
  ------------------
  |  Branch (738:6): [True: 0, False: 8.50k]
  ------------------
  739|      0|		return;
  740|  8.50k|	r = scconf_parse(ctx->conf);
  741|  8.50k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  742|  8.50k|#ifdef OPENSC_CONFIG_STRING
  743|       |	/* Parse the string if config file didn't exist */
  744|  8.50k|	if (r < 0)
  ------------------
  |  Branch (744:6): [True: 8.50k, False: 0]
  ------------------
  745|  8.50k|		r = scconf_parse_string(ctx->conf, OPENSC_CONFIG_STRING);
  ------------------
  |  |  741|  8.50k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  ------------------
  746|  8.50k|#endif
  747|  8.50k|	if (r < 1) {
  ------------------
  |  Branch (747:6): [True: 0, False: 8.50k]
  ------------------
  748|       |		/* A negative return value means the config file isn't
  749|       |		 * there, which is not an error. Nevertheless log this
  750|       |		 * fact. */
  751|      0|		if (r < 0)
  ------------------
  |  Branch (751:7): [True: 0, False: 0]
  ------------------
  752|      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__
  |  |  ------------------
  ------------------
  753|      0|		else
  754|      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__
  |  |  ------------------
  ------------------
  755|      0|		scconf_free(ctx->conf);
  756|      0|		ctx->conf = NULL;
  757|      0|		return;
  758|      0|	}
  759|       |	/* needs to be after the log file is known */
  760|  8.50k|	sc_log(ctx, "Used configuration file '%s'", conf_path);
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
  761|  8.50k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->exe_path);
  762|  8.50k|	if (blocks && blocks[0])
  ------------------
  |  Branch (762:6): [True: 8.50k, False: 0]
  |  Branch (762:16): [True: 0, False: 8.50k]
  ------------------
  763|      0|		ctx->conf_blocks[count++] = blocks[0];
  764|  8.50k|	free(blocks);
  765|  8.50k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
  766|  8.50k|	if (blocks && blocks[0])
  ------------------
  |  Branch (766:6): [True: 8.50k, False: 0]
  |  Branch (766:16): [True: 0, False: 8.50k]
  ------------------
  767|      0|		ctx->conf_blocks[count++] = blocks[0];
  768|  8.50k|	free(blocks);
  769|  8.50k|	if (strcmp(ctx->app_name, "default") != 0) {
  ------------------
  |  Branch (769:6): [True: 8.50k, False: 0]
  ------------------
  770|  8.50k|		blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
  771|  8.50k|		if (blocks && blocks[0])
  ------------------
  |  Branch (771:7): [True: 8.50k, False: 0]
  |  Branch (771:17): [True: 8.50k, False: 0]
  ------------------
  772|  8.50k|			ctx->conf_blocks[count] = blocks[0];
  773|  8.50k|		free(blocks);
  774|  8.50k|	}
  775|       |	/* Above we add 3 blocks at most, but conf_blocks has 4 elements,
  776|       |	 * so at least one is NULL */
  777|  17.0k|	for (i = 0; ctx->conf_blocks[i]; i++)
  ------------------
  |  Branch (777:14): [True: 8.50k, False: 8.50k]
  ------------------
  778|  8.50k|		load_parameters(ctx, ctx->conf_blocks[i], opts);
  779|  8.50k|}
ctx.c:load_parameters:
  385|  8.50k|{
  386|  8.50k|	int err = 0;
  387|  8.50k|	const scconf_list *list;
  388|  8.50k|	const char *val;
  389|  8.50k|	int debug;
  390|  8.50k|	const char *disable_hw_pkcs1_padding;
  391|       |#ifdef _WIN32
  392|       |	char expanded_val[PATH_MAX];
  393|       |	DWORD expanded_len;
  394|       |#endif
  395|       |
  396|  8.50k|	debug = scconf_get_int(block, "debug", ctx->debug);
  397|  8.50k|	if (debug > ctx->debug)
  ------------------
  |  Branch (397:6): [True: 0, False: 8.50k]
  ------------------
  398|      0|		ctx->debug = debug;
  399|       |
  400|  8.50k|	val = scconf_get_str(block, "debug_file", NULL);
  401|  8.50k|	if (val)   {
  ------------------
  |  Branch (401:6): [True: 0, False: 8.50k]
  ------------------
  402|       |#ifdef _WIN32
  403|       |		expanded_len = PATH_MAX;
  404|       |		expanded_len = ExpandEnvironmentStringsA(val, expanded_val, expanded_len);
  405|       |		if (0 < expanded_len && expanded_len < sizeof expanded_val)
  406|       |			val = expanded_val;
  407|       |#endif
  408|      0|		sc_ctx_log_to_file(ctx, val);
  409|      0|	}
  410|  8.50k|	else if (ctx->debug)   {
  ------------------
  |  Branch (410:11): [True: 0, False: 8.50k]
  ------------------
  411|      0|		sc_ctx_log_to_file(ctx, NULL);
  412|      0|	}
  413|       |
  414|  8.50k|	if (scconf_get_bool (block, "disable_popups",
  ------------------
  |  Branch (414:6): [True: 0, False: 8.50k]
  ------------------
  415|  8.50k|				ctx->flags & SC_CTX_FLAG_DISABLE_POPUPS))
  ------------------
  |  |  861|  8.50k|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  416|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_POPUPS;
  ------------------
  |  |  861|      0|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  417|       |
  418|  8.50k|	if (scconf_get_bool (block, "disable_colors",
  ------------------
  |  Branch (418:6): [True: 0, False: 8.50k]
  ------------------
  419|  8.50k|				ctx->flags & SC_CTX_FLAG_DISABLE_COLORS))
  ------------------
  |  |  862|  8.50k|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  420|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_COLORS;
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  421|       |
  422|  8.50k|	if (scconf_get_bool (block, "enable_default_driver",
  ------------------
  |  Branch (422:6): [True: 0, False: 8.50k]
  ------------------
  423|  8.50k|				ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER))
  ------------------
  |  |  860|  8.50k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  424|      0|		ctx->flags |= SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER;
  ------------------
  |  |  860|      0|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  425|       |
  426|  8.50k|	list = scconf_find_list(block, "card_drivers");
  427|  8.50k|	set_drivers(opts, list);
  428|       |
  429|       |	/* Disable PKCS#1 v1.5 type 2 (for decryption) depadding on card by default */
  430|  8.50k|	disable_hw_pkcs1_padding = "decipher";
  431|  8.50k|	ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  8.50k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  432|  8.50k|	disable_hw_pkcs1_padding = scconf_get_str(block, "disable_hw_pkcs1_padding", disable_hw_pkcs1_padding);
  433|  8.50k|	if (0 == strcmp(disable_hw_pkcs1_padding, "no")) {
  ------------------
  |  Branch (433:6): [True: 0, False: 8.50k]
  ------------------
  434|      0|		ctx->disable_hw_pkcs1_padding = 0;
  435|  8.50k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "sign")) {
  ------------------
  |  Branch (435:13): [True: 0, False: 8.50k]
  ------------------
  436|      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 */
  ------------------
  437|  8.50k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "decipher")) {
  ------------------
  |  Branch (437:13): [True: 8.50k, False: 0]
  ------------------
  438|  8.50k|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  8.50k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  439|  8.50k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "both")) {
  ------------------
  |  Branch (439:13): [True: 0, False: 0]
  ------------------
  440|      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 */
  ------------------
  441|      0|	}
  442|       |
  443|       |#ifdef USE_OPENSSL3_LIBCTX
  444|       |	val = scconf_get_str(block, "openssl_config", NULL);
  445|       |	if (val != NULL) {
  446|       |		ctx->openssl_config = strdup(val);
  447|       |	}
  448|       |#endif
  449|       |
  450|  8.50k|	return err;
  451|  8.50k|}
ctx.c:set_drivers:
  368|  8.50k|{
  369|  8.50k|	const char *s_internal = "internal", *s_old = "old";
  370|  8.50k|	if (list != NULL)
  ------------------
  |  Branch (370:6): [True: 8.50k, False: 0]
  ------------------
  371|  8.50k|		del_drvs(opts);
  372|  25.5k|	while (list != NULL) {
  ------------------
  |  Branch (372:9): [True: 17.0k, False: 8.50k]
  ------------------
  373|  17.0k|		if (strcmp(list->data, s_internal) == 0)
  ------------------
  |  Branch (373:7): [True: 8.50k, False: 8.50k]
  ------------------
  374|  8.50k|			add_internal_drvs(opts);
  375|  8.50k|		else if (strcmp(list->data, s_old) == 0)
  ------------------
  |  Branch (375:12): [True: 8.50k, False: 0]
  ------------------
  376|  8.50k|			add_old_drvs(opts);
  377|      0|		else
  378|      0|			add_drv(opts, list->data);
  379|  17.0k|		list = list->next;
  380|  17.0k|	}
  381|  8.50k|}
ctx.c:add_old_drvs:
  309|  8.50k|{
  310|  8.50k|	const struct _sc_driver_entry *lst;
  311|  8.50k|	int i;
  312|       |
  313|  8.50k|	lst = old_card_drivers;
  314|  8.50k|	i = 0;
  315|  51.0k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (315:9): [True: 42.5k, False: 8.50k]
  ------------------
  316|  42.5k|		add_drv(opts, lst[i].name);
  317|  42.5k|		i++;
  318|  42.5k|	}
  319|  8.50k|}
ctx.c:load_card_drivers:
  564|  8.50k|{
  565|  8.50k|	const struct _sc_driver_entry *ent;
  566|  8.50k|	int drv_count;
  567|  8.50k|	int i;
  568|       |
  569|  8.50k|	for (drv_count = 0; ctx->card_drivers[drv_count] != NULL; drv_count++)
  ------------------
  |  Branch (569:22): [True: 0, False: 8.50k]
  ------------------
  570|      0|		;
  571|       |
  572|   391k|	for (i = 0; i < opts->ccount; i++) {
  ------------------
  |  Branch (572:14): [True: 382k, False: 8.50k]
  ------------------
  573|   382k|		struct sc_card_driver *(*func)(void) = NULL;
  574|   382k|		struct sc_card_driver *(**tfunc)(void) = &func;
  575|   382k|		void *dll = NULL;
  576|   382k|		int  j;
  577|       |
  578|   382k|		if (drv_count >= SC_MAX_CARD_DRIVERS - 1)   {
  ------------------
  |  |   31|   382k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  |  Branch (578:7): [True: 0, False: 382k]
  ------------------
  579|      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)
  |  |  ------------------
  |  |  |  |  579|      0|			sc_log(ctx, "Not more then %i card drivers allowed.", SC_MAX_CARD_DRIVERS);
  |  |  |  |  ------------------
  |  |  |  |  |  |   31|      0|#define SC_MAX_CARD_DRIVERS		48
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|      0|			break;
  581|      0|		}
  582|       |
  583|   382k|		ent = &opts->cdrv[i];
  584|  8.71M|		for (j = 0; internal_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (584:15): [True: 8.67M, False: 42.5k]
  ------------------
  585|  8.67M|			if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (585:8): [True: 340k, False: 8.33M]
  ------------------
  586|   340k|				func = (struct sc_card_driver *(*)(void)) internal_card_drivers[j].func;
  587|   340k|				break;
  588|   340k|			}
  589|  8.67M|		}
  590|   382k|		if (func == NULL) {
  ------------------
  |  Branch (590:7): [True: 42.5k, False: 340k]
  ------------------
  591|   127k|			for (j = 0; old_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (591:16): [True: 127k, False: 0]
  ------------------
  592|   127k|				if (strcmp(ent->name, old_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (592:9): [True: 42.5k, False: 85.0k]
  ------------------
  593|  42.5k|					func = (struct sc_card_driver *(*)(void)) old_card_drivers[j].func;
  594|  42.5k|					break;
  595|  42.5k|				}
  596|   127k|			}
  597|  42.5k|		}
  598|       |		/* if not initialized assume external module */
  599|   382k|		if (func == NULL)
  ------------------
  |  Branch (599:7): [True: 0, False: 382k]
  ------------------
  600|      0|			*(void **)(tfunc) = load_dynamic_driver(ctx, &dll, ent->name);
  601|       |		/* if still null, assume driver not found */
  602|   382k|		if (func == NULL) {
  ------------------
  |  Branch (602:7): [True: 0, False: 382k]
  ------------------
  603|      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__
  |  |  ------------------
  ------------------
  604|      0|			if (dll)
  ------------------
  |  Branch (604:8): [True: 0, False: 0]
  ------------------
  605|      0|				sc_dlclose(dll);
  606|      0|			continue;
  607|      0|		}
  608|       |
  609|   382k|		ctx->card_drivers[drv_count] = func();
  610|   382k|		if (ctx->card_drivers[drv_count] == NULL) {
  ------------------
  |  Branch (610:7): [True: 0, False: 382k]
  ------------------
  611|      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__
  |  |  ------------------
  ------------------
  612|      0|			continue;
  613|      0|		}
  614|       |
  615|   382k|		ctx->card_drivers[drv_count]->dll = dll;
  616|   382k|		ctx->card_drivers[drv_count]->atr_map = NULL;
  617|   382k|		ctx->card_drivers[drv_count]->natrs = 0;
  618|       |
  619|   382k|		load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
  620|       |
  621|       |		/* Ensure that the list is always terminated by NULL */
  622|   382k|		ctx->card_drivers[drv_count + 1] = NULL;
  623|       |
  624|   382k|		drv_count++;
  625|   382k|	}
  626|  8.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.50k|#define SC_SUCCESS				0
  ------------------
  627|  8.50k|}
ctx.c:load_card_driver_options:
  543|   382k|{
  544|   382k|	scconf_block **blocks, *blk;
  545|   382k|	int i;
  546|       |
  547|   765k|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (547:14): [True: 382k, False: 382k]
  ------------------
  548|   382k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  549|   382k|				"card_driver", driver->short_name);
  550|   382k|		if (!blocks)
  ------------------
  |  Branch (550:7): [True: 0, False: 382k]
  ------------------
  551|      0|			continue;
  552|   382k|		blk = blocks[0];
  553|   382k|		free(blocks);
  554|       |
  555|   382k|		if (blk == NULL)
  ------------------
  |  Branch (555:7): [True: 382k, False: 0]
  ------------------
  556|   382k|			continue;
  557|       |
  558|       |		/* no options at the moment */
  559|   382k|	}
  560|   382k|	return SC_SUCCESS;
  ------------------
  |  |   28|   382k|#define SC_SUCCESS				0
  ------------------
  561|   382k|}

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

cwa_create_secure_channel:
 1097|    586|{
 1098|    586|	u8 *cert = NULL;
 1099|    586|	size_t certlen;
 1100|       |
 1101|    586|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    586|#define SC_SUCCESS				0
  ------------------
 1102|    586|	char *msg = "Success";
 1103|       |
 1104|       |	/* data to get and parse certificates */
 1105|    586|	X509 *icc_cert = NULL;
 1106|    586|	X509 *ca_cert = NULL;
 1107|    586|	EVP_PKEY *icc_pubkey = NULL;
 1108|    586|	EVP_PKEY *ifd_privkey = NULL;
 1109|    586|	sc_context_t *ctx = NULL;
 1110|    586|	struct sm_cwa_session * sm = &card->sm_ctx.info.session.cwa;
 1111|    586|	u8 sig[128];
 1112|       |
 1113|       |	/* several buffer and buffer pointers */
 1114|    586|	u8 *buffer = NULL;
 1115|    586|	size_t bufferlen;
 1116|    586|	u8 *tlv = NULL;		/* buffer to compose TLV messages */
 1117|    586|	size_t tlvlen = 0;
 1118|    586|	u8 rndbuf[16]; /* 8 RND.IFD + 8 SN.IFD */
 1119|       |
 1120|       |	/* preliminary checks */
 1121|    586|	if (!card || !card->ctx )
  ------------------
  |  Branch (1121:6): [True: 0, False: 586]
  |  Branch (1121:15): [True: 0, False: 586]
  ------------------
 1122|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1123|    586|	if (!provider)
  ------------------
  |  Branch (1123:6): [True: 0, False: 586]
  ------------------
 1124|      0|		return SC_ERROR_SM_NOT_INITIALIZED;
  ------------------
  |  |  120|      0|#define SC_ERROR_SM_NOT_INITIALIZED		-1605
  ------------------
 1125|       |	/* commodity vars */
 1126|    586|	ctx = card->ctx;
 1127|       |
 1128|    586|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    586|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    586|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    586|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    586|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 586]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|       |
 1130|       |	/* check requested initialization method */
 1131|    586|	switch (flag) {
 1132|    586|	case CWA_SM_OFF:	/* disable SM */
  ------------------
  |  |   31|    586|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  |  Branch (1132:2): [True: 586, False: 0]
  ------------------
 1133|    586|		card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    586|#define SM_MODE_NONE		0x0
  ------------------
 1134|    586|		sc_log(ctx, "Setting CWA SM status to none");
  ------------------
  |  |   71|    586|#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|    586|		res = sc_select_file(card, sc_get_mf_path(), NULL);
 1137|    586|		if (res == SC_ERROR_SM)
  ------------------
  |  |  115|    586|#define SC_ERROR_SM				-1600
  ------------------
  |  Branch (1137:7): [True: 10, False: 576]
  ------------------
 1138|     10|			res = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 1139|    586|		LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|    586|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    586|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    586|	int _ret = r; \
  |  |  |  |  155|    586|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 586, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    586|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    293|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 293, False: 293]
  |  |  |  |  ------------------
  |  |  |  |  157|    586|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    586|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    586|	return _ret; \
  |  |  |  |  163|    586|} 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: 586]
  ------------------
 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: 586]
  ------------------
 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|    586|	}
 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|    306|{
 2169|    306|	cwa_provider_t *res = NULL;
 2170|    306|	if (!card || !card->ctx)
  ------------------
  |  Branch (2170:6): [True: 0, False: 306]
  |  Branch (2170:15): [True: 0, False: 306]
  ------------------
 2171|      0|		return NULL;
 2172|    306|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    306|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    306|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    306|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    306|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 306]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2173|    306|	res = calloc(1, sizeof(cwa_provider_t));
 2174|    306|	if (!res) {
  ------------------
  |  Branch (2174:6): [True: 0, False: 306]
  ------------------
 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|    306|	memcpy(res, &default_cwa_provider, sizeof(cwa_provider_t));
 2179|    306|	return res;
 2180|    306|}

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

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

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

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

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

iso7816_fixup_transceive_length:
   36|  9.85k|{
   37|  9.85k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 9.85k]
  |  Branch (37:22): [True: 0, False: 9.85k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  9.85k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 173, False: 9.67k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    173|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    173|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    173|	}
   45|       |
   46|  9.85k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 1.15k, False: 8.69k]
  ------------------
   47|       |		/* The lower layers will automatically do a GET RESPONSE, if possible.
   48|       |		 * All other workarounds must be carried out by the upper layers. */
   49|  1.15k|		apdu->le = sc_get_max_recv_size(card);
   50|  1.15k|	}
   51|  9.85k|}
encode_do_data:
  177|  2.03k|{
  178|  2.03k|	unsigned char offset_buffer[2];
  179|  2.03k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  2.03k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  2.03k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  2.03k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 2.03k]
  ------------------
  184|  2.03k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|  2.03k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  2.03k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  2.03k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  2.03k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 2.03k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  2.03k|	} else {
  192|  2.03k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  2.03k|	}
  194|       |
  195|  2.03k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  2.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.03k|	int _ret = (r); \
  |  |  |  |  168|  2.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  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.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  2.03k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  2.03k|			"sc_asn1_encode() failed");
  198|       |
  199|  2.03k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.03k|#define SC_SUCCESS				0
  ------------------
  200|  2.03k|}
decode_do_data:
  205|  1.74k|{
  206|  1.74k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  1.74k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  1.74k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  1.74k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  1.74k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  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: 142, False: 1.60k]
  |  |  |  |  ------------------
  |  |  |  |  169|    142|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    142|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    142|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    142|		return _ret; \
  |  |  |  |  172|    142|	} \
  |  |  |  |  173|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.60k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  1.60k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  1.60k|			"sc_asn1_decode() failed");
  215|       |
  216|  1.60k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  1.60k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 1.56k, False: 35]
  ------------------
  217|  1.56k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.56k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|     35|	return SC_SUCCESS;
  ------------------
  |  |   28|     35|#define SC_SUCCESS				0
  ------------------
  220|  1.60k|}
iso7816_build_pin_apdu:
 1183|  1.79k|{
 1184|  1.79k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1185|  1.79k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  1.79k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1186|       |
 1187|  1.79k|	switch (data->pin_type) {
 1188|  1.79k|	case SC_AC_CHV:
  ------------------
  |  |  151|  1.79k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1188:2): [True: 1.79k, False: 0]
  ------------------
 1189|       |		/* fall through */
 1190|  1.79k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  1.79k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1190:2): [True: 0, False: 1.79k]
  ------------------
 1191|  1.79k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  1.79k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1191:2): [True: 0, False: 1.79k]
  ------------------
 1192|  1.79k|		break;
 1193|      0|	default:
  ------------------
  |  Branch (1193:2): [True: 0, False: 1.79k]
  ------------------
 1194|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1195|  1.79k|	}
 1196|       |
 1197|  1.79k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|  1.79k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1197:6): [True: 257, False: 1.53k]
  ------------------
 1198|    257|		pad = 1;
 1199|  1.79k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|  1.79k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1199:6): [True: 0, False: 1.79k]
  ------------------
 1200|      0|		use_pin_pad = 1;
 1201|       |
 1202|  1.79k|	data->pin1.offset = 5;
 1203|       |
 1204|  1.79k|	switch (data->cmd) {
 1205|     85|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     85|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1205:2): [True: 85, False: 1.71k]
  ------------------
 1206|     85|		ins = 0x20;
 1207|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1208|     85|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1208:7): [True: 29, False: 56]
  |  Branch (1208:30): [True: 29, False: 0]
  ------------------
 1209|     29|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     29|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1210|     56|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1210:7): [True: 12, False: 44]
  ------------------
 1211|     12|			return r;
 1212|     44|		len = r;
 1213|     44|		break;
 1214|    177|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|    177|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1214:2): [True: 177, False: 1.61k]
  ------------------
 1215|    177|		ins = 0x24;
 1216|    177|		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 (1216:7): [True: 177, False: 0]
  |  Branch (1216:31): [True: 0, False: 0]
  |  Branch (1216:46): [True: 0, False: 0]
  ------------------
 1217|    177|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1217:8): [True: 0, False: 177]
  ------------------
 1218|      0|				return r;
 1219|    177|			len += r;
 1220|    177|		}
 1221|      0|		else {
 1222|       |			/* implicit test */
 1223|      0|			p1 = 1;
 1224|      0|		}
 1225|       |
 1226|    177|		data->pin2.offset = data->pin1.offset + len;
 1227|    177|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1227:7): [True: 0, False: 177]
  ------------------
 1228|      0|			return r;
 1229|       |		/* Special case - where provided the old PIN on the command line
 1230|       |		 * but expect the new one to be entered on the keypad.
 1231|       |		 */
 1232|    177|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1232:7): [True: 177, False: 0]
  |  Branch (1232:25): [True: 0, False: 177]
  ------------------
 1233|      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__
  |  |  ------------------
  ------------------
 1234|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1235|      0|		};
 1236|    177|		len += r;
 1237|    177|		break;
 1238|      6|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      6|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1238:2): [True: 6, False: 1.78k]
  ------------------
 1239|      6|		ins = 0x2C;
 1240|      6|		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 (1240:7): [True: 6, False: 0]
  |  Branch (1240:31): [True: 0, False: 0]
  |  Branch (1240:46): [True: 0, False: 0]
  ------------------
 1241|      6|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1241:8): [True: 0, False: 6]
  ------------------
 1242|      0|				return r;
 1243|      6|			len += r;
 1244|      6|		} else {
 1245|      0|			p1 |= 0x02;
 1246|      0|		}
 1247|       |
 1248|      6|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1248:7): [True: 6, False: 0]
  |  Branch (1248:30): [True: 0, False: 0]
  ------------------
 1249|      6|			data->pin2.offset = data->pin1.offset + len;
 1250|      6|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1250:8): [True: 0, False: 6]
  ------------------
 1251|      0|				return r;
 1252|      6|			len += r;
 1253|      6|		} else {
 1254|      0|			p1 |= 0x01;
 1255|      0|		}
 1256|      6|		if (p1 == 0x03) {
  ------------------
  |  Branch (1256:7): [True: 0, False: 6]
  ------------------
 1257|       |			/* No data to send or to receive */
 1258|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1259|      0|		}
 1260|      6|		break;
 1261|  1.52k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|  1.52k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1261:2): [True: 1.52k, False: 268]
  ------------------
 1262|  1.52k|		ins = 0x20;
 1263|       |		/* No data to send or to receive */
 1264|  1.52k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  1.52k|#define SC_APDU_CASE_1			0x01
  ------------------
 1265|  1.52k|		break;
 1266|      0|	default:
  ------------------
  |  Branch (1266:2): [True: 0, False: 1.79k]
  ------------------
 1267|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1268|  1.79k|	}
 1269|       |
 1270|  1.75k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1271|  1.75k|	apdu->lc = len;
 1272|  1.75k|	apdu->datalen = len;
 1273|  1.75k|	apdu->data = buf;
 1274|  1.75k|	apdu->resplen = 0;
 1275|       |
 1276|  1.75k|	return 0;
 1277|  1.79k|}
iso7816_select_aid:
 1395|  17.5k|{
 1396|  17.5k|	struct sc_context *ctx = card->ctx;
 1397|  17.5k|	struct sc_apdu apdu;
 1398|  17.5k|	int rv;
 1399|       |
 1400|  17.5k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  17.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  17.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  17.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 17.5k]
  |  |  ------------------
  ------------------
 1401|       |
 1402|  17.5k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  3.46k|#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|  14.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1402:30): [True: 3.46k, False: 14.0k]
  |  Branch (1402:102): [True: 3.46k, False: 14.0k]
  ------------------
 1403|  17.5k|	apdu.lc = reqlen;
 1404|  17.5k|	apdu.data = req;
 1405|  17.5k|	apdu.datalen = reqlen;
 1406|  17.5k|	apdu.resp = resp;
 1407|  17.5k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1407:17): [True: 3.46k, False: 14.0k]
  ------------------
 1408|  17.5k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1408:12): [True: 3.46k, False: 14.0k]
  ------------------
 1409|       |
 1410|  17.5k|	rv = sc_transmit_apdu(card, &apdu);
 1411|  17.5k|	if (resplen)
  ------------------
  |  Branch (1411:6): [True: 14.0k, False: 3.46k]
  ------------------
 1412|  14.0k|		*resplen = apdu.resplen;
 1413|  17.5k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  17.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  17.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  17.5k|	int _ret = (r); \
  |  |  |  |  168|  17.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 365, False: 17.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|    365|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    365|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    365|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    365|		return _ret; \
  |  |  |  |  172|    365|	} \
  |  |  |  |  173|  17.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1414|       |
 1415|  17.1k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1416|  17.1k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  17.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.1k|	int _ret = r; \
  |  |  |  |  155|  17.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.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|  15.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.2k, False: 1.94k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.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|  17.1k|	return _ret; \
  |  |  |  |  163|  17.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1417|  17.1k|}
sc_get_iso7816_driver:
 1485|   310k|{
 1486|   310k|	return &iso_driver;
 1487|   310k|}
iso7816.c:no_match:
 1431|  5.08k|{
 1432|  5.08k|	return 0;
 1433|  5.08k|}
iso7816.c:iso7816_read_record:
  225|  4.58k|{
  226|  4.58k|	struct sc_apdu apdu;
  227|  4.58k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  4.58k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  4.58k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  4.58k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  4.58k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 1, False: 4.58k]
  ------------------
  234|  4.58k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  4.58k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 2.55k, False: 2.03k]
  ------------------
  237|  2.55k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  2.55k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  2.55k|		apdu.le = count;
  239|  2.55k|		apdu.resplen = count;
  240|  2.55k|		apdu.resp = buf;
  241|  2.55k|	} else {
  242|  2.03k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  2.03k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  2.03k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.03k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.03k|	int _ret = (r); \
  |  |  |  |  178|  2.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  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.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  2.03k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  2.03k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  2.03k|		apdu.lc = encoded_data_len;
  247|  2.03k|		apdu.datalen = encoded_data_len;
  248|  2.03k|		apdu.data = encoded_data;
  249|  2.03k|		apdu.le = sizeof resp;
  250|  2.03k|		apdu.resplen = sizeof resp;
  251|  2.03k|		apdu.resp = resp;
  252|  2.03k|	}
  253|  4.58k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  4.58k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  4.58k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  4.58k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 4.58k, False: 0]
  ------------------
  255|  4.58k|		apdu.p2 |= 0x04;
  256|       |
  257|  4.58k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  4.58k|	r = sc_transmit_apdu(card, &apdu);
  259|  4.58k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  4.58k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.58k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.58k|	int _ret = (r); \
  |  |  |  |  178|  4.58k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 138, False: 4.45k]
  |  |  |  |  ------------------
  |  |  |  |  179|    138|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    138|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    138|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    138|		goto err; \
  |  |  |  |  182|    138|	} \
  |  |  |  |  183|  4.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  4.45k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  4.45k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  4.45k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.45k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.45k|	int _ret = (r); \
  |  |  |  |  178|  4.45k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 442, False: 4.00k]
  |  |  |  |  ------------------
  |  |  |  |  179|    442|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    442|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    442|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    442|		goto err; \
  |  |  |  |  182|    442|	} \
  |  |  |  |  183|  4.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  4.00k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 2.26k, False: 1.74k]
  ------------------
  264|  2.26k|		r = (int)apdu.resplen;
  265|  2.26k|	} else {
  266|  1.74k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  1.74k|				&decoded_data, &decoded_data_len);
  268|  1.74k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  1.74k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.74k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.74k|	int _ret = (r); \
  |  |  |  |  178|  1.74k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.71k, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.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|  1.71k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.71k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.71k|		goto err; \
  |  |  |  |  182|  1.71k|	} \
  |  |  |  |  183|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|     35|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 22, False: 13]
  ------------------
  270|     22|			count = decoded_data_len;
  271|     22|		}
  272|     35|		memcpy(buf, decoded_data, count);
  273|     35|		r = (int)count;
  274|     35|	}
  275|       |
  276|  4.58k|err:
  277|  4.58k|	free(encoded_data);
  278|  4.58k|	free(decoded_data);
  279|  4.58k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.58k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.58k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.58k|	int _ret = r; \
  |  |  |  |  155|  4.58k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.35k, False: 2.23k]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.35k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.29k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.29k, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.35k|	} else { \
  |  |  |  |  159|  2.23k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.23k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.23k|	} \
  |  |  |  |  162|  4.58k|	return _ret; \
  |  |  |  |  163|  4.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  4.58k|}
iso7816.c:iso7816_select_file:
  629|  24.7k|{
  630|  24.7k|	struct sc_context *ctx;
  631|  24.7k|	struct sc_apdu apdu;
  632|  24.7k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  633|  24.7k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  634|  24.7k|	int r, pathtype;
  635|  24.7k|	size_t pathlen;
  636|  24.7k|	int select_mf = 0;
  637|  24.7k|	struct sc_file *file = NULL;
  638|  24.7k|	const u8 *buffer;
  639|  24.7k|	size_t buffer_len;
  640|  24.7k|	unsigned int cla, tag;
  641|       |
  642|  24.7k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 24.7k]
  |  Branch (642:22): [True: 0, False: 24.7k]
  ------------------
  643|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  644|      0|	}
  645|  24.7k|	ctx = card->ctx;
  646|  24.7k|	memcpy(path, in_path->value, in_path->len);
  647|  24.7k|	pathlen = in_path->len;
  648|  24.7k|	pathtype = in_path->type;
  649|       |
  650|  24.7k|	if (in_path->aid.len) {
  ------------------
  |  Branch (650:6): [True: 1.25k, False: 23.4k]
  ------------------
  651|  1.25k|		if (!pathlen) {
  ------------------
  |  Branch (651:7): [True: 1.12k, False: 132]
  ------------------
  652|  1.12k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  653|  1.12k|			pathlen = in_path->aid.len;
  654|  1.12k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.12k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  655|  1.12k|		} else {
  656|       |			/* First, select the application */
  657|    132|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    132|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  658|    132|			apdu.data = in_path->aid.value;
  659|    132|			apdu.datalen = in_path->aid.len;
  660|    132|			apdu.lc = in_path->aid.len;
  661|       |
  662|    132|			r = sc_transmit_apdu(card, &apdu);
  663|    132|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    132|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    132|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    132|	int _ret = (r); \
  |  |  |  |  168|    132|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  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|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  664|    130|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  665|    130|			if (r)
  ------------------
  |  Branch (665:8): [True: 89, False: 41]
  ------------------
  666|    130|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     89|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|       |
  668|     41|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|     82|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (668:8): [True: 41, False: 0]
  ------------------
  669|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (669:9): [True: 0, False: 0]
  ------------------
  670|     41|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|     41|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  671|     41|		}
  672|  1.25k|	}
  673|       |
  674|  24.6k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  24.6k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  675|       |
  676|  24.6k|	switch (pathtype) {
  677|  1.06k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  1.06k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (677:2): [True: 1.06k, False: 23.5k]
  ------------------
  678|  1.06k|		apdu.p1 = 0;
  679|  1.06k|		if (pathlen != 2)
  ------------------
  |  Branch (679:7): [True: 0, False: 1.06k]
  ------------------
  680|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  681|  1.06k|		break;
  682|  13.1k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  13.1k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (682:2): [True: 13.1k, False: 11.5k]
  ------------------
  683|  13.1k|		apdu.p1 = 4;
  684|  13.1k|		break;
  685|  10.4k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  10.4k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (685:2): [True: 10.4k, False: 14.2k]
  ------------------
  686|  10.4k|		apdu.p1 = 8;
  687|  10.4k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (687:7): [True: 10.4k, False: 11]
  |  Branch (687:23): [True: 7.93k, False: 2.49k]
  ------------------
  688|  7.93k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (688:8): [True: 2.06k, False: 5.86k]
  ------------------
  689|  2.06k|				select_mf = 1;
  690|  2.06k|				apdu.p1 = 0;
  691|  2.06k|				break;
  692|  2.06k|			}
  693|  5.86k|			path += 2;
  694|  5.86k|			pathlen -= 2;
  695|  5.86k|		}
  696|  8.36k|		break;
  697|  8.36k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|     41|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (697:2): [True: 41, False: 24.6k]
  ------------------
  698|     41|		apdu.p1 = 9;
  699|     41|		break;
  700|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (700:2): [True: 0, False: 24.6k]
  ------------------
  701|      0|		apdu.p1 = 3;
  702|      0|		pathlen = 0;
  703|      0|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  704|      0|		break;
  705|      0|	default:
  ------------------
  |  Branch (705:2): [True: 0, False: 24.6k]
  ------------------
  706|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  707|  24.6k|	}
  708|  24.6k|	apdu.lc = pathlen;
  709|  24.6k|	apdu.data = path;
  710|  24.6k|	apdu.datalen = pathlen;
  711|       |
  712|  24.6k|	if (file_out != NULL) {
  ------------------
  |  Branch (712:6): [True: 15.1k, False: 9.48k]
  ------------------
  713|  15.1k|		apdu.p2 = 0;		/* first record, return FCI */
  714|  15.1k|		apdu.resp = buf;
  715|  15.1k|		apdu.resplen = sizeof(buf);
  716|  15.1k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (716:13): [True: 752, False: 14.4k]
  ------------------
  717|  15.1k|	}
  718|  9.48k|	else {
  719|  9.48k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  720|  9.48k|		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|  18.9k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (720:14): [True: 0, False: 9.48k]
  ------------------
  721|  9.48k|	}
  722|       |
  723|  24.6k|	r = sc_transmit_apdu(card, &apdu);
  724|  24.6k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  24.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  24.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  24.6k|	int _ret = (r); \
  |  |  |  |  168|  24.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 271, False: 24.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|    271|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    271|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    271|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    271|		return _ret; \
  |  |  |  |  172|    271|	} \
  |  |  |  |  173|  24.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  725|  24.3k|	if (file_out == NULL) {
  ------------------
  |  Branch (725:6): [True: 9.47k, False: 14.8k]
  ------------------
  726|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  727|  9.47k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  728|  9.47k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (728:7): [True: 234, False: 9.24k]
  |  Branch (728:27): [True: 73, False: 161]
  ------------------
  729|     73|			apdu.p2 = 0x00;
  730|     73|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     73|#define SC_SUCCESS				0
  ------------------
  |  Branch (730:8): [True: 72, False: 1]
  ------------------
  731|     72|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  732|     73|		}
  733|  9.47k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (733:7): [True: 0, False: 9.47k]
  ------------------
  734|  9.47k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  735|  9.47k|		LOG_FUNC_RETURN(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|  6.97k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.97k, False: 2.50k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  736|  9.47k|	}
  737|       |
  738|  14.8k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  739|  14.8k|	if (r)
  ------------------
  |  Branch (739:6): [True: 9.98k, False: 4.91k]
  ------------------
  740|  14.8k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  9.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.98k|	int _ret = r; \
  |  |  |  |  155|  9.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  9.98k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.98k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.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|  9.98k|	return _ret; \
  |  |  |  |  163|  9.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  741|       |
  742|  4.91k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (742:6): [True: 4.91k, False: 0]
  |  Branch (742:18): [True: 1.22k, False: 3.69k]
  ------------------
  743|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  744|  1.22k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.22k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (744:7): [True: 0, False: 1.22k]
  |  Branch (744:20): [True: 956, False: 265]
  ------------------
  745|    956|			file = sc_file_new();
  746|    956|			if (file == NULL)
  ------------------
  |  Branch (746:8): [True: 0, False: 956]
  ------------------
  747|    956|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  748|    956|			file->path = *in_path;
  749|       |
  750|    956|			*file_out = file;
  751|    956|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    956|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    956|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    956|	int _ret = r; \
  |  |  |  |  155|    956|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 956, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    956|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 956]
  |  |  |  |  ------------------
  |  |  |  |  157|    956|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    956|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    956|	return _ret; \
  |  |  |  |  163|    956|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|    956|		}
  753|  1.22k|	}
  754|       |
  755|  3.95k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (755:6): [True: 270, False: 3.68k]
  ------------------
  756|  3.95k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    270|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    270|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    270|	int _ret = r; \
  |  |  |  |  155|    270|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 270, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    270|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    270|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 270, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    270|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    270|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    270|	return _ret; \
  |  |  |  |  163|    270|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  757|  3.68k|	switch (apdu.resp[0]) {
  758|  3.04k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  3.04k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (758:2): [True: 3.04k, False: 639]
  ------------------
  759|  3.18k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  3.18k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (759:2): [True: 140, False: 3.54k]
  ------------------
  760|  3.18k|		file = sc_file_new();
  761|  3.18k|		if (file == NULL)
  ------------------
  |  Branch (761:7): [True: 0, False: 3.18k]
  ------------------
  762|  3.18k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  763|  3.18k|		file->path = *in_path;
  764|  3.18k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (764:7): [True: 0, False: 3.18k]
  ------------------
  765|      0|			sc_file_free(file);
  766|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|      0|		}
  768|  3.18k|		buffer = apdu.resp;
  769|  3.18k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  770|  3.18k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  3.18k|#define SC_SUCCESS				0
  ------------------
  |  Branch (770:7): [True: 3.02k, False: 165]
  ------------------
  771|  3.02k|			card->ops->process_fci(card, file, buffer, buffer_len);
  772|  3.18k|		*file_out = file;
  773|  3.18k|		break;
  774|    137|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (774:2): [True: 137, False: 3.54k]
  ------------------
  775|    137|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    137|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    137|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    137|	int _ret = r; \
  |  |  |  |  155|    137|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 137, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    137|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    137|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    137|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    137|	return _ret; \
  |  |  |  |  163|    137|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|    362|	default:
  ------------------
  |  Branch (776:2): [True: 362, False: 3.32k]
  ------------------
  777|    362|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    362|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    362|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    362|	int _ret = r; \
  |  |  |  |  155|    362|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 362, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    362|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    362|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 362, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    362|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    362|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    362|	return _ret; \
  |  |  |  |  163|    362|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|  3.68k|	}
  779|       |
  780|  3.18k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.18k|#define SC_SUCCESS				0
  ------------------
  781|  3.68k|}
iso7816.c:iso7816_get_response:
  904|  24.4k|{
  905|  24.4k|	struct sc_apdu apdu = {0};
  906|  24.4k|	int r;
  907|  24.4k|	size_t rlen;
  908|       |
  909|       |	/* request at most max_recv_size bytes */
  910|  24.4k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (910:6): [True: 1.11k, False: 23.3k]
  ------------------
  911|  1.11k|		rlen = sc_get_max_recv_size(card);
  912|  23.3k|	else
  913|  23.3k|		rlen = *count;
  914|       |
  915|  24.4k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  24.4k|#define SC_APDU_CASE_2			0x22
  ------------------
  916|  24.4k|	apdu.le      = rlen;
  917|  24.4k|	apdu.resplen = rlen;
  918|  24.4k|	apdu.resp    = buf;
  919|       |	/* don't call GET RESPONSE recursively */
  920|  24.4k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  24.4k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  921|       |
  922|  24.4k|	r = sc_transmit_apdu(card, &apdu);
  923|  24.4k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  24.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  24.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  24.4k|	int _ret = (r); \
  |  |  |  |  168|  24.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 24.4k]
  |  |  |  |  ------------------
  |  |  |  |  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|  24.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  924|       |
  925|  24.4k|	*count = apdu.resplen;
  926|       |
  927|  24.4k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (927:6): [True: 10.6k, False: 13.8k]
  ------------------
  928|  10.6k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|  1.75k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.75k, False: 8.85k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|  10.6k|	}
  930|  13.8k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (930:6): [True: 7.25k, False: 6.58k]
  |  Branch (930:26): [True: 7.19k, False: 61]
  ------------------
  931|  7.19k|		r = 0;					/* no more data to read */
  932|  6.64k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (932:11): [True: 4.31k, False: 2.33k]
  ------------------
  933|  4.31k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (933:7): [True: 279, False: 4.03k]
  ------------------
  934|  2.33k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (934:11): [True: 65, False: 2.26k]
  |  Branch (934:31): [True: 35, False: 30]
  ------------------
  935|     35|		r = 0; /* Le not reached but file/record ended */
  936|  2.29k|	else
  937|  2.29k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  938|       |
  939|  13.8k|	return r;
  940|  24.4k|}
iso7816.c:iso7816_check_sw:
  111|   209k|{
  112|   209k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   209k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   209k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 44, False: 209k]
  ------------------
  117|     44|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  118|     44|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     44|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|     44|	}
  120|   209k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 46.3k, False: 162k]
  |  Branch (120:21): [True: 45.8k, False: 571]
  ------------------
  121|  45.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  45.8k|#define SC_SUCCESS				0
  ------------------
  122|   163k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 208, False: 163k]
  |  Branch (122:22): [True: 4, False: 204]
  ------------------
  123|      4|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  124|      4|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      4|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|      4|	}
  126|  6.68M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 6.67M, False: 9.97k]
  ------------------
  127|  6.67M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 153k, False: 6.52M]
  ------------------
  128|   153k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   153k|#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|   153k|			return iso7816_errors[i].errorno;
  130|   153k|		}
  131|  6.67M|	}
  132|       |
  133|  9.97k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  9.97k|#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|  9.97k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  9.97k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   163k|}
iso7816.c:iso7816_process_fci:
  431|  4.67k|{
  432|  4.67k|	struct sc_context *ctx = card->ctx;
  433|  4.67k|	const unsigned char *p, *end;
  434|  4.67k|	unsigned int cla = 0, tag = 0;
  435|  4.67k|	size_t length;
  436|       |
  437|  4.67k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  4.67k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  4.67k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  21.6k|			p < end;
  ------------------
  |  Branch (440:4): [True: 19.3k, False: 2.29k]
  ------------------
  441|  19.3k|			p += length, length = end - p) {
  442|       |
  443|  19.3k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  19.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 1.54k, False: 17.8k]
  ------------------
  444|  17.8k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 833, False: 16.9k]
  ------------------
  445|  2.37k|			break;
  446|  2.37k|		}
  447|  16.9k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 13.6k, False: 3.29k]
  ------------------
  448|  2.03k|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 2.03k, False: 14.9k]
  ------------------
  449|  2.03k|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 59, False: 1.97k]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|     59|					break;
  452|     59|				}
  453|       |				/* fall through */
  454|  4.10k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 2.12k, False: 14.8k]
  ------------------
  455|       |				/* determine the file size */
  456|  4.10k|				file->size = 0;
  457|  4.10k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 4.10k, False: 0]
  |  Branch (457:14): [True: 4.02k, False: 83]
  ------------------
  458|  4.02k|					size_t size = 0, i;
  459|  11.2k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 7.20k, False: 4.02k]
  ------------------
  460|  7.20k|						size <<= 8;
  461|  7.20k|						size |= p[i];
  462|  7.20k|					}
  463|  4.02k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  4.02k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 383, False: 3.63k]
  ------------------
  464|    383|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    383|#define MAX_FILE_SIZE 65535
  ------------------
  465|    383|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   71|    383|#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|  3.63k|					} else {
  467|  3.63k|						file->size = size;
  468|  3.63k|					}
  469|  4.02k|				}
  470|       |
  471|  4.10k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  472|  4.10k|				break;
  473|       |
  474|  2.55k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 2.55k, False: 14.4k]
  ------------------
  475|  2.55k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 2.49k, False: 52]
  ------------------
  476|  2.49k|					unsigned char byte = p[0];
  477|  2.49k|					const char *type;
  478|       |
  479|  2.49k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 77, False: 2.42k]
  ------------------
  480|  2.49k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  4.99k|#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: 77, False: 2.42k]
  |  |  ------------------
  ------------------
  481|  2.49k|					file->ef_structure = byte & 0x07;
  482|  2.49k|					switch ((byte >> 3) & 7) {
  483|  2.10k|						case 0:
  ------------------
  |  Branch (483:7): [True: 2.10k, False: 395]
  ------------------
  484|  2.10k|							type = "working EF";
  485|  2.10k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  2.10k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|  2.10k|							break;
  487|     91|						case 1:
  ------------------
  |  Branch (487:7): [True: 91, False: 2.40k]
  ------------------
  488|     91|							type = "internal EF";
  489|     91|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     91|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|     91|							break;
  491|     67|						case 7:
  ------------------
  |  Branch (491:7): [True: 67, False: 2.43k]
  ------------------
  492|     67|							type = "DF";
  493|     67|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     67|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|     67|							break;
  495|    237|						default:
  ------------------
  |  Branch (495:7): [True: 237, False: 2.26k]
  ------------------
  496|    237|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    237|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    237|							type = "unknown";
  498|    237|							break;
  499|  2.49k|					}
  500|  2.49k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  501|  2.49k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  502|  2.49k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  2.49k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.49k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 2.43k, False: 67]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  2.43k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 274, False: 2.15k]
  |  Branch (507:25): [True: 211, False: 63]
  ------------------
  508|    211|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 196, False: 15]
  ------------------
  509|    211|								? bebytes2ushort(p+2)
  510|    211|								: p[2];
  511|    211|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  512|    211|						}
  513|       |
  514|       |						/* number of records */
  515|  2.43k|						if (length > 4) {
  ------------------
  |  Branch (515:11): [True: 225, False: 2.20k]
  ------------------
  516|    225|							file->record_count = (length > 5)
  ------------------
  |  Branch (516:29): [True: 208, False: 17]
  ------------------
  517|    225|								? bebytes2ushort(p+4)
  518|    225|								: p[4];
  519|    225|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   71|    225|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  520|    225|						}
  521|  2.43k|					}
  522|       |
  523|  2.49k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  2.49k|#define SC_SUCCESS				0
  ------------------
  |  Branch (523:10): [True: 0, False: 2.49k]
  ------------------
  524|      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__
  |  |  ------------------
  ------------------
  525|  2.49k|				}
  526|  2.55k|				break;
  527|       |
  528|  2.55k|			case 0x83:
  ------------------
  |  Branch (528:4): [True: 2.06k, False: 14.9k]
  ------------------
  529|  2.06k|				if (length == 2) {
  ------------------
  |  Branch (529:9): [True: 1.96k, False: 97]
  ------------------
  530|  1.96k|					file->id = (p[0] << 8) | p[1];
  531|  1.96k|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|  1.96k|#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|  1.96k|				}
  533|  2.06k|				break;
  534|       |
  535|    288|			case 0x84:
  ------------------
  |  Branch (535:4): [True: 288, False: 16.6k]
  ------------------
  536|    288|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (536:9): [True: 149, False: 139]
  |  Branch (536:23): [True: 129, False: 20]
  ------------------
  537|    129|					memcpy(file->name, p, length);
  538|    129|					file->namelen = length;
  539|       |
  540|    129|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    129|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    129|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  541|    129|					if (!file->type)
  ------------------
  |  Branch (541:10): [True: 46, False: 83]
  ------------------
  542|     46|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     46|#define SC_FILE_TYPE_DF			0x04
  ------------------
  543|    129|				}
  544|    288|				break;
  545|       |
  546|    517|			case 0x85:
  ------------------
  |  Branch (546:4): [True: 517, False: 16.4k]
  ------------------
  547|    616|			case 0xA5:
  ------------------
  |  Branch (547:4): [True: 99, False: 16.8k]
  ------------------
  548|    616|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|    616|#define SC_SUCCESS				0
  ------------------
  |  Branch (548:9): [True: 0, False: 616]
  ------------------
  549|      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__
  |  |  ------------------
  ------------------
  550|      0|				}
  551|    616|				break;
  552|       |
  553|  1.07k|			case 0x86:
  ------------------
  |  Branch (553:4): [True: 1.07k, False: 15.8k]
  ------------------
  554|  1.07k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (554:9): [True: 0, False: 1.07k]
  ------------------
  555|      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__
  |  |  ------------------
  ------------------
  556|      0|				}
  557|  1.07k|				break;
  558|       |
  559|    130|			case 0x88:
  ------------------
  |  Branch (559:4): [True: 130, False: 16.8k]
  ------------------
  560|    130|				if (length == 1) {
  ------------------
  |  Branch (560:9): [True: 18, False: 112]
  ------------------
  561|     18|					file->sid = *p;
  562|     18|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  563|     18|				}
  564|    130|				break;
  565|       |
  566|  2.03k|			case 0x8A:
  ------------------
  |  Branch (566:4): [True: 2.03k, False: 14.9k]
  ------------------
  567|  2.03k|				if (length == 1) {
  ------------------
  |  Branch (567:9): [True: 1.92k, False: 111]
  ------------------
  568|  1.92k|					switch (p[0]) {
  569|    210|						case 0:
  ------------------
  |  Branch (569:7): [True: 210, False: 1.71k]
  ------------------
  570|    210|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|    210|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  571|    210|							break;
  572|     11|						case 1:
  ------------------
  |  Branch (572:7): [True: 11, False: 1.91k]
  ------------------
  573|     11|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     11|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  574|     11|							break;
  575|      5|						case 3:
  ------------------
  |  Branch (575:7): [True: 5, False: 1.91k]
  ------------------
  576|      5|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|      5|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  577|      5|							break;
  578|      9|						case 4:
  ------------------
  |  Branch (578:7): [True: 9, False: 1.91k]
  ------------------
  579|     16|						case 6:
  ------------------
  |  Branch (579:7): [True: 7, False: 1.91k]
  ------------------
  580|     16|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     16|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  581|     16|							break;
  582|    996|						case 5:
  ------------------
  |  Branch (582:7): [True: 996, False: 926]
  ------------------
  583|  1.44k|						case 7:
  ------------------
  |  Branch (583:7): [True: 445, False: 1.47k]
  ------------------
  584|  1.44k|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|  1.44k|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  585|  1.44k|							break;
  586|      8|						case 12:
  ------------------
  |  Branch (586:7): [True: 8, False: 1.91k]
  ------------------
  587|     18|						case 13:
  ------------------
  |  Branch (587:7): [True: 10, False: 1.91k]
  ------------------
  588|     24|						case 14:
  ------------------
  |  Branch (588:7): [True: 6, False: 1.91k]
  ------------------
  589|     38|						case 15:
  ------------------
  |  Branch (589:7): [True: 14, False: 1.90k]
  ------------------
  590|     38|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|     38|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  591|     38|							break;
  592|     17|						case 2:
  ------------------
  |  Branch (592:7): [True: 17, False: 1.90k]
  ------------------
  593|     17|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     17|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  594|     17|							break;
  595|      9|						case 8:
  ------------------
  |  Branch (595:7): [True: 9, False: 1.91k]
  ------------------
  596|      9|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|      9|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  597|      9|							break;
  598|     12|						case 9:
  ------------------
  |  Branch (598:7): [True: 12, False: 1.91k]
  ------------------
  599|     12|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     12|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  600|     12|							break;
  601|     15|						case 10:
  ------------------
  |  Branch (601:7): [True: 15, False: 1.90k]
  ------------------
  602|     15|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     15|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  603|     15|							break;
  604|     13|						case 11:
  ------------------
  |  Branch (604:7): [True: 13, False: 1.90k]
  ------------------
  605|     13|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     13|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  606|     13|							break;
  607|    135|						default:
  ------------------
  |  Branch (607:7): [True: 135, False: 1.78k]
  ------------------
  608|    135|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|    135|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  609|  1.92k|					}
  610|  1.92k|				}
  611|  2.03k|				break;
  612|       |
  613|  2.03k|			case 0x62:
  ------------------
  |  Branch (613:4): [True: 584, False: 16.3k]
  ------------------
  614|    637|			case 0x64:
  ------------------
  |  Branch (614:4): [True: 53, False: 16.9k]
  ------------------
  615|    754|			case 0x6F:
  ------------------
  |  Branch (615:4): [True: 117, False: 16.8k]
  ------------------
  616|       |				/* allow nested FCP/FMD/FCI templates */
  617|    754|				iso7816_process_fci(card, file, p, length);
  618|  16.9k|		}
  619|  16.9k|	}
  620|       |
  621|  4.67k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  4.67k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  622|       |
  623|  4.67k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.67k|#define SC_SUCCESS				0
  ------------------
  624|  4.67k|}
iso7816.c:iso7816_pin_cmd:
 1282|  1.96k|{
 1283|  1.96k|	struct sc_apdu local_apdu, *apdu;
 1284|  1.96k|	int r;
 1285|  1.96k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1286|       |
 1287|  1.96k|	data->pin1.tries_left = -1;
 1288|       |
 1289|       |	/* Many cards do support PIN status queries, but some cards don't and
 1290|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1291|       |	 * allow cards with this flag.  In future this may be reduced to a
 1292|       |	 * blocklist, subject to testing more cards. */
 1293|  1.96k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  3.92k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1293:6): [True: 1.69k, False: 268]
  ------------------
 1294|  1.69k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|  1.69k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1294:6): [True: 167, False: 1.52k]
  ------------------
 1295|    167|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    167|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1296|    167|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    167|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1297|    167|	}
 1298|       |
 1299|       |	/* See if we've been called from another card driver, which is
 1300|       |	 * passing an APDU to us (this allows to write card drivers
 1301|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1302|       |	 * special circumstances.
 1303|       |	 */
 1304|  1.79k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1304:6): [True: 1.79k, False: 4]
  ------------------
 1305|  1.79k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1306|  1.79k|		if (r < 0)
  ------------------
  |  Branch (1306:7): [True: 41, False: 1.75k]
  ------------------
 1307|     41|			return r;
 1308|  1.75k|		data->apdu = &local_apdu;
 1309|  1.75k|	}
 1310|  1.75k|	apdu = data->apdu;
 1311|       |
 1312|  1.75k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|  1.75k|#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 (1312:6): [True: 1.75k, False: 0]
  |  Branch (1312:48): [True: 0, False: 0]
  ------------------
 1313|       |		/* Transmit the APDU to the card */
 1314|  1.75k|		r = sc_transmit_apdu(card, apdu);
 1315|       |
 1316|       |		/* Clear the buffer - it may contain pins */
 1317|  1.75k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1318|  1.75k|	}
 1319|      0|	else {
 1320|       |		/* Call the reader driver to collect
 1321|       |		 * the PIN and pass on the APDU to the card */
 1322|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1322:7): [True: 0, False: 0]
  ------------------
 1323|      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__
  |  |  ------------------
  ------------------
 1324|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1325|      0|		}
 1326|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1326:7): [True: 0, False: 0]
  |  Branch (1326:23): [True: 0, False: 0]
  |  Branch (1326:44): [True: 0, False: 0]
  ------------------
 1327|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1328|       |			/* sw1/sw2 filled in by reader driver */
 1329|      0|		}
 1330|      0|		else {
 1331|      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__
  |  |  ------------------
  ------------------
 1332|      0|					"PIN entry through reader key pad");
 1333|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1334|      0|		}
 1335|      0|	}
 1336|       |
 1337|       |	/* Don't pass references to local variables up to the caller. */
 1338|  1.75k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1338:6): [True: 1.75k, False: 4]
  ------------------
 1339|  1.75k|		data->apdu = NULL;
 1340|       |
 1341|  1.75k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.75k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.75k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.75k|	int _ret = (r); \
  |  |  |  |  168|  1.75k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 1.74k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.75k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.74k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1342|  1.74k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1343|       |
 1344|  1.74k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.74k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1344:6): [True: 167, False: 1.57k]
  ------------------
 1345|    167|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|    167|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1346|  1.57k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  1.57k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1346:13): [True: 14, False: 1.56k]
  ------------------
 1347|     14|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1348|     14|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     14|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1349|     14|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     14|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1349:7): [True: 13, False: 1]
  ------------------
 1350|     13|			r = SC_SUCCESS;
  ------------------
  |  |   28|     13|#define SC_SUCCESS				0
  ------------------
 1351|  1.56k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  1.56k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1351:13): [True: 1, False: 1.56k]
  ------------------
 1352|      1|		data->pin1.tries_left = 0;
 1353|      1|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      1|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1354|      1|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      1|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1354:7): [True: 1, False: 0]
  ------------------
 1355|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1356|      1|	}
 1357|       |
 1358|  1.74k|	return r;
 1359|  1.75k|}
iso7816.c:iso7816_get_data:
 1363|     93|{
 1364|     93|	int                             r, cse;
 1365|     93|	struct sc_apdu                  apdu;
 1366|       |
 1367|     93|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     93|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     93|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     93|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 93]
  |  |  ------------------
  ------------------
 1368|       |
 1369|     93|	if (buf && len)
  ------------------
  |  Branch (1369:6): [True: 93, False: 0]
  |  Branch (1369:13): [True: 93, False: 0]
  ------------------
 1370|     93|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|     93|#define SC_APDU_CASE_2			0x22
  ------------------
 1371|      0|	else
 1372|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1373|       |
 1374|     93|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1375|     93|	apdu.le = len;
 1376|     93|	apdu.resp = buf;
 1377|     93|	apdu.resplen = len;
 1378|     93|	r = sc_transmit_apdu(card, &apdu);
 1379|     93|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     93|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     93|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     93|	int _ret = (r); \
  |  |  |  |  168|     93|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  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|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|     91|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1382|     91|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|     91|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     91|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     91|	int _ret = (r); \
  |  |  |  |  168|     91|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  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|     91|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|       |
 1384|     64|	if (apdu.resplen > len)
  ------------------
  |  Branch (1384:6): [True: 0, False: 64]
  ------------------
 1385|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1386|     64|	else
 1387|     64|		r = (int)apdu.resplen;
 1388|       |
 1389|     64|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 56]
  |  |  |  |  ------------------
  |  |  |  |  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|     56|	} else { \
  |  |  |  |  159|     56|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     56|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     56|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1390|     64|}
iso7816.c:iso7816_read_binary:
  140|  5.26k|{
  141|  5.26k|	struct sc_context *ctx = card->ctx;
  142|  5.26k|	struct sc_apdu apdu;
  143|  5.26k|	int r;
  144|       |
  145|  5.26k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 2, False: 5.26k]
  ------------------
  146|      2|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  147|      2|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      2|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|      2|	}
  149|       |
  150|  5.26k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  5.26k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  5.26k|	apdu.le = count;
  152|  5.26k|	apdu.resplen = count;
  153|  5.26k|	apdu.resp = buf;
  154|       |
  155|  5.26k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  5.26k|	r = sc_transmit_apdu(card, &apdu);
  157|  5.26k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  5.26k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.26k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.26k|	int _ret = (r); \
  |  |  |  |  168|  5.26k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 137, False: 5.12k]
  |  |  |  |  ------------------
  |  |  |  |  169|    137|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    137|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    137|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    137|		return _ret; \
  |  |  |  |  172|    137|	} \
  |  |  |  |  173|  5.26k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.12k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  5.12k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  5.12k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  10.2k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  5.11k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 11, False: 5.11k]
  |  Branch (160:40): [True: 69, False: 5.04k]
  ------------------
  161|  5.12k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 16, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  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|     64|	} else { \
  |  |  |  |  159|     64|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     64|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     64|	} \
  |  |  |  |  162|     80|	return _ret; \
  |  |  |  |  163|     80|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  5.04k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  5.04k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.04k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.04k|	int _ret = (r); \
  |  |  |  |  168|  5.04k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 759, False: 4.28k]
  |  |  |  |  ------------------
  |  |  |  |  169|    759|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    759|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    759|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    759|		return _ret; \
  |  |  |  |  172|    759|	} \
  |  |  |  |  173|  5.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.28k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  4.28k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  4.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.28k|	int _ret = r; \
  |  |  |  |  155|  4.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 241, False: 4.04k]
  |  |  |  |  ------------------
  |  |  |  |  156|    241|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 241]
  |  |  |  |  ------------------
  |  |  |  |  157|    241|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.04k|	} else { \
  |  |  |  |  159|  4.04k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  4.04k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  4.04k|	} \
  |  |  |  |  162|  4.28k|	return _ret; \
  |  |  |  |  163|  4.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  4.28k|}

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

mscfs_new:
   45|    395|mscfs_t *mscfs_new(void) {
   46|    395|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   47|    395|	if (!fs)
  ------------------
  |  Branch (47:6): [True: 0, False: 395]
  ------------------
   48|      0|		return NULL;
   49|    395|	memset(fs, 0, sizeof(mscfs_t));
   50|    395|	memcpy(fs->currentPath, "\x3F\x00", 2);
   51|    395|	return fs;
   52|    395|}
mscfs_free:
   54|    395|void mscfs_free(mscfs_t *fs) {
   55|    395|	mscfs_clear_cache(fs);
   56|    395|	free(fs);
   57|    395|}
mscfs_clear_cache:
   59|  1.55k|void mscfs_clear_cache(mscfs_t* fs) {
   60|  1.55k|	if(!fs->cache.array) {
  ------------------
  |  Branch (60:5): [True: 1.38k, False: 166]
  ------------------
   61|  1.38k|		return;
   62|  1.38k|	}
   63|    166|	free(fs->cache.array);
   64|       |	fs->cache.array = NULL;
   65|    166|	fs->cache.totalSize = 0;
   66|    166|	fs->cache.size = 0;
   67|    166|}
mscfs_push_file:
   83|  2.29k|{
   84|  2.29k|	mscfs_cache_t *cache = &fs->cache;
   85|  2.29k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   81|  2.29k|#define MAX_FILES 10000
  ------------------
  |  Branch (85:6): [True: 0, False: 2.29k]
  ------------------
   86|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   87|  2.29k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (87:5): [True: 166, False: 2.12k]
  |  Branch (87:22): [True: 11, False: 2.11k]
  ------------------
   88|    177|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   35|    177|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   89|    177|		mscfs_file_t *oldArray;
   90|    177|		cache->totalSize = length;
   91|    177|		oldArray = cache->array;
   92|    177|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   93|    177|		if(!cache->array)
  ------------------
  |  Branch (93:6): [True: 0, False: 177]
  ------------------
   94|      0|			return MSCFS_NO_MEMORY;
  ------------------
  |  |   32|      0|#define MSCFS_NO_MEMORY  	SC_ERROR_OUT_OF_MEMORY
  |  |  ------------------
  |  |  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  |  |  ------------------
  ------------------
   95|    177|		if(oldArray) {
  ------------------
  |  Branch (95:6): [True: 11, False: 166]
  ------------------
   96|     11|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   97|     11|			free(oldArray);
   98|     11|		}
   99|    177|	}
  100|  2.29k|	cache->array[cache->size] = *file;
  101|  2.29k|	cache->size++;
  102|  2.29k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.29k|#define SC_SUCCESS				0
  ------------------
  103|  2.29k|}
mscfs_update_cache:
  105|  1.15k|int mscfs_update_cache(mscfs_t* fs) {
  106|  1.15k|	mscfs_file_t file;
  107|  1.15k|	int r;
  108|  1.15k|	mscfs_clear_cache(fs);
  109|  1.15k|	r = fs->listFile(&file, 1, fs->udata);
  110|  1.15k|	if(r == 0)
  ------------------
  |  Branch (110:5): [True: 120, False: 1.03k]
  ------------------
  111|    120|		return 0;
  112|  1.03k|	else if(r < 0)
  ------------------
  |  Branch (112:10): [True: 855, False: 182]
  ------------------
  113|    855|		return r;
  114|  2.31k|	while(1) {
  ------------------
  |  Branch (114:8): [True: 2.31k, Folded]
  ------------------
  115|  2.31k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (115:6): [True: 2.29k, False: 21]
  ------------------
  116|       |			/* Check if its a directory in the root */
  117|  2.29k|			u8* oid = file.objectId.id;
  118|  2.29k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (118:7): [True: 338, False: 1.95k]
  |  Branch (118:22): [True: 101, False: 237]
  ------------------
  119|    101|				oid[2] = oid[0];
  120|    101|				oid[3] = oid[1];
  121|    101|				oid[0] = 0x3F;
  122|    101|				oid[1] = 0x00;
  123|    101|				file.ef = 0;
  124|  2.19k|			} else  {
  125|  2.19k|				file.ef = 1; /* File is a working elementary file */
  126|  2.19k|			}
  127|       |
  128|  2.29k|			r = mscfs_push_file(fs, &file);
  129|  2.29k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  2.29k|#define SC_SUCCESS				0
  ------------------
  |  Branch (129:8): [True: 0, False: 2.29k]
  ------------------
  130|      0|				return r;
  131|  2.29k|		}
  132|  2.31k|		r = fs->listFile(&file, 0, fs->udata);
  133|  2.31k|		if(r == 0)
  ------------------
  |  Branch (133:6): [True: 20, False: 2.29k]
  ------------------
  134|     20|			break;
  135|  2.29k|		else if(r < 0)
  ------------------
  |  Branch (135:11): [True: 162, False: 2.13k]
  ------------------
  136|    162|			return r;
  137|  2.31k|	}
  138|     20|	return fs->cache.size;
  139|    182|}
mscfs_check_cache:
  142|  2.20k|{
  143|  2.20k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.20k|#define SC_SUCCESS				0
  ------------------
  144|  2.20k|	if(!fs->cache.array) {
  ------------------
  |  Branch (144:5): [True: 1.15k, False: 1.04k]
  ------------------
  145|  1.15k|		r = mscfs_update_cache(fs);
  146|  1.15k|	}
  147|  2.20k|	return r;
  148|  2.20k|}
mscfs_lookup_path:
  151|    805|{
  152|    805|	u8* oid = objectId->id;
  153|    805|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (153:6): [True: 327, False: 478]
  ------------------
  154|    327|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|    327|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    327|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  155|    478|	if(isDirectory) {
  ------------------
  |  Branch (155:5): [True: 0, False: 478]
  ------------------
  156|       |		/* Directory must be right next to root */
  157|      0|		if ((pathlen == 4 && 0 == memcmp(path, "\x3F\x00", 2)) ||
  ------------------
  |  Branch (157:8): [True: 0, False: 0]
  |  Branch (157:24): [True: 0, False: 0]
  ------------------
  158|      0|		    (pathlen == 2 && 0 == memcmp(fs->currentPath, "\x3F\x00", 2))) {
  ------------------
  |  Branch (158:8): [True: 0, False: 0]
  |  Branch (158:24): [True: 0, False: 0]
  ------------------
  159|      0|			oid[0] = path[pathlen - 2];
  160|      0|			oid[1] = path[pathlen - 1];
  161|      0|			oid[2] = oid[3] = 0;
  162|      0|		} else {
  163|      0|			return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  164|      0|		}
  165|      0|	}
  166|    478|	oid[0] = fs->currentPath[0];
  167|    478|	oid[1] = fs->currentPath[1];
  168|       |	/* Chop off the root in the path */
  169|    478|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (169:5): [True: 478, False: 0]
  |  Branch (169:20): [True: 478, False: 0]
  ------------------
  170|    478|		path += 2;
  171|    478|		pathlen -= 2;
  172|    478|		oid[0] = 0x3F;
  173|    478|		oid[1] = 0x00;
  174|    478|	}
  175|       |	/* Limit to a single directory */
  176|    478|	if(pathlen > 4)
  ------------------
  |  Branch (176:5): [True: 0, False: 478]
  ------------------
  177|      0|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  178|       |	/* Reset to root */
  179|    478|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (179:5): [True: 279, False: 199]
  |  Branch (179:21): [True: 0, False: 279]
  ------------------
  180|      0|		oid[0] = oid[2] = path[0];
  181|      0|		oid[1] = oid[3] = path[1];
  182|    478|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (182:12): [True: 279, False: 199]
  ------------------
  183|    279|		oid[2] = path[0];
  184|    279|		oid[3] = path[1];
  185|    279|	} else if(pathlen == 4) {
  ------------------
  |  Branch (185:12): [True: 199, False: 0]
  ------------------
  186|    199|		oid[0] = path[0];
  187|    199|		oid[1] = path[1];
  188|    199|		oid[2] = path[2];
  189|    199|		oid[3] = path[3];
  190|    199|	}
  191|       |
  192|    478|	return 0;
  193|    478|}
mscfs_check_selection:
  207|    132|{
  208|    132|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (208:5): [True: 0, False: 132]
  |  Branch (208:32): [True: 0, False: 0]
  ------------------
  209|      0|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  210|    132|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (210:5): [True: 0, False: 132]
  |  Branch (210:26): [True: 0, False: 0]
  |  Branch (210:53): [True: 0, False: 0]
  ------------------
  211|      0|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|      0|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  212|    132|	return 0;
  213|    132|}
mscfs_loadFileInfo:
  216|    805|{
  217|    805|	msc_id fullPath = {{0, 0, 0, 0}};
  218|    805|	int x, rc;
  219|    805|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 805]
  |  Branch (219:20): [True: 0, False: 805]
  |  Branch (219:36): [True: 0, False: 805]
  ------------------
  220|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  221|    805|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  222|    805|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|    805|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 327, False: 478]
  ------------------
  223|    327|		return rc;
  224|    327|	}
  225|       |
  226|       |	/* Obtain file information while checking if it exists */
  227|    478|	rc = mscfs_check_cache(fs);
  228|    478|	if (rc < 0)
  ------------------
  |  Branch (228:6): [True: 95, False: 383]
  ------------------
  229|     95|		return rc;
  230|    383|	if(idx) *idx = -1;
  ------------------
  |  Branch (230:5): [True: 383, False: 0]
  ------------------
  231|  5.01k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (231:13): [True: 4.73k, False: 275]
  ------------------
  232|  4.73k|		*file_data = &fs->cache.array[x];
  233|  4.73k|		if (*file_data) {
  ------------------
  |  Branch (233:7): [True: 4.73k, False: 0]
  ------------------
  234|  4.73k|			msc_id objectId;
  235|  4.73k|			objectId = (*file_data)->objectId;
  236|  4.73k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (236:7): [True: 108, False: 4.63k]
  ------------------
  237|    108|				if (idx)
  ------------------
  |  Branch (237:9): [True: 108, False: 0]
  ------------------
  238|    108|					*idx = x;
  239|    108|				break;
  240|    108|			}
  241|  4.63k|			*file_data = NULL;
  242|  4.63k|		}
  243|  4.73k|	}
  244|    383|	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 (244:5): [True: 275, False: 108]
  |  Branch (244:28): [True: 0, False: 275]
  |  Branch (244:79): [True: 147, False: 128]
  |  Branch (244:131): [True: 0, False: 128]
  ------------------
  245|    147|		static mscfs_file_t ROOT_FILE;
  246|    147|		ROOT_FILE.ef = 0;
  247|    147|		ROOT_FILE.size = 0;
  248|       |		/* Faked Root ID */
  249|    147|		ROOT_FILE.objectId = rootId;
  250|       |
  251|    147|		ROOT_FILE.read = 0;
  252|    147|		ROOT_FILE.write = 0x02; /* User Pin access */
  253|    147|		ROOT_FILE.delete = 0x02;
  254|       |
  255|    147|		*file_data = &ROOT_FILE;
  256|    147|		if(idx) *idx = -2;
  ------------------
  |  Branch (256:6): [True: 147, False: 0]
  ------------------
  257|    236|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (257:12): [True: 128, False: 108]
  ------------------
  258|    128|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   34|    128|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    128|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  259|    128|	}
  260|       |
  261|    255|	return 0;
  262|    383|}
muscle-filesystem.c:mscfs_is_ignored:
   70|  2.31k|{
   71|  2.31k|	int ignored = 0;
   72|  2.31k|	const u8** ptr = ignoredFiles;
   73|  6.93k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (73:8): [True: 6.93k, False: 0]
  |  Branch (73:15): [True: 4.63k, False: 2.30k]
  |  Branch (73:23): [True: 4.61k, False: 16]
  ------------------
   74|  4.61k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (74:6): [True: 21, False: 4.59k]
  ------------------
   75|     21|			ignored = 1;
   76|  4.61k|		ptr++;
   77|  4.61k|	}
   78|  2.31k|	return ignored;
   79|  2.31k|}

msc_list_objects:
   37|  3.47k|int msc_list_objects(sc_card_t* card, u8 next, mscfs_file_t* file) {
   38|  3.47k|	sc_apdu_t apdu;
   39|  3.47k|	u8 fileData[14];
   40|  3.47k|	int r;
   41|       |
   42|  3.47k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x58, next, 0x00);
  ------------------
  |  |  301|  3.47k|#define SC_APDU_CASE_2			0x22
  ------------------
   43|  3.47k|	apdu.le = 14;
   44|  3.47k|	apdu.resplen = 14;
   45|  3.47k|	apdu.resp = fileData;
   46|  3.47k|	r = sc_transmit_apdu(card, &apdu);
   47|  3.47k|	if (r)
  ------------------
  |  Branch (47:6): [True: 90, False: 3.38k]
  ------------------
   48|     90|		return r;
   49|       |
   50|  3.38k|	if(apdu.sw1 == 0x9C && apdu.sw2 == 0x12) {
  ------------------
  |  Branch (50:5): [True: 83, False: 3.30k]
  |  Branch (50:25): [True: 1, False: 82]
  ------------------
   51|      1|		return 0;
   52|      1|	}
   53|  3.38k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   54|  3.38k|	if (r)
  ------------------
  |  Branch (54:6): [True: 906, False: 2.47k]
  ------------------
   55|    906|		return r;
   56|  2.47k|	if(apdu.resplen == 0) /* No more left */
  ------------------
  |  Branch (56:5): [True: 139, False: 2.33k]
  ------------------
   57|    139|		return 0;
   58|  2.33k|	if (apdu.resplen != 14) {
  ------------------
  |  Branch (58:6): [True: 21, False: 2.31k]
  ------------------
   59|     21|		sc_log(card->ctx, "expected 14 bytes, got %zu.\n", apdu.resplen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   60|     21|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     21|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   61|     21|	}
   62|  2.31k|	memcpy(file->objectId.id, fileData, 4);
   63|  2.31k|	file->size = bebytes2ulong(fileData + 4);
   64|  2.31k|	file->read = bebytes2ushort(fileData + 8);
   65|  2.31k|	file->write = bebytes2ushort(fileData + 10);
   66|  2.31k|	file->delete = bebytes2ushort(fileData + 12);
   67|       |
   68|  2.31k|	return 1;
   69|  2.33k|}
msc_partial_read_object:
   72|    132|{
   73|    132|	u8 buffer[9];
   74|    132|	sc_apdu_t apdu;
   75|    132|	int r;
   76|       |
   77|    132|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x56, 0x00, 0x00);
  ------------------
  |  |  294|    132|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
   78|       |
   79|    132|	sc_log(card->ctx, "READ: Offset: %x\tLength: %zu\n", offset, dataLength);
  ------------------
  |  |   71|    132|#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|    132|	memcpy(buffer, objectId.id, 4);
   81|    132|	ulong2bebytes(buffer + 4, offset);
   82|    132|	buffer[8] = (u8)dataLength;
   83|    132|	apdu.data = buffer;
   84|    132|	apdu.datalen = 9;
   85|    132|	apdu.lc = 9;
   86|    132|	apdu.le = dataLength;
   87|    132|	apdu.resplen = dataLength;
   88|    132|	apdu.resp = data;
   89|    132|	r = sc_transmit_apdu(card, &apdu);
   90|    132|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    132|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    132|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    132|	int _ret = (r); \
  |  |  |  |  168|    132|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 131]
  |  |  |  |  ------------------
  |  |  |  |  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|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 131]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|    131|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && dataLength <= apdu.resplen)
  ------------------
  |  Branch (91:6): [True: 97, False: 34]
  |  Branch (91:26): [True: 96, False: 1]
  |  Branch (91:46): [True: 90, False: 6]
  ------------------
   92|     90|		return (int)dataLength;
   93|     41|	if (apdu.sw1 == 0x9C) {
  ------------------
  |  Branch (93:6): [True: 6, False: 35]
  ------------------
   94|      6|		if (apdu.sw2 == 0x07) {
  ------------------
  |  Branch (94:7): [True: 1, False: 5]
  ------------------
   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|      5|		} else if (apdu.sw2 == 0x06) {
  ------------------
  |  Branch (96:14): [True: 1, False: 4]
  ------------------
   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|      4|		} else if (apdu.sw2 == 0x0F) {
  ------------------
  |  Branch (98:14): [True: 1, False: 3]
  ------------------
   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|      6|	}
  103|     38|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  104|     38|		"got strange SWs: 0x%02X 0x%02X\n", apdu.sw1, apdu.sw2);
  105|     38|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  106|     38|}
msc_read_object:
  109|    132|{
  110|    132|	int r = 0;
  111|    132|	unsigned int i;
  112|    132|	size_t max_read_unit = MSC_MAX_READ;
  ------------------
  |  |   35|    132|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 132, False: 0]
  |  |  ------------------
  ------------------
  113|       |
  114|    222|	for (i = 0; i < dataLength; i += r) {
  ------------------
  |  Branch (114:14): [True: 132, False: 90]
  ------------------
  115|    132|		r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit));
  ------------------
  |  |   70|    132|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 17, False: 115]
  |  |  ------------------
  ------------------
  116|    132|		LOG_TEST_RET(card->ctx, r, "Error in partial object read");
  ------------------
  |  |  174|    132|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    132|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    132|	int _ret = (r); \
  |  |  |  |  168|    132|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  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|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|     90|		if (r == 0)
  ------------------
  |  Branch (117:7): [True: 0, False: 90]
  ------------------
  118|      0|			break;
  119|     90|	}
  120|     90|	return (int)dataLength;
  121|    132|}
msc_select_applet:
  256|  5.05k|{
  257|  5.05k|	sc_apdu_t apdu;
  258|  5.05k|	int r;
  259|       |
  260|  5.05k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  5.05k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  261|  5.05k|	apdu.lc = appletIdLength;
  262|  5.05k|	apdu.data = appletId;
  263|  5.05k|	apdu.datalen = appletIdLength;
  264|  5.05k|	apdu.resplen = 0;
  265|  5.05k|	apdu.le = 0;
  266|       |
  267|  5.05k|	r = sc_transmit_apdu(card, &apdu);
  268|  5.05k|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 14, False: 5.04k]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  5.04k|	if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (269:5): [True: 404, False: 4.63k]
  |  Branch (269:25): [True: 395, False: 9]
  ------------------
  270|    395|		return 1;
  271|       |
  272|  4.64k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  153|  4.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  4.64k|	int _ret = r; \
  |  |  155|  4.64k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4.64k, False: 0]
  |  |  ------------------
  |  |  156|  4.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|  4.64k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.64k, False: 0]
  |  |  ------------------
  |  |  157|  4.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.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|  4.64k|	return _ret; \
  |  |  163|  4.64k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  273|  4.64k|}

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

sc_pkcs15emu_cac_init_ex:
  371|  4.71k|{
  372|  4.71k|	sc_card_t   *card = p15card->card;
  373|  4.71k|	sc_context_t    *ctx = card->ctx;
  374|       |
  375|  4.71k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.71k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.71k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.71k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.71k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.71k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|       |
  377|  4.71k|	if (cac_detect_card(p15card))
  ------------------
  |  Branch (377:6): [True: 4.18k, False: 531]
  ------------------
  378|  4.18k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  4.18k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  379|    531|	return sc_pkcs15emu_cac_init(p15card);
  380|  4.71k|}
pkcs15-cac.c:cac_detect_card:
   65|  4.71k|{
   66|  4.71k|	sc_card_t *card = p15card->card;
   67|       |
   68|  4.71k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.71k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.71k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.71k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.71k]
  |  |  ------------------
  ------------------
   69|  4.71k|	if (card->type < SC_CARD_TYPE_CAC_GENERIC
  ------------------
  |  Branch (69:6): [True: 3.78k, False: 929]
  ------------------
   70|    929|		|| card->type >= SC_CARD_TYPE_CAC_GENERIC+1000)
  ------------------
  |  Branch (70:6): [True: 398, False: 531]
  ------------------
   71|  4.18k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  4.18k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   72|    531|	return SC_SUCCESS;
  ------------------
  |  |   28|    531|#define SC_SUCCESS				0
  ------------------
   73|  4.71k|}
pkcs15-cac.c:sc_pkcs15emu_cac_init:
   89|    531|{
   90|    531|	static const pindata pins[] = {
   91|    531|		{ "1", "PIN", "", 0x00,
   92|    531|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    531|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
   93|    531|		  8, 4, 8,
   94|    531|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    531|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
   95|    531|		  SC_PKCS15_PIN_FLAG_INITIALIZED ,
  ------------------
  |  |   58|    531|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
   96|    531|		  -1, 0xFF,
   97|    531|		  SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|    531|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   98|    531|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   99|    531|	};
  100|       |	/* oid for key usage */
  101|    531|	static const struct sc_object_id usage_type = {{ 2, 5, 29, 15, -1 }};
  102|    531|	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|    531|	int    r, i;
  113|    531|	sc_card_t *card = p15card->card;
  114|    531|	sc_serial_number_t serial;
  115|    531|	char buf[SC_MAX_SERIALNR * 2 + 1];
  116|    531|	int count;
  117|    531|	char *token_name = NULL;
  118|       |
  119|       |
  120|    531|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    531|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    531|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    531|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 531]
  |  |  ------------------
  ------------------
  121|       |
  122|    531|	memset(&serial, 0, sizeof(serial));
  123|       |
  124|       |	/* could read this off card if needed */
  125|       |
  126|    531|	set_string(&p15card->tokeninfo->label, cac_get_name(card->type));
  127|    531|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   46|    531|#define MANU_ID		"Common Access Card"
  ------------------
  128|       |
  129|       |	/*
  130|       |	 * get serial number
  131|       |	 */
  132|    531|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  133|    531|	if (r < 0) {
  ------------------
  |  Branch (133:6): [True: 462, False: 69]
  ------------------
  134|    462|		sc_log(card->ctx, "sc_card_ctl rc=%d",r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  135|    462|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  136|    462|	} else {
  137|     69|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  138|     69|		set_string(&p15card->tokeninfo->serial_number, buf);
  139|     69|	}
  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|    531|	sc_log(card->ctx,  "CAC adding pins...");
  ------------------
  |  |   71|    531|#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.06k|	for (i = 0; pins[i].id; i++) {
  ------------------
  |  Branch (146:14): [True: 531, False: 531]
  ------------------
  147|    531|		struct sc_pkcs15_auth_info pin_info;
  148|    531|		struct sc_pkcs15_object   pin_obj;
  149|    531|		const char * label;
  150|       |
  151|    531|		memset(&pin_info, 0, sizeof(pin_info));
  152|    531|		memset(&pin_obj,  0, sizeof(pin_obj));
  153|       |
  154|    531|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    531|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  155|    531|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  156|    531|		pin_info.attrs.pin.reference     = pins[i].ref;
  157|    531|		pin_info.attrs.pin.flags         = pins[i].flags;
  158|    531|		pin_info.attrs.pin.type          = pins[i].type;
  159|    531|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  160|    531|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  161|    531|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  162|    531|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  163|    531|		sc_format_path(pins[i].path, &pin_info.path);
  164|    531|		pin_info.tries_left    = -1;
  165|       |
  166|    531|		label = pins[i].label;
  167|    531|		sc_log(card->ctx,  "CAC Adding pin %d label=%s",i, label);
  ------------------
  |  |   71|    531|#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|    531|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    531|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  169|    531|		pin_obj.flags = pins[i].obj_flags;
  170|       |
  171|       |		/* get the ACA path in case it needs to be selected before PIN verify */
  172|    531|		r = sc_card_ctl(card, SC_CARDCTL_CAC_GET_ACA_PATH, &pin_info.path);
  173|    531|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get ACA path.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|    531|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  176|    531|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  177|    531|	}
  178|       |
  179|       |	/* set other objects */
  180|    531|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_INIT_GET_GENERIC_OBJECTS, &count);
  181|    531|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate generic objects.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|    820|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (183:14): [True: 289, False: 531]
  ------------------
  184|    289|		struct sc_pkcs15_data_info obj_info;
  185|    289|		struct sc_pkcs15_object    obj_obj;
  186|       |
  187|    289|		r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_GET_NEXT_GENERIC_OBJECT, &obj_info);
  188|    289|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next generic object.");
  ------------------
  |  |  184|    289|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    289|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    289|	int _ret = (r); \
  |  |  |  |  178|    289|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 289]
  |  |  |  |  ------------------
  |  |  |  |  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|    289|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 289]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    289|		memset(&obj_obj, 0, sizeof(obj_obj));
  190|    289|		memcpy(obj_obj.label, obj_info.app_label, sizeof(obj_obj.label));
  191|       |
  192|    289|		r = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    289|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  193|    289|			&obj_obj, &obj_info);
  194|    289|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize generic object.");
  ------------------
  |  |  184|    289|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    289|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    289|	int _ret = (r); \
  |  |  |  |  178|    289|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 289]
  |  |  |  |  ------------------
  |  |  |  |  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|    289|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 289]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|    289|	}
  196|    531|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_FINAL_GET_GENERIC_OBJECTS, &count);
  197|    531|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize generic objects.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    531|	sc_log(card->ctx,  "CAC adding certs, pub and priv keys...");
  ------------------
  |  |   71|    531|#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|    531|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_INIT_GET_CERT_OBJECTS, &count);
  207|    531|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate cert objects.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|  2.40k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (209:14): [True: 1.87k, False: 531]
  ------------------
  210|  1.87k|		struct sc_pkcs15_data_info obj_info;
  211|  1.87k|		struct sc_pkcs15_cert_info cert_info;
  212|  1.87k|		struct sc_pkcs15_pubkey_info pubkey_info;
  213|  1.87k|		struct sc_pkcs15_prkey_info prkey_info;
  214|  1.87k|		struct sc_pkcs15_object cert_obj;
  215|  1.87k|		struct sc_pkcs15_object pubkey_obj;
  216|  1.87k|		struct sc_pkcs15_object prkey_obj;
  217|  1.87k|		sc_pkcs15_der_t   cert_der;
  218|  1.87k|		sc_pkcs15_cert_t *cert_out = NULL;
  219|       |
  220|  1.87k|		r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_GET_NEXT_CERT_OBJECT, &obj_info);
  221|  1.87k|		LOG_TEST_RET(card->ctx, r, "Can not get next object");
  ------------------
  |  |  174|  1.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.87k|	int _ret = (r); \
  |  |  |  |  168|  1.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.87k]
  |  |  |  |  ------------------
  |  |  |  |  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.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|       |
  223|  1.87k|		memset(&cert_info, 0, sizeof(cert_info));
  224|  1.87k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  225|  1.87k|		memset(&prkey_info, 0, sizeof(prkey_info));
  226|  1.87k|		memset(&cert_obj,  0, sizeof(cert_obj));
  227|  1.87k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  228|  1.87k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  229|       |
  230|  1.87k|		cert_info.id = obj_info.id;
  231|  1.87k|		pubkey_info.id = obj_info.id;
  232|  1.87k|		prkey_info.id = obj_info.id;
  233|  1.87k|		cert_info.path = obj_info.path;
  234|  1.87k|		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|  1.87k|		if (prkey_info.path.len && prkey_info.path.len <= 2) {
  ------------------
  |  Branch (237:7): [True: 91, False: 1.78k]
  |  Branch (237:30): [True: 91, False: 0]
  ------------------
  238|     91|			prkey_info.path.value[2] = prkey_info.path.value[0];
  239|     91|			prkey_info.path.value[3] = prkey_info.path.value[1];
  240|     91|			prkey_info.path.value[0] = 0x3f;
  241|     91|			prkey_info.path.value[1] = 0x00;
  242|     91|			prkey_info.path.len += 2;
  243|     91|		}
  244|  1.87k|		pubkey_info.native        = 1;
  245|  1.87k|		pubkey_info.key_reference = ((int)obj_info.id.value[0]) << 8 | obj_info.id.value[1];
  246|  1.87k|		prkey_info.key_reference = ((int)obj_info.id.value[0]) << 8 | obj_info.id.value[1];
  247|  1.87k|		prkey_info.native        = 1;
  248|       |
  249|  1.87k|		memcpy(cert_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  250|  1.87k|		memcpy(pubkey_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  251|  1.87k|		memcpy(prkey_obj.label, obj_info.app_label, sizeof(obj_info.app_label));
  252|  1.87k|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  1.87k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  253|  1.87k|		sc_pkcs15_format_id(pins[0].id, &prkey_obj.auth_id);
  254|       |
  255|  1.87k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, 0);
  256|       |
  257|  1.87k|		if (r) {
  ------------------
  |  Branch (257:7): [True: 1.71k, False: 158]
  ------------------
  258|  1.71k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  1.71k|#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|  1.71k|			continue;
  260|  1.71k|		}
  261|    158|		cert_info.path.count = (int)cert_der.len;
  262|       |
  263|    158|		sc_log(card->ctx, "cert len=%zu, cert_info.path.count=%d r=%d",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  264|    158|				cert_der.len, cert_info.path.count, r);
  265|    158|		sc_log_hex(card->ctx, "cert", cert_der.value, cert_der.len);
  ------------------
  |  |  129|    158|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    158|    _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|    158|		if (cert_der.value) {
  ------------------
  |  Branch (269:7): [True: 123, False: 35]
  ------------------
  270|    123|			cert_info.value.value = cert_der.value;
  271|    123|			cert_info.value.len = cert_der.len;
  272|    123|			cert_info.path.len = 0; /* use in mem cert from now on */
  273|    123|		}
  274|       |
  275|       |		/* following will find the cached cert in cert_info */
  276|    158|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert_out);
  277|    158|		if (r < 0 || cert_out->key == NULL) {
  ------------------
  |  Branch (277:7): [True: 158, False: 0]
  |  Branch (277:16): [True: 0, False: 0]
  ------------------
  278|    158|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  279|    158|			if (cert_out != NULL)
  ------------------
  |  Branch (279:8): [True: 0, False: 158]
  ------------------
  280|      0|				sc_pkcs15_free_certificate(cert_out);
  281|    158|			free(cert_info.value.value);
  282|    158|			continue;
  283|    158|		}
  284|       |
  285|      0|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  286|      0|		if (r < 0) {
  ------------------
  |  Branch (286:7): [True: 0, False: 0]
  ------------------
  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|      0|		if (!token_name) {
  ------------------
  |  Branch (293:7): [True: 0, False: 0]
  ------------------
  294|      0|			u8 * cn_name = NULL;
  295|      0|			size_t cn_len = 0;
  296|      0|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  297|      0|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  298|      0|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  299|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (299:8): [True: 0, False: 0]
  ------------------
  300|      0|				token_name = malloc (cn_len+1);
  301|      0|				if (!token_name) {
  ------------------
  |  Branch (301:9): [True: 0, False: 0]
  ------------------
  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|      0|				memcpy(token_name, cn_name, cn_len);
  307|      0|				free(cn_name);
  308|      0|				token_name[cn_len] = 0;
  309|      0|				free(p15card->tokeninfo->label);
  310|      0|				p15card->tokeninfo->label = token_name;
  311|      0|			}
  312|      0|		}
  313|       |
  314|       |
  315|      0|		r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, cert_out->key, &pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
  316|      0|		if (r < 0)
  ------------------
  |  Branch (316:7): [True: 0, False: 0]
  ------------------
  317|      0|			goto fail;
  318|      0|		pubkey_obj.emulated = cert_out->key;
  319|       |
  320|      0|		r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out, &usage_type, &usage, NULL);
  321|      0|		if (r < 0) {
  ------------------
  |  Branch (321:7): [True: 0, False: 0]
  ------------------
  322|      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
  ------------------
  323|      0|		}
  324|      0|		sc_pkcs15_map_usage(usage, cert_out->key->algorithm, &pubkey_info.usage, &prkey_info.usage, 1);
  325|      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__
  |  |  ------------------
  ------------------
  326|      0|				sc_dump_hex(cert_info.id.value, cert_info.id.len),
  327|      0|				 usage, pubkey_info.usage, prkey_info.usage);
  328|      0|		if (cert_out->key->algorithm != SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (328:7): [True: 0, False: 0]
  ------------------
  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|      0|		} else {
  334|      0|			pubkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  335|      0|			prkey_info.modulus_length = cert_out->key->u.rsa.modulus.len * 8;
  336|      0|			r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  337|      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__
  |  |  ------------------
  ------------------
  338|      0|			if (r < 0) {
  ------------------
  |  Branch (338:8): [True: 0, False: 0]
  ------------------
  339|      0|				free(pubkey_info.direct.spki.value);
  340|      0|				goto fail;
  341|      0|			}
  342|      0|			pubkey_info.direct.spki.value = NULL; /* moved to the pubkey object on p15card  */
  343|      0|			pubkey_info.direct.spki.len = 0;
  344|      0|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  345|      0|			if (r < 0)
  ------------------
  |  Branch (345:8): [True: 0, False: 0]
  ------------------
  346|      0|				goto fail;
  347|      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__
  |  |  ------------------
  ------------------
  348|      0|		}
  349|       |
  350|      0|		cert_out->key = NULL;
  351|      0|fail:
  352|      0|		sc_pkcs15_free_certificate(cert_out);
  353|      0|		if (r < 0) {
  ------------------
  |  Branch (353:7): [True: 0, False: 0]
  ------------------
  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|      0|	}
  359|    531|	r = (card->ops->card_ctl)(card, SC_CARDCTL_CAC_FINAL_GET_CERT_OBJECTS, &count);
  360|    531|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize cert objects.");
  ------------------
  |  |  184|    531|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    531|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    531|	int _ret = (r); \
  |  |  |  |  178|    531|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  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|    531|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 531]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|    531|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    531|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    531|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    531|	int _ret = r; \
  |  |  |  |  155|    531|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 531, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    531|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 531]
  |  |  |  |  ------------------
  |  |  |  |  157|    531|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    531|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    531|	return _ret; \
  |  |  |  |  163|    531|} 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|    531|{
   79|    531|    switch (type) {
   80|    125|    case SC_CARD_TYPE_CAC_I: return ("CAC I");
  ------------------
  |  Branch (80:5): [True: 125, False: 406]
  ------------------
   81|    222|    case SC_CARD_TYPE_CAC_II: return ("CAC II");
  ------------------
  |  Branch (81:5): [True: 222, False: 309]
  ------------------
   82|    184|    case SC_CARD_TYPE_CAC_ALT_HID: return ("CAC ALT HID");
  ------------------
  |  Branch (82:5): [True: 184, False: 347]
  ------------------
   83|      0|    default: break;
  ------------------
  |  Branch (83:5): [True: 0, False: 531]
  ------------------
   84|    531|    }
   85|      0|    return ("CAC");
   86|    531|}

sc_pkcs15_read_cached_file:
  113|  3.80k|{
  114|  3.80k|	char fname[PATH_MAX];
  115|  3.80k|	int rv;
  116|  3.80k|	FILE *f;
  117|  3.80k|	size_t count;
  118|  3.80k|	struct stat stbuf;
  119|  3.80k|	u8 *data = NULL;
  120|       |
  121|  3.80k|	if (path->len < 2)
  ------------------
  |  Branch (121:6): [True: 1.84k, False: 1.96k]
  ------------------
  122|  1.84k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.84k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  123|       |
  124|       |	/* Accept full path or FILE-ID path with AID */
  125|  1.96k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  1.96k|#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|  1.67k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (125:6): [True: 836, False: 1.12k]
  |  Branch (125:44): [True: 0, False: 836]
  |  Branch (125:82): [True: 506, False: 330]
  ------------------
  126|    506|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    506|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  127|       |
  128|  1.45k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  129|  1.45k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  130|  1.45k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  1.45k|#define SC_SUCCESS				0
  ------------------
  |  Branch (130:6): [True: 814, False: 641]
  ------------------
  131|    814|		return rv;
  132|    641|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|    641|#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|       |
  134|    641|	f = fopen(fname, "rb");
  135|    641|	if (!f)
  ------------------
  |  Branch (135:6): [True: 484, False: 157]
  ------------------
  136|    484|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    484|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  137|    157|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (137:6): [True: 0, False: 157]
  ------------------
  138|      0|		fclose(f);
  139|      0|		return  SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  140|      0|	}
  141|       |
  142|    157|	if (path->count < 0) {
  ------------------
  |  Branch (142:6): [True: 119, False: 38]
  ------------------
  143|    119|		count = stbuf.st_size;
  144|    119|	}
  145|     38|	else {
  146|     38|		count = path->count;
  147|     38|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (147:7): [True: 34, False: 4]
  ------------------
  148|     34|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|     34|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  149|     34|			goto err;
  150|     34|		}
  151|       |
  152|      4|		if (0 != fseek(f, (long)path->index, SEEK_SET)) {
  ------------------
  |  Branch (152:7): [True: 0, False: 4]
  ------------------
  153|      0|			rv = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  154|      0|			goto err;
  155|      0|		}
  156|      4|	}
  157|       |
  158|    123|	if (*buf == NULL) {
  ------------------
  |  Branch (158:6): [True: 97, False: 26]
  ------------------
  159|     97|		data = malloc((size_t)stbuf.st_size);
  160|     97|		if (data == NULL)   {
  ------------------
  |  Branch (160:7): [True: 0, False: 97]
  ------------------
  161|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  162|      0|			goto err;
  163|      0|		}
  164|     97|	}
  165|     26|	else {
  166|     26|		if (count > *bufsize) {
  ------------------
  |  Branch (166:7): [True: 2, False: 24]
  ------------------
  167|      2|			rv =  SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      2|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  168|      2|			goto err;
  169|      2|		}
  170|     24|		data = *buf;
  171|     24|	}
  172|       |
  173|    121|	if (count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (173:6): [True: 0, False: 121]
  ------------------
  174|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  175|      0|		goto err;
  176|      0|	}
  177|    121|	*buf = data;
  178|    121|	*bufsize = count;
  179|       |
  180|    121|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    121|#define SC_SUCCESS				0
  ------------------
  181|       |
  182|    157|err:
  183|    157|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    157|#define SC_SUCCESS				0
  ------------------
  |  Branch (183:6): [True: 36, False: 121]
  ------------------
  184|     36|		if (data != *buf) {
  ------------------
  |  Branch (184:7): [True: 2, False: 34]
  ------------------
  185|      2|			free(data);
  186|      2|		}
  187|     36|	}
  188|       |
  189|    157|	fclose(f);
  190|    157|	return rv;
  191|    121|}
sc_pkcs15_cache_file:
  196|    667|{
  197|    667|	char fname[PATH_MAX];
  198|    667|	int r;
  199|    667|	long len;
  200|    667|	FILE *f;
  201|    667|	size_t c;
  202|       |
  203|    667|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  204|    667|	if (r != 0)
  ------------------
  |  Branch (204:6): [True: 505, False: 162]
  ------------------
  205|    505|		return r;
  206|       |
  207|    162|	f = fopen(fname, "ab");
  208|       |	/* If the open failed because the cache directory does
  209|       |	 * not exist, create it and a re-try the fopen() call.
  210|       |	 */
  211|    162|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (211:6): [True: 68, False: 94]
  |  Branch (211:19): [True: 68, False: 0]
  ------------------
  212|     68|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (212:7): [True: 63, False: 5]
  ------------------
  213|     63|			return r;
  214|      5|		f = fopen(fname, "ab");
  215|      5|	}
  216|     99|	if (f == NULL)
  ------------------
  |  Branch (216:6): [True: 2, False: 97]
  ------------------
  217|      2|		return 0;
  218|       |
  219|       |	/* we opened the file for appending so we should be at the end of file.
  220|       |	 * The ftell() will give use the length of the file */
  221|     97|	len = ftell(f);
  222|     97|	if (len > path->index) {
  ------------------
  |  Branch (222:6): [True: 2, False: 95]
  ------------------
  223|       |		/* override previous cache records on this location */
  224|      2|		r = fseek(f, path->index, SEEK_SET);
  225|      2|		if (r != 0) {
  ------------------
  |  Branch (225:7): [True: 0, False: 2]
  ------------------
  226|      0|			fclose(f);
  227|      0|			return 0;
  228|      0|		}
  229|     95|	} else if (path->index > len) {
  ------------------
  |  Branch (229:13): [True: 3, False: 92]
  ------------------
  230|       |		/* We miss some bytes so we will not cache this chunk */
  231|      3|		fclose(f);
  232|      3|		return 0;
  233|      3|	}
  234|       |
  235|     94|	c = fwrite(buf, 1, bufsize, f);
  236|     94|	fclose(f);
  237|     94|	if (c != bufsize) {
  ------------------
  |  Branch (237:6): [True: 0, False: 94]
  ------------------
  238|      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__
  |  |  ------------------
  ------------------
  239|      0|		unlink(fname);
  240|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  241|      0|	}
  242|     94|	return 0;
  243|     94|}
pkcs15-cache.c:generate_cache_filename:
   44|  2.12k|{
   45|  2.12k|	char dir[PATH_MAX];
   46|  2.12k|	char *last_update = NULL;
   47|  2.12k|	int  r;
   48|  2.12k|	unsigned u;
   49|  2.12k|	size_t change_counter;
   50|       |
   51|  2.12k|	if (p15card->tokeninfo->serial_number == NULL
  ------------------
  |  Branch (51:6): [True: 1.12k, False: 993]
  ------------------
   52|  1.12k|			&& (p15card->card->uid.len == 0
  ------------------
  |  Branch (52:8): [True: 1.12k, False: 0]
  ------------------
   53|      0|				|| p15card->card->uid.value[0] == RANDOM_UID_INDICATOR))
  ------------------
  |  |   40|      0|#define RANDOM_UID_INDICATOR 0x08
  ------------------
  |  Branch (53:8): [True: 0, False: 0]
  ------------------
   54|  1.12k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.12k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   55|       |
   56|    993|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|    993|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (56:6): [True: 0, False: 993]
  ------------------
   57|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|    993|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   59|    993|	if (r)
  ------------------
  |  Branch (59:6): [True: 0, False: 993]
  ------------------
   60|      0|		return r;
   61|    993|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   62|       |
   63|    993|	last_update = sc_pkcs15_get_lastupdate(p15card);
   64|    993|	if (!last_update)
  ------------------
  |  Branch (64:6): [True: 979, False: 14]
  ------------------
   65|    979|		last_update = "NODATE";
   66|       |
   67|    993|	if (p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (67:6): [True: 993, False: 0]
  ------------------
   68|    993|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   69|    993|				"%s_%s", p15card->tokeninfo->serial_number,
   70|    993|				last_update);
   71|    993|	} else {
   72|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   73|      0|				"uid-%s_%s", sc_dump_hex(
   74|      0|					p15card->card->uid.value,
   75|      0|					p15card->card->uid.len), last_update);
   76|      0|	}
   77|       |
   78|    993|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|    993|#define SC_SUCCESS				0
  ------------------
  |  Branch (78:6): [True: 1, False: 992]
  ------------------
   79|      1|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%zu", change_counter);
   80|       |
   81|    993|	if (path->aid.len &&
  ------------------
  |  Branch (81:6): [True: 272, False: 721]
  ------------------
   82|    272|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|    544|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|    171|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (82:4): [True: 101, False: 171]
  |  Branch (82:42): [True: 17, False: 154]
  ------------------
   83|    118|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   84|  1.08k|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (84:15): [True: 962, False: 118]
  ------------------
   85|    962|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   86|    962|					"%02X",  path->aid.value[u]);
   87|    118|	}
   88|    875|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|    875|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (88:11): [True: 190, False: 685]
  ------------------
   89|    190|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    190|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|    190|	}
   91|       |
   92|    803|	if (path->len)   {
  ------------------
  |  Branch (92:6): [True: 803, False: 0]
  ------------------
   93|    803|		size_t offs = 0;
   94|       |
   95|    803|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (95:7): [True: 685, False: 118]
  |  Branch (95:24): [True: 675, False: 10]
  ------------------
   96|    675|			offs = 2;
   97|    803|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   98|  3.81k|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (98:15): [True: 3.01k, False: 803]
  ------------------
   99|  3.01k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  100|  3.01k|					"%02X",  path->value[u + offs]);
  101|    803|	}
  102|       |
  103|    803|	if (!buf)
  ------------------
  |  Branch (103:6): [True: 0, False: 803]
  ------------------
  104|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  105|    803|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|    803|#define strlcpy _strlcpy
  ------------------
  106|       |
  107|    803|	return SC_SUCCESS;
  ------------------
  |  |   28|    803|#define SC_SUCCESS				0
  ------------------
  108|    803|}

sc_pkcs15emu_cardos_init_ex:
  172|  3.42k|{
  173|  3.42k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (173:6): [True: 3.11k, False: 314]
  ------------------
  174|  3.11k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.11k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  175|       |
  176|    314|	return sc_pkcs15emu_cardos_init(p15card, aid);
  177|  3.42k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  138|  3.42k|{
  139|  3.42k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (139:6): [True: 273, False: 3.15k]
  ------------------
  140|    273|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    273|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  141|       |
  142|  3.15k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (142:6): [True: 2.84k, False: 314]
  ------------------
  143|  2.84k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  2.84k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|    314|	return SC_SUCCESS;
  ------------------
  |  |   28|    314|#define SC_SUCCESS				0
  ------------------
  146|  3.15k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  151|    314|{
  152|    314|	sc_card_t *card = p15card->card;
  153|    314|	int r;
  154|       |
  155|    314|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    314|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    314|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    314|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    314|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 314]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|       |
  157|    314|	r = sc_pkcs15_bind_internal(p15card, aid);
  158|    314|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal failed");
  ------------------
  |  |  174|    314|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    314|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    314|	int _ret = (r); \
  |  |  |  |  168|    314|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 310, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|    310|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    310|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    310|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    310|		return _ret; \
  |  |  |  |  172|    310|	} \
  |  |  |  |  173|    314|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|       |
  160|       |	/* If card has created algorithms, return  */
  161|      4|	sc_log(card->ctx, " card->algorithms:%p card->algorithm_count:%d", card->algorithms, card->algorithm_count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  162|      4|	if (!card->algorithms && card->algorithm_count == 0) {
  ------------------
  |  Branch (162:6): [True: 4, False: 0]
  |  Branch (162:27): [True: 4, False: 0]
  ------------------
  163|      4|		r = cardos_fix_token_info(p15card);
  164|      4|	}
  165|       |
  166|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      4|}
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: 0, False: 4]
  ------------------
  120|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "EID_COMPLIANT flag found");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  121|      0|				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |   96|      0|#define SC_ALGORITHM_SPECIFIC_FLAGS	0x001FFFFF
  ------------------
              				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_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 */
  |  |  ------------------
  ------------------
  122|      0|			} else
  123|      4|				passed->new_flags = passed->used_flags; /* from default cardos_init */
  124|      4|		}
  125|      4|	}
  126|       |
  127|      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__
  |  |  ------------------
  ------------------
  128|       |
  129|      4|	passed->pass = 2; /* tell card driver to use the new flags */
  130|      4|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
  131|       |
  132|      4|	free(passed);
  133|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|      4|}

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

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

sc_pkcs15emu_coolkey_init_ex:
  732|  3.79k|{
  733|  3.79k|	sc_card_t      *card = p15card->card;
  734|  3.79k|	sc_context_t    *ctx = card->ctx;
  735|  3.79k|	int rv;
  736|       |
  737|  3.79k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.79k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.79k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.79k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|       |
  739|  3.79k|	rv = coolkey_detect_card(p15card);
  740|  3.79k|	if (rv)
  ------------------
  |  Branch (740:6): [True: 3.77k, False: 24]
  ------------------
  741|  3.79k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  3.77k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.77k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.77k|	int _ret = r; \
  |  |  |  |  155|  3.77k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.77k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.77k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.77k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.77k|	} else { \
  |  |  |  |  159|      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.77k|	return _ret; \
  |  |  |  |  163|  3.77k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|     24|	rv = sc_pkcs15emu_coolkey_init(p15card);
  743|       |
  744|     24|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  745|     24|}
pkcs15-coolkey.c:coolkey_detect_card:
   60|  3.79k|{
   61|  3.79k|	sc_card_t *card = p15card->card;
   62|       |
   63|  3.79k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.79k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.79k]
  |  |  ------------------
  ------------------
   64|  3.79k|	if (card->type < SC_CARD_TYPE_COOLKEY_GENERIC
  ------------------
  |  Branch (64:6): [True: 3.73k, False: 59]
  ------------------
   65|     59|		|| card->type >= SC_CARD_TYPE_COOLKEY_GENERIC+1000)
  ------------------
  |  Branch (65:6): [True: 35, False: 24]
  ------------------
   66|  3.77k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  3.77k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   67|     24|	return SC_SUCCESS;
  ------------------
  |  |   28|     24|#define SC_SUCCESS				0
  ------------------
   68|  3.79k|}
pkcs15-coolkey.c:sc_pkcs15emu_coolkey_init:
  467|     24|{
  468|     24|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  469|     24|	static const pindata pins[] = {
  470|     24|		{ "1", NULL, "", 0x00,
  471|     24|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|     24|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  472|     24|		  32, 4, 32,
  473|     24|		  SC_PKCS15_PIN_FLAG_INITIALIZED,
  ------------------
  |  |   58|     24|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  474|     24|		  -1, 0xFF,
  475|     24|		  SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|     24|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  476|     24|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  477|     24|	};
  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|     24|	int    r, i;
  487|     24|	sc_card_t *card = p15card->card;
  488|     24|	sc_serial_number_t serial;
  489|     24|	int count;
  490|     24|	struct sc_pkcs15_object *obj;
  491|       |
  492|     24|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     24|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     24|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     24|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 24]
  |  |  ------------------
  ------------------
  493|       |
  494|     24|	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|     24|	p15card->opts.use_pin_cache = 0;
  500|       |
  501|       |	/* get the token info from the card */
  502|     24|	r = sc_card_ctl(card, SC_CARDCTL_COOLKEY_GET_TOKEN_INFO, p15card->tokeninfo);
  503|     24|	if (r < 0) {
  ------------------
  |  Branch (503:6): [True: 0, False: 24]
  ------------------
  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|     24|	sc_log(card->ctx,  "Coolkey adding pins...");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  512|     48|	for (i = 0; pins[i].id; i++) {
  ------------------
  |  Branch (512:14): [True: 24, False: 24]
  ------------------
  513|     24|		struct sc_pkcs15_auth_info pin_info;
  514|     24|		struct sc_pkcs15_object   pin_obj;
  515|     24|		const char * label;
  516|       |
  517|     24|		memset(&pin_info, 0, sizeof(pin_info));
  518|     24|		memset(&pin_obj,  0, sizeof(pin_obj));
  519|       |
  520|     24|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     24|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  521|     24|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  522|     24|		pin_info.attrs.pin.reference     = pins[i].ref;
  523|     24|		pin_info.attrs.pin.flags         = pins[i].flags;
  524|     24|		pin_info.attrs.pin.type          = pins[i].type;
  525|     24|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  526|     24|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  527|     24|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  528|     24|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  529|     24|		sc_format_path(pins[i].path, &pin_info.path);
  530|     24|		pin_info.tries_left    = -1;
  531|       |
  532|     24|		label = pins[i].label? pins[i].label : p15card->tokeninfo->label;
  ------------------
  |  Branch (532:11): [True: 0, False: 24]
  ------------------
  533|     24|		sc_log(card->ctx,  "Coolkey Adding pin %d label=%s",i, label);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  534|     24|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|     24|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  535|     24|		pin_obj.flags = pins[i].obj_flags;
  536|       |
  537|     24|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  538|     24|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object.");
  ------------------
  |  |  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: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|     24|	}
  540|       |
  541|       |	/* set other objects */
  542|     24|	r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS, &count);
  543|     24|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate objects.");
  ------------------
  |  |  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: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  544|       |
  545|     24|	sc_log(card->ctx,  "Iterating over %d objects", count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  546|     24|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (546:14): [True: 0, False: 24]
  ------------------
  547|      0|		struct sc_cardctl_coolkey_object     coolkey_obj;
  548|      0|		struct sc_pkcs15_object    obj_obj;
  549|      0|		struct sc_pkcs15_cert_info cert_info = {0};
  550|      0|		struct sc_pkcs15_pubkey_info pubkey_info;
  551|      0|		struct sc_pkcs15_prkey_info prkey_info;
  552|      0|		sc_pkcs15_pubkey_t *key = NULL;
  553|      0|		void *obj_info = NULL;
  554|      0|		int obj_type = 0;
  555|      0|		CK_KEY_TYPE key_type;
  556|      0|		CK_OBJECT_CLASS obj_class;
  557|      0|		size_t len;
  558|       |
  559|      0|		r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT, &coolkey_obj);
  560|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next object from 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  561|      0|		sc_log(card->ctx, "Loading object %d", 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__
  |  |  ------------------
  ------------------
  562|      0|		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|      0|		coolkey_get_attribute_bytes(card, &coolkey_obj, CKA_LABEL, (u8 *)obj_obj.label, &len, sizeof(obj_obj.label));
  ------------------
  |  |  140|      0|#define CKA_LABEL 0x00000003UL
  ------------------
  566|      0|		coolkey_get_flags(card, &coolkey_obj, &obj_obj.flags);
  567|      0|		if (obj_obj.flags & SC_PKCS15_CO_FLAG_PRIVATE) {
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  |  Branch (567:7): [True: 0, False: 0]
  ------------------
  568|      0|			sc_pkcs15_format_id(pins[0].id, &obj_obj.auth_id);
  569|      0|		}
  570|       |
  571|      0|		r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_CLASS, &obj_class);
  ------------------
  |  |  137|      0|#define CKA_CLASS 0x00000000UL
  ------------------
  572|      0|		if (r < 0) {
  ------------------
  |  Branch (572:7): [True: 0, False: 0]
  ------------------
  573|      0|			goto fail;
  574|      0|		}
  575|      0|		switch (obj_class) {
  576|      0|		case CKO_PRIVATE_KEY:
  ------------------
  |  | 1030|      0|#define CKO_PRIVATE_KEY 0x00000003UL
  ------------------
  |  Branch (576:3): [True: 0, False: 0]
  ------------------
  577|      0|			sc_log(card->ctx, "Processing private key object %d", 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__
  |  |  ------------------
  ------------------
  578|      0|			r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_KEY_TYPE, &key_type);
  ------------------
  |  |  159|      0|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  579|       |			/* default to CKK_RSA */
  580|      0|			if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (580:8): [True: 0, False: 0]
  ------------------
  581|      0|				key_type = CKK_RSA;
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
  582|      0|				r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  583|      0|			}
  584|      0|			if (r < 0) {
  ------------------
  |  Branch (584:8): [True: 0, False: 0]
  ------------------
  585|      0|				goto fail;
  586|      0|			}
  587|       |			/* set the info values */
  588|      0|			obj_info = &prkey_info;
  589|      0|			memset(&prkey_info, 0, sizeof(prkey_info));
  590|      0|			coolkey_get_id(card, &coolkey_obj, &prkey_info.id);
  591|      0|			prkey_info.path = coolkey_obj.path;
  592|      0|			prkey_info.key_reference = (int)coolkey_obj.id;
  593|      0|			prkey_info.native = 1;
  594|      0|			coolkey_get_usage(card, &coolkey_obj, &prkey_info.usage);
  595|      0|			coolkey_get_access(card, &coolkey_obj, &prkey_info.access_flags);
  596|      0|			key = coolkey_get_public_key(p15card, &coolkey_obj, key_type);
  597|      0|			if (key_type == CKK_RSA) {
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (597:8): [True: 0, False: 0]
  ------------------
  598|      0|				obj_type = SC_PKCS15_TYPE_PRKEY_RSA;
  ------------------
  |  |  419|      0|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  599|      0|				if (key) {
  ------------------
  |  Branch (599:9): [True: 0, False: 0]
  ------------------
  600|      0|					prkey_info.modulus_length = key->u.rsa.modulus.len*8;
  601|      0|				}
  602|      0|			} else if (key_type == CKK_EC) {
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (602:15): [True: 0, False: 0]
  ------------------
  603|      0|				obj_type = SC_PKCS15_TYPE_PRKEY_EC;
  ------------------
  |  |  421|      0|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  604|      0|				if (key) {
  ------------------
  |  Branch (604:9): [True: 0, False: 0]
  ------------------
  605|      0|					prkey_info.field_length = key->u.ec.params.field_length;
  606|      0|				}
  607|      0|			} else {
  608|      0|				goto fail;
  609|      0|			}
  610|      0|			break;
  611|       |
  612|      0|		case CKO_PUBLIC_KEY:
  ------------------
  |  | 1029|      0|#define CKO_PUBLIC_KEY 0x00000002UL
  ------------------
  |  Branch (612:3): [True: 0, False: 0]
  ------------------
  613|      0|			sc_log(card->ctx, "Processing public key object %d", 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__
  |  |  ------------------
  ------------------
  614|      0|			r = coolkey_get_attribute_ulong(card, &coolkey_obj, CKA_KEY_TYPE, &key_type);
  ------------------
  |  |  159|      0|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  615|       |			/* default to CKK_RSA */
  616|      0|			if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (616:8): [True: 0, False: 0]
  ------------------
  617|      0|				key_type = CKK_RSA;
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
  618|      0|				r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  619|      0|			}
  620|      0|			if (r < 0) {
  ------------------
  |  Branch (620:8): [True: 0, False: 0]
  ------------------
  621|      0|				goto fail;
  622|      0|			}
  623|      0|			key = coolkey_get_public_key(p15card, &coolkey_obj, key_type);
  624|      0|			if (key == NULL) {
  ------------------
  |  Branch (624:8): [True: 0, False: 0]
  ------------------
  625|      0|				goto fail;
  626|      0|			}
  627|       |			/* set the info values */
  628|      0|			obj_info = &pubkey_info;
  629|      0|			memset(&pubkey_info, 0, sizeof(pubkey_info));
  630|      0|			r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, key, &pubkey_info.direct.spki.value,
  631|      0|				&pubkey_info.direct.spki.len);
  632|      0|			if (r < 0)
  ------------------
  |  Branch (632:8): [True: 0, False: 0]
  ------------------
  633|      0|				goto fail;
  634|      0|			coolkey_get_id(card, &coolkey_obj, &pubkey_info.id);
  635|      0|			pubkey_info.path = coolkey_obj.path;
  636|      0|			pubkey_info.native = 1;
  637|      0|			pubkey_info.key_reference = (int)coolkey_obj.id;
  638|      0|			coolkey_get_usage(card, &coolkey_obj, &pubkey_info.usage);
  639|      0|			coolkey_get_access(card, &coolkey_obj, &pubkey_info.access_flags);
  640|      0|			if (key_type == CKK_RSA) {
  ------------------
  |  |  464|      0|#define CKK_RSA 0x00000000UL
  ------------------
  |  Branch (640:8): [True: 0, False: 0]
  ------------------
  641|      0|				obj_type = SC_PKCS15_TYPE_PUBKEY_RSA;
  ------------------
  |  |  426|      0|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  642|      0|				pubkey_info.modulus_length = key->u.rsa.modulus.len*8;
  643|      0|			} else if (key_type == CKK_EC) {
  ------------------
  |  |  467|      0|#define CKK_EC 0x00000003UL
  ------------------
  |  Branch (643:15): [True: 0, False: 0]
  ------------------
  644|      0|				obj_type = SC_PKCS15_TYPE_PUBKEY_EC;
  ------------------
  |  |  428|      0|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  645|      0|				pubkey_info.field_length = key->u.ec.params.field_length;
  646|      0|			} else {
  647|      0|				free(pubkey_info.direct.spki.value);
  648|      0|				goto fail;
  649|      0|			}
  650|       |			/* set the obj values */
  651|      0|			obj_obj.emulated = key;
  652|      0|			key = NULL;
  653|      0|			break;
  654|       |
  655|      0|		case CKO_CERTIFICATE:
  ------------------
  |  | 1028|      0|#define CKO_CERTIFICATE 0x00000001UL
  ------------------
  |  Branch (655:3): [True: 0, False: 0]
  ------------------
  656|      0|			sc_log(card->ctx, "Processing certificate object %d", 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__
  |  |  ------------------
  ------------------
  657|      0|			obj_info = &cert_info;
  658|      0|			memset(&cert_info, 0, sizeof(cert_info));
  659|      0|			coolkey_get_id(card, &coolkey_obj, &cert_info.id);
  660|      0|			cert_info.path = coolkey_obj.path;
  661|      0|			obj_type = SC_PKCS15_TYPE_CERT_X509;
  ------------------
  |  |  439|      0|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  662|       |
  663|       |			/* following will find the cached cert in cert_info */
  664|      0|			r = coolkey_get_certificate(card, &coolkey_obj, &cert_info.value);
  665|      0|			if (r < 0) {
  ------------------
  |  Branch (665:8): [True: 0, False: 0]
  ------------------
  666|      0|				goto fail;
  667|      0|			}
  668|      0|			break;
  669|       |
  670|       |
  671|      0|		default:
  ------------------
  |  Branch (671:3): [True: 0, False: 0]
  ------------------
  672|       |			/* no other recognized types which are stored 'on card' */
  673|      0|			sc_log(card->ctx, "Unknown object type %lu, skipping", obj_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__
  |  |  ------------------
  ------------------
  674|      0|			continue;
  675|      0|		}
  676|       |
  677|      0|		r = sc_pkcs15emu_object_add(p15card, obj_type, &obj_obj, obj_info);
  678|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (678:7): [True: 0, False: 0]
  ------------------
  679|      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__
  |  |  ------------------
  ------------------
  680|      0|fail:
  681|      0|		if (key) {
  ------------------
  |  Branch (681:7): [True: 0, False: 0]
  ------------------
  682|      0|			sc_pkcs15_free_pubkey(key);
  683|      0|		}
  684|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (684:7): [True: 0, False: 0]
  ------------------
  685|      0|			free(cert_info.value.value);
  686|      0|		}
  687|      0|	}
  688|     24|	r = (card->ops->card_ctl)(card, SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS, &count);
  689|     24|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize objects.");
  ------------------
  |  |  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: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  690|       |
  691|       |	/* Iterate over all the created objects and fill missing labels */
  692|     48|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (692:32): [True: 24, False: 24]
  ------------------
  693|     24|		struct sc_pkcs15_id *id = NULL;
  694|     24|		struct sc_pkcs15_object *cert_object;
  695|       |
  696|       |		/* label non-empty -- do not overwrite */
  697|     24|		if (obj->label[0] != '\0')
  ------------------
  |  Branch (697:7): [True: 24, False: 0]
  ------------------
  698|     24|			continue;
  699|       |
  700|      0|		switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  701|      0|		case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (701:3): [True: 0, False: 0]
  ------------------
  702|      0|			id = &((struct sc_pkcs15_pubkey_info *)obj->data)->id;
  703|      0|			break;
  704|      0|		case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (704:3): [True: 0, False: 0]
  ------------------
  705|      0|			id = &((struct sc_pkcs15_prkey_info *)obj->data)->id;
  706|      0|			break;
  707|      0|		default:
  ------------------
  |  Branch (707:3): [True: 0, False: 0]
  ------------------
  708|       |			/* We do not care about other objects */
  709|      0|			continue;
  710|      0|		}
  711|      0|		r = sc_pkcs15_find_cert_by_id(p15card, id, &cert_object);
  712|      0|		if (r != 0)
  ------------------
  |  Branch (712:7): [True: 0, False: 0]
  ------------------
  713|      0|			continue;
  714|       |
  715|      0|		sc_log(card->ctx, "Copy label \"%s\" from cert to key object",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  716|      0|			cert_object->label);
  717|      0|		memcpy(obj->label, cert_object->label, SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|      0|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  718|      0|	}
  719|       |
  720|     24|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|       |
  722|      0|err:
  723|      0|	sc_pkcs15_card_clear(p15card);
  724|      0|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  725|       |
  726|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|      0|}

sc_pkcs15_read_data_object:
   46|  8.68k|{
   47|  8.68k|	struct sc_context *ctx = p15card->card->ctx;
   48|  8.68k|	struct sc_pkcs15_data *data_object;
   49|  8.68k|	struct sc_pkcs15_der der;
   50|  8.68k|	int r;
   51|       |
   52|  8.68k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  8.68k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.68k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.68k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.68k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.68k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|  8.68k|	if (!info || !data_object_out)
  ------------------
  |  Branch (53:6): [True: 0, False: 8.68k]
  |  Branch (53:15): [True: 0, False: 8.68k]
  ------------------
   54|  8.68k|		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|  8.68k|	if (!info->data.value)   {
  ------------------
  |  Branch (56:6): [True: 8.47k, False: 208]
  ------------------
   57|  8.47k|		r = sc_pkcs15_read_file(p15card, &info->path, (unsigned char **) &info->data.value, (size_t *) &info->data.len, private_obj);
   58|  8.47k|		LOG_TEST_RET(ctx, r, "Cannot get DATA object data");
  ------------------
  |  |  174|  8.47k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.47k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.47k|	int _ret = (r); \
  |  |  |  |  168|  8.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7.32k, False: 1.15k]
  |  |  |  |  ------------------
  |  |  |  |  169|  7.32k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.32k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  7.32k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  7.32k|		return _ret; \
  |  |  |  |  172|  7.32k|	} \
  |  |  |  |  173|  8.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|  8.47k|	}
   60|       |
   61|  1.36k|	r = sc_der_copy(&der, &info->data);
   62|  1.36k|	LOG_TEST_RET(ctx, r, "Cannot allocate memory for der value");
  ------------------
  |  |  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: 0, False: 1.36k]
  |  |  |  |  ------------------
  |  |  |  |  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.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.36k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|       |
   64|  1.36k|	data_object = calloc(1, sizeof(struct sc_pkcs15_data));
   65|  1.36k|	if (!data_object)   {
  ------------------
  |  Branch (65:6): [True: 0, False: 1.36k]
  ------------------
   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|  1.36k|	data_object->data = der.value;
   71|  1.36k|	data_object->data_len = der.len;
   72|  1.36k|	*data_object_out = data_object;
   73|       |
   74|  1.36k|	LOG_FUNC_RETURN(ctx,SC_SUCCESS);
  ------------------
  |  |  164|  1.36k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.36k|	int _ret = r; \
  |  |  |  |  155|  1.36k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.36k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.36k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.36k|	return _ret; \
  |  |  |  |  163|  1.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|  1.36k|}
sc_pkcs15_decode_dodf_entry:
   95|     16|{
   96|     16|        sc_context_t *ctx = p15card->card->ctx;
   97|     16|	struct sc_pkcs15_data_info info;
   98|     16|	struct sc_asn1_entry	asn1_com_data_attr[3],
   99|     16|				asn1_type_data_attr[2],
  100|     16|				asn1_data[2];
  101|     16|	struct sc_asn1_pkcs15_object data_obj = { obj, asn1_com_data_attr, NULL,
  102|     16|					     asn1_type_data_attr };
  103|     16|	size_t label_len = sizeof(info.app_label) - 1;
  104|     16|	int r;
  105|       |
  106|     16|	memset(info.app_label, 0, sizeof(info.app_label));
  107|       |
  108|     16|	sc_copy_asn1_entry(c_asn1_com_data_attr, asn1_com_data_attr);
  109|     16|	sc_copy_asn1_entry(c_asn1_type_data_attr, asn1_type_data_attr);
  110|     16|	sc_copy_asn1_entry(c_asn1_data, asn1_data);
  111|       |
  112|     16|	sc_format_asn1_entry(asn1_com_data_attr + 0, &info.app_label, &label_len, 0);
  113|     16|	sc_format_asn1_entry(asn1_com_data_attr + 1, &info.app_oid, NULL, 0);
  114|     16|	sc_format_asn1_entry(asn1_type_data_attr + 0, &info.path, NULL, 0);
  115|     16|	sc_format_asn1_entry(asn1_data + 0, &data_obj, NULL, 0);
  116|       |
  117|       |	/* Fill in defaults */
  118|     16|	memset(&info, 0, sizeof(info));
  119|     16|	sc_init_oid(&info.app_oid);
  120|       |
  121|     16|	r = sc_asn1_decode(ctx, asn1_data, *buf, *buflen, buf, buflen);
  122|     16|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     16|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (122:6): [True: 4, False: 12]
  ------------------
  123|      4|		return r;
  124|     12|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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: 4, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  125|       |
  126|      8|	if (!p15card->app || !p15card->app->ddo.aid.len) {
  ------------------
  |  Branch (126:6): [True: 8, False: 0]
  |  Branch (126:23): [True: 0, False: 0]
  ------------------
  127|      8|		if (!p15card->file_app) {
  ------------------
  |  Branch (127:7): [True: 0, False: 8]
  ------------------
  128|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  129|      0|		}
  130|      8|		r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path);
  131|      8|		if (r < 0)
  ------------------
  |  Branch (131:7): [True: 0, False: 8]
  ------------------
  132|      0|			return r;
  133|      8|	}
  134|      0|	else   {
  135|      0|		info.path.aid = p15card->app->ddo.aid;
  136|      0|	}
  137|       |
  138|      8|	obj->type = SC_PKCS15_TYPE_DATA_OBJECT;
  ------------------
  |  |  442|      8|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  139|      8|	obj->data = malloc(sizeof(info));
  140|      8|	if (obj->data == NULL)
  ------------------
  |  Branch (140:6): [True: 0, False: 8]
  ------------------
  141|      8|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  142|      8|	memcpy(obj->data, &info, sizeof(info));
  143|       |
  144|      8|	return SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  145|      8|}
sc_pkcs15_free_data_object:
  180|  1.36k|{
  181|  1.36k|	if (data_object == NULL)
  ------------------
  |  Branch (181:6): [True: 0, False: 1.36k]
  ------------------
  182|      0|		return;
  183|       |
  184|  1.36k|	free(data_object->data);
  185|  1.36k|	free(data_object);
  186|  1.36k|}
sc_pkcs15_free_data_info:
  189|  20.6k|{
  190|  20.6k|	if (info && info->data.value && info->data.len)
  ------------------
  |  Branch (190:6): [True: 20.6k, False: 0]
  |  Branch (190:14): [True: 1.02k, False: 19.6k]
  |  Branch (190:34): [True: 1.01k, False: 2]
  ------------------
  191|  1.01k|		free(info->data.value);
  192|       |
  193|  20.6k|	free(info);
  194|  20.6k|}

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

sc_pkcs15emu_dnie_init_ex:
  281|  4.01k|{
  282|  4.01k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  4.01k|#define SC_SUCCESS				0
  ------------------
  283|  4.01k|	sc_context_t *ctx = p15card->card->ctx;
  284|  4.01k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  4.01k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  4.01k|	r = dnie_match_card(p15card->card);
  289|  4.01k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 3.73k, False: 275]
  ------------------
  290|  4.01k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  3.73k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.73k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.73k|	int _ret = r; \
  |  |  |  |  155|  3.73k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.73k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.73k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.73k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.73k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.73k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.73k|	} else { \
  |  |  |  |  159|      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.73k|	return _ret; \
  |  |  |  |  163|  3.73k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    275|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  164|    275|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    275|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    275|	int _ret = r; \
  |  |  |  |  155|    275|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 275, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    275|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    275|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 275, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    275|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    275|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    275|	return _ret; \
  |  |  |  |  163|    275|} 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|    275|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    275|{
  140|    275|	u8 buf[1024];
  141|    275|	sc_pkcs15_df_t *df;
  142|    275|	sc_pkcs15_object_t *p15_obj;
  143|    275|	size_t len = sizeof(buf);
  144|    275|	int rv;
  145|    275|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    275|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    275|	sc_context_t *ctx = p15card->card->ctx;
  149|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    275|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 1, False: 274]
  ------------------
  153|      1|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      1|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    274|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 274]
  ------------------
  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|    274|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    274|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 12, False: 262]
  ------------------
  163|     12|		p15card->opts.use_pin_cache = 1;
  164|     12|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|     12|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|     12|		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|     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__
  |  |  ------------------
  ------------------
  166|     12|			p15card->opts.use_file_cache,
  167|     12|			p15card->opts.use_pin_cache,
  168|     12|			p15card->opts.pin_cache_counter,
  169|     12|			p15card->opts.pin_cache_ignore_user_consent);
  170|     12|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    274|	sc_file_free(p15card->file_app);
  174|    274|	p15card->file_app = sc_file_new();
  175|    274|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 274]
  ------------------
  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|    274|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    274|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    274|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    274|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    274|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    274|	int _ret = (r); \
  |  |  |  |  178|    274|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 265, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  179|    265|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    265|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    265|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    265|		goto err; \
  |  |  |  |  182|    265|	} \
  |  |  |  |  183|    274|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|      9|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  186|      9|				       buf, len);
  187|      9|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of EF.TOKENINFO failed.");
  ------------------
  |  |  184|      9|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      9|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      9|	int _ret = (r); \
  |  |  |  |  178|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      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
  |  |  |  |  ------------------
  |  |  |  |  180|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      9|		goto err; \
  |  |  |  |  182|      9|	} \
  |  |  |  |  183|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* Only accept the original stuff */
  190|      0|	if (strcmp(p15card->tokeninfo->manufacturer_id, "DGP-FNMT") != 0) {
  ------------------
  |  Branch (190:6): [True: 0, False: 0]
  ------------------
  191|      0|		rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  192|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Wrong 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|      0|	}
  194|       |
  195|       |	/* Load ODF */
  196|      0|	rv = dump_ef(p15card->card, "3F0050155031", buf, &len);
  197|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of ODF 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|      0|	rv = parse_odf(buf, len, p15card);
  200|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of ODF 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|       |	/* Decode EF.PrKDF, EF.PuKDF and EF.CDF */
  203|      0|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (203:30): [True: 0, False: 0]
  ------------------
  204|      0|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|      0|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (204:7): [True: 0, False: 0]
  ------------------
  205|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  206|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (206:8): [True: 0, False: 0]
  ------------------
  207|      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__
  |  |  ------------------
  ------------------
  208|      0|				       "Decoding of EF.PrKDF (%s) failed: %d",
  209|      0|				       sc_print_path(&df->path), rv);
  210|      0|			}
  211|      0|		}
  212|      0|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|      0|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (212:7): [True: 0, False: 0]
  ------------------
  213|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  214|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (214:8): [True: 0, False: 0]
  ------------------
  215|      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__
  |  |  ------------------
  ------------------
  216|      0|				       "Decoding of EF.PuKDF (%s) failed: %d",
  217|      0|				       sc_print_path(&df->path), rv);
  218|      0|			}
  219|      0|		}
  220|      0|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|      0|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (220:7): [True: 0, False: 0]
  ------------------
  221|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  222|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:8): [True: 0, False: 0]
  ------------------
  223|      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__
  |  |  ------------------
  ------------------
  224|      0|				       "Decoding of EF.CDF (%s) failed: %d",
  225|      0|				       sc_print_path(&df->path), rv);
  226|      0|			}
  227|      0|		}
  228|      0|		if (df->type == SC_PKCS15_DODF) {
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (228:7): [True: 0, False: 0]
  ------------------
  229|      0|			rv = sc_pkcs15_parse_df(p15card, df);
  230|      0|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (230:8): [True: 0, False: 0]
  ------------------
  231|      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__
  |  |  ------------------
  ------------------
  232|      0|				       "Decoding of EF.DODF (%s) failed: %d",
  233|      0|				       sc_print_path(&df->path), rv);
  234|      0|			}
  235|      0|		}
  236|      0|	}
  237|       |
  238|       |	/* Perform required fixes */
  239|      0|	p15_obj = p15card->obj_list;
  240|      0|	while (p15_obj != NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 0]
  ------------------
  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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|    274|err:
  270|    274|	sc_pkcs15_card_clear(p15card);
  271|    274|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    274|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    274|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    274|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    274|	int _ret = r; \
  |  |  |  |  155|    274|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 274, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    274|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    274|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 274, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    274|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    274|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    274|	return _ret; \
  |  |  |  |  163|    274|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    274|}
pkcs15-dnie.c:dump_ef:
   42|    274|{
   43|    274|	int rv;
   44|    274|	sc_file_t *file = NULL;
   45|    274|	sc_path_t scpath;
   46|    274|	sc_format_path(path, &scpath);
   47|    274|	rv = sc_select_file(card, &scpath, &file);
   48|    274|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 256, False: 18]
  ------------------
   49|    256|		sc_file_free(file);
   50|    256|		return rv;
   51|    256|	}
   52|     18|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 8, False: 10]
  ------------------
   53|      8|		sc_file_free(file);
   54|      8|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      8|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|      8|	}
   56|     10|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   57|     10|	sc_file_free(file);
   58|     10|	if (rv < 0)
  ------------------
  |  Branch (58:6): [True: 1, False: 9]
  ------------------
   59|      1|		return rv;
   60|      9|	*buf_len = rv;
   61|       |
   62|      9|	return SC_SUCCESS;
  ------------------
  |  |   28|      9|#define SC_SUCCESS				0
  ------------------
   63|     10|}

sc_pkcs15emu_dtrust_init_ex:
  125|  3.42k|{
  126|  3.42k|	if (dtrust_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (126:6): [True: 3.42k, False: 0]
  ------------------
  127|  3.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  128|       |
  129|      0|	return sc_pkcs15emu_dtrust_init(p15card, aid);
  130|  3.42k|}
pkcs15-dtrust.c:dtrust_pkcs15emu_detect_card:
   82|  3.42k|{
   83|  3.42k|	if (p15card->card->type < SC_CARD_TYPE_DTRUST_V4_1_STD)
  ------------------
  |  Branch (83:6): [True: 3.42k, False: 0]
  ------------------
   84|  3.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#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|  3.42k|{
   36|  3.42k|	struct sc_card *card = p15card->card;
   37|  3.42k|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
   38|  3.42k|	struct sc_pkcs15_search_key sk;
   39|  3.42k|	struct sc_pkcs15_object *objs[MAX_OBJECTS];
   40|  3.42k|	int i, j, len;
   41|       |
   42|  3.42k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.42k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.42k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.42k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.42k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.42k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   43|       |
   44|  3.42k|	if (card->type != SC_CARD_TYPE_EOI && card->type != SC_CARD_TYPE_EOI_CONTACTLESS)
  ------------------
  |  Branch (44:6): [True: 3.42k, False: 0]
  |  Branch (44:40): [True: 3.42k, False: 0]
  ------------------
   45|  3.42k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  3.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.42k|	int _ret = r; \
  |  |  |  |  155|  3.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.42k|	return _ret; \
  |  |  |  |  163|  3.42k|} 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|  4.01k|{
   80|  4.01k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.01k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  ------------------
  ------------------
   81|       |
   82|  4.01k|	if (entersafe_detect_card(p15card))
  ------------------
  |  Branch (82:6): [True: 3.91k, False: 97]
  ------------------
   83|  3.91k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.91k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   84|     97|	return sc_pkcs15emu_entersafe_init(p15card);
   85|  4.01k|}
pkcs15-esinit.c:entersafe_detect_card:
   33|  4.01k|{
   34|  4.01k|	sc_card_t *card = p15card->card;
   35|       |
   36|  4.01k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.01k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  ------------------
  ------------------
   37|       |
   38|       |	/* check if we have the correct card OS */
   39|  4.01k|	if (strcmp(card->name, "entersafe"))
  ------------------
  |  Branch (39:6): [True: 3.91k, False: 97]
  ------------------
   40|  3.91k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.91k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   41|       |
   42|     97|    return SC_SUCCESS;
  ------------------
  |  |   28|     97|#define SC_SUCCESS				0
  ------------------
   43|  4.01k|}
pkcs15-esinit.c:sc_pkcs15emu_entersafe_init:
   46|     97|{
   47|     97|	int    r;
   48|     97|	char   buf[256];
   49|     97|	sc_card_t *card = p15card->card;
   50|     97|	sc_serial_number_t serial;
   51|       |
   52|     97|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   53|       |
   54|       |	/* get serial number */
   55|     97|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   56|     97|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     97|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:6): [True: 96, False: 1]
  ------------------
   57|     96|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     96|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|      1|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   59|      1|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (59:6): [True: 0, False: 1]
  ------------------
   60|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   61|       |
   62|      1|	set_string(&p15card->tokeninfo->serial_number, buf);
   63|      1|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (63:6): [True: 0, False: 1]
  ------------------
   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|      1|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   30|      1|#define MANU_ID		"entersafe"
  ------------------
   68|      1|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (68:6): [True: 0, False: 1]
  ------------------
   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|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
   75|      1|}

sc_pkcs15emu_esteid2018_init_ex:
  256|  3.42k|int sc_pkcs15emu_esteid2018_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid) {
  257|  3.42k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2018 ||
  ------------------
  |  Branch (257:6): [True: 0, False: 3.42k]
  ------------------
  258|  3.42k|			p15card->card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025 ||
  ------------------
  |  Branch (258:4): [True: 0, False: 3.42k]
  ------------------
  259|  3.42k|			is_latvian_eid(p15card))
  ------------------
  |  Branch (259:4): [True: 0, False: 3.42k]
  ------------------
  260|      0|		return sc_pkcs15emu_esteid2018_init(p15card);
  261|  3.42k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  262|  3.42k|}
pkcs15-esteid2018.c:is_latvian_eid:
   38|  3.42k|{
   39|  3.42k|	return p15card->card->type == SC_CARD_TYPE_LATEID_2018 ||
  ------------------
  |  Branch (39:9): [True: 0, False: 3.42k]
  ------------------
   40|  3.42k|	       p15card->card->type == SC_CARD_TYPE_LATEID_2018_V2_2025;
  ------------------
  |  Branch (40:9): [True: 0, False: 3.42k]
  ------------------
   41|  3.42k|}

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

sc_pkcs15emu_gemsafeV1_init_ex:
  451|  4.01k|{
  452|  4.01k|	if (gemsafe_detect_card(p15card))
  ------------------
  |  Branch (452:6): [True: 4.01k, False: 0]
  ------------------
  453|  4.01k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  4.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  454|      0|	return sc_pkcs15emu_gemsafeV1_init(p15card);
  455|  4.01k|}
pkcs15-gemsafeV1.c:gemsafe_detect_card:
  298|  4.01k|{
  299|  4.01k|	if (strcmp(p15card->card->name, "GemSAFE V1"))
  ------------------
  |  Branch (299:6): [True: 4.01k, False: 0]
  ------------------
  300|  4.01k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  4.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  301|       |
  302|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  303|  4.01k|}

sc_pkcs15emu_gids_init_ex:
  241|  4.01k|{
  242|  4.01k|	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: 3.97k, False: 38]
  |  Branch (242:58): [True: 3.97k, False: 1]
  |  Branch (242:105): [True: 3.97k, False: 1]
  ------------------
  243|  3.97k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.97k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  244|  3.97k|	}
  245|     40|	return sc_pkcs15emu_gids_init(p15card);
  246|  4.01k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  112|     40|{
  113|     40|	sc_card_t *card = p15card->card;
  114|     40|	int r;
  115|     40|	size_t i;
  116|     40|	struct sc_pkcs15_auth_info pin_info;
  117|     40|	struct sc_pkcs15_object pin_obj;
  118|     40|	struct sc_pin_cmd_data pin_cmd_data;
  119|     40|	size_t recordsnum;
  120|     40|	int has_puk;
  121|       |
  122|     40|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  123|     40|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  3.81k|{
  269|  3.81k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (269:6): [True: 3.81k, False: 0]
  ------------------
  270|  3.81k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.81k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  271|       |
  272|      0|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  273|  3.81k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  239|  3.81k|{
  240|  3.81k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (240:6): [True: 3.20k, False: 614]
  ------------------
  241|  3.20k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.20k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  242|       |
  243|    614|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (243:6): [True: 614, False: 0]
  ------------------
  244|    614|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    614|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  245|       |
  246|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  247|    614|}

sc_pkcs15emu_idprime_init_ex:
  357|  4.18k|{
  358|  4.18k|	sc_card_t   *card = p15card->card;
  359|  4.18k|	sc_context_t    *ctx = card->ctx;
  360|       |
  361|  4.18k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.18k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.18k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  362|       |
  363|  4.18k|	if (idprime_detect_card(p15card))
  ------------------
  |  Branch (363:6): [True: 4.01k, False: 169]
  ------------------
  364|  4.01k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  4.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  365|    169|	return sc_pkcs15emu_idprime_init(p15card);
  366|  4.18k|}
pkcs15-idprime.c:idprime_detect_card:
   40|  4.18k|{
   41|  4.18k|	sc_card_t *card = p15card->card;
   42|       |
   43|  4.18k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.18k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.18k]
  |  |  ------------------
  ------------------
   44|       |
   45|  4.18k|	if (card->type < SC_CARD_TYPE_IDPRIME_BASE
  ------------------
  |  Branch (45:6): [True: 3.81k, False: 363]
  ------------------
   46|    363|		|| card->type >= SC_CARD_TYPE_IDPRIME_BASE+1000)
  ------------------
  |  Branch (46:6): [True: 194, False: 169]
  ------------------
   47|  4.01k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  4.01k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   48|    169|	return SC_SUCCESS;
  ------------------
  |  |   28|    169|#define SC_SUCCESS				0
  ------------------
   49|  4.18k|}
pkcs15-idprime.c:sc_pkcs15emu_idprime_init:
   52|    169|{
   53|    169|	int r, i;
   54|    169|	sc_card_t *card = p15card->card;
   55|    169|	sc_serial_number_t serial;
   56|    169|	char buf[SC_MAX_SERIALNR * 2 + 1];
   57|    169|	int count;
   58|    169|	char *token_name = NULL;
   59|    169|	struct sc_pkcs15_auth_info pin_info;
   60|    169|	struct sc_pkcs15_object   pin_obj;
   61|    169|	const char pin_label[] = "PIN";
   62|    169|	const char *pin_id = "11";
   63|    169|	const char sig_pin_label[] = "Digital Signature PIN";
   64|    169|	const char *sig_pin_id = "83";
   65|       |
   66|       |	/* oid for key usage */
   67|    169|	static const struct sc_object_id usage_type = {{ 2, 5, 29, 15, -1 }};
   68|    169|	unsigned int usage;
   69|       |
   70|    169|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    169|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    169|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    169|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 169]
  |  |  ------------------
  ------------------
   71|       |
   72|       |	/* could read this off card if needed */
   73|    169|	set_string(&p15card->tokeninfo->label, "IDPrime");
   74|    169|	set_string(&p15card->tokeninfo->manufacturer_id, "Gemalto");
   75|       |
   76|       |	/*
   77|       |	 * get serial number
   78|       |	 */
   79|    169|	memset(&serial, 0, sizeof(serial));
   80|    169|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   81|    169|	if (r < 0) {
  ------------------
  |  Branch (81:6): [True: 159, False: 10]
  ------------------
   82|    159|		sc_log(card->ctx, "sc_card_ctl rc=%d", r);
  ------------------
  |  |   71|    159|#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|    159|		set_string(&p15card->tokeninfo->serial_number, "00000000");
   84|    159|	} else {
   85|     10|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   86|     10|		set_string(&p15card->tokeninfo->serial_number, buf);
   87|     10|	}
   88|       |	/* set pin */
   89|    169|	sc_log(card->ctx,  "IDPrime adding pin...");
  ------------------
  |  |   71|    169|#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|    169|	memset(&pin_info, 0, sizeof(pin_info));
   91|    169|	memset(&pin_obj,  0, sizeof(pin_obj));
   92|       |
   93|    169|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    169|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
   94|    169|	sc_pkcs15_format_id(pin_id, &pin_info.auth_id);
   95|    169|	pin_info.attrs.pin.reference     = 0x11;
   96|    169|	pin_info.attrs.pin.flags         = SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|    169|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
   97|    169|	pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    169|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
   98|    169|	pin_info.attrs.pin.min_length    = 4;
   99|    169|	pin_info.attrs.pin.stored_length = 0;
  100|    169|	pin_info.attrs.pin.max_length    = 16;
  101|    169|	pin_info.tries_left    = -1;
  102|       |
  103|    169|	if (card->type == SC_CARD_TYPE_IDPRIME_840
  ------------------
  |  Branch (103:6): [True: 0, False: 169]
  ------------------
  104|    169|	    || card->type == SC_CARD_TYPE_IDPRIME_940
  ------------------
  |  Branch (104:9): [True: 27, False: 142]
  ------------------
  105|    142|	    || card->type == SC_CARD_TYPE_IDPRIME_GENERIC) {
  ------------------
  |  Branch (105:9): [True: 31, False: 111]
  ------------------
  106|     58|		pin_info.attrs.pin.flags |= SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     58|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  107|     58|		pin_info.attrs.pin.stored_length = 16;
  108|     58|		pin_info.attrs.pin.pad_char = 0x00;
  109|     58|	}
  110|       |
  111|    169|	sc_log(card->ctx,  "IDPrime Adding pin with label=%s", pin_label);
  ------------------
  |  |   71|    169|#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|    169|	strncpy(pin_obj.label, pin_label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    169|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  113|    169|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    169|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  114|       |
  115|    169|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  116|    169|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add pin object");
  ------------------
  |  |  184|    169|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    169|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    169|	int _ret = (r); \
  |  |  |  |  178|    169|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  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|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 169]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|       |
  118|       |	/* set signature pin for 940 cards */
  119|    169|	if (card->type == SC_CARD_TYPE_IDPRIME_940) {
  ------------------
  |  Branch (119:6): [True: 27, False: 142]
  ------------------
  120|     27|		sc_log(card->ctx,  "IDPrime adding Digital Signature pin...");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  121|     27|		memset(&pin_info, 0, sizeof(pin_info));
  122|     27|		memset(&pin_obj,  0, sizeof(pin_obj));
  123|       |
  124|     27|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     27|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  125|     27|		sc_pkcs15_format_id(sig_pin_id, &pin_info.auth_id);
  126|     27|		pin_info.attrs.pin.reference     = 0x83;
  127|     27|		pin_info.attrs.pin.flags         = SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|     27|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  128|     27|		pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     27|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  129|     27|		pin_info.attrs.pin.min_length    = 4;
  130|     27|		pin_info.attrs.pin.stored_length = 0;
  131|     27|		pin_info.attrs.pin.max_length    = 16;
  132|     27|		pin_info.tries_left    = -1;
  133|       |
  134|     27|		pin_info.attrs.pin.flags |= SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     27|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  135|     27|		pin_info.attrs.pin.stored_length = 16;
  136|     27|		pin_info.attrs.pin.pad_char = 0x00;
  137|       |
  138|     27|		sc_log(card->ctx,  "IDPrime Adding Digital Signature pin with label=%s", sig_pin_label);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  139|     27|		strncpy(pin_obj.label, sig_pin_label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|     27|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  140|     27|		pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     27|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  141|       |
  142|     27|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  143|     27|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not add Digital Signature pin object");
  ------------------
  |  |  184|     27|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     27|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     27|	int _ret = (r); \
  |  |  |  |  178|     27|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 27]
  |  |  |  |  ------------------
  |  |  |  |  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|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|     27|	}
  145|       |
  146|       |	/*
  147|       |	 * get token name if provided
  148|       |	 */
  149|    169|	r = sc_card_ctl(card, SC_CARDCTL_IDPRIME_GET_TOKEN_NAME, &token_name);
  150|    169|	if (r < 0) {
  ------------------
  |  Branch (150:6): [True: 169, False: 0]
  ------------------
  151|       |		/* On failure we will get the token name from certificates later */
  152|    169|		sc_log(card->ctx, "sc_card_ctl rc=%d", r);
  ------------------
  |  |   71|    169|#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|    169|	} else {
  154|      0|		free(p15card->tokeninfo->label);
  155|      0|		p15card->tokeninfo->label = token_name;
  156|      0|		sc_log(card->ctx,  "IDPrime setting token label = %s", token_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__
  |  |  ------------------
  ------------------
  157|      0|	}
  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|    169|	sc_log(card->ctx,  "IDPrime adding certs, pub and priv keys...");
  ------------------
  |  |   71|    169|#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|    169|	r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_INIT_GET_OBJECTS, &count);
  166|    169|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not initiate cert objects.");
  ------------------
  |  |  184|    169|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    169|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    169|	int _ret = (r); \
  |  |  |  |  178|    169|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  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|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 169]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|       |
  168|    482|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (168:14): [True: 313, False: 169]
  ------------------
  169|    313|		struct sc_pkcs15_prkey_info prkey_info;
  170|    313|		struct sc_pkcs15_cert_info cert_info;
  171|    313|		struct sc_pkcs15_pubkey_info pubkey_info;
  172|    313|		struct sc_pkcs15_object cert_obj;
  173|    313|		struct sc_pkcs15_object pubkey_obj;
  174|    313|		struct sc_pkcs15_object prkey_obj;
  175|    313|		sc_pkcs15_der_t cert_der;
  176|    313|		sc_pkcs15_cert_t *cert_out = NULL;
  177|    313|		const char *pin_id = NULL;
  178|       |
  179|    313|		r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_GET_PIN_ID, (void *) &pin_id);
  180|    313|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get PIN id of next object ");
  ------------------
  |  |  184|    313|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    313|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    313|	int _ret = (r); \
  |  |  |  |  178|    313|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 313]
  |  |  |  |  ------------------
  |  |  |  |  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|    313|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 313]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|    313|		r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_GET_NEXT_OBJECT, &prkey_info);
  182|    313|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can not get next object");
  ------------------
  |  |  184|    313|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    313|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    313|	int _ret = (r); \
  |  |  |  |  178|    313|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 313]
  |  |  |  |  ------------------
  |  |  |  |  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|    313|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 313]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    313|		memset(&cert_info, 0, sizeof(cert_info));
  185|    313|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  186|       |		/* prkey_info cleaned by the card_ctl call */
  187|    313|		memset(&cert_obj,  0, sizeof(cert_obj));
  188|    313|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  189|    313|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  190|       |
  191|    313|		cert_info.id = prkey_info.id;
  192|    313|		pubkey_info.id = prkey_info.id;
  193|    313|		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|    313|		prkey_info.path.len = 0;
  197|    313|		prkey_info.path.aid.len = 0;
  198|    313|		pubkey_info.key_reference = prkey_info.key_reference;
  199|    313|		sc_log(card->ctx,  "Key ref r=%x", prkey_info.key_reference);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  200|       |
  201|    313|		pubkey_info.native        = 1;
  202|    313|		prkey_info.native        = 1;
  203|       |
  204|    313|		snprintf(cert_obj.label, SC_PKCS15_MAX_LABEL_SIZE, CERT_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|    313|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(cert_obj.label, SC_PKCS15_MAX_LABEL_SIZE, CERT_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|    313|#define CERT_LABEL_TEMPLATE "Certificate %d"
  ------------------
  205|    313|		snprintf(pubkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PUBKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|    313|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(pubkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PUBKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   36|    313|#define PUBKEY_LABEL_TEMPLATE "Public key %d"
  ------------------
  206|    313|		snprintf(prkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PRIVKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   35|    313|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
              		snprintf(prkey_obj.label, SC_PKCS15_MAX_LABEL_SIZE, PRIVKEY_LABEL_TEMPLATE, i+1);
  ------------------
  |  |   37|    313|#define PRIVKEY_LABEL_TEMPLATE "Private key %d"
  ------------------
  207|    313|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    313|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  208|       |
  209|       |		/* Differentiate between objects accessible with normal and with digital signature pin */
  210|    313|		sc_pkcs15_format_id(pin_id, &prkey_obj.auth_id);
  211|    313|		sc_log(card->ctx,  "Pin ID r=%s", pin_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  212|       |
  213|    313|		if (memcmp(pin_id, sig_pin_id, 2) == 0)
  ------------------
  |  Branch (213:7): [True: 21, False: 292]
  ------------------
  214|     21|			prkey_obj.user_consent = 1;
  215|       |
  216|    313|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, 0);
  217|       |
  218|    313|		if (r) {
  ------------------
  |  Branch (218:7): [True: 287, False: 26]
  ------------------
  219|    287|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  220|    287|			continue;
  221|    287|		}
  222|     26|		cert_info.path.count = (int)cert_der.len;
  223|       |
  224|     26|		sc_log(card->ctx, "cert len=%zu, cert_info.path.count=%d r=%d",
  ------------------
  |  |   71|     26|#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|     26|				cert_der.len, cert_info.path.count, r);
  226|     26|		sc_log_hex(card->ctx, "cert", cert_der.value, cert_der.len);
  ------------------
  |  |  129|     26|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     26|    _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|     26|		if (cert_der.value) {
  ------------------
  |  Branch (230:7): [True: 14, False: 12]
  ------------------
  231|     14|			cert_info.value.value = cert_der.value;
  232|     14|			cert_info.value.len = cert_der.len;
  233|     14|			cert_info.path.len = 0; /* use in mem cert from now on */
  234|     14|		}
  235|       |
  236|       |		/* following will find the cached cert in cert_info */
  237|     26|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert_out);
  238|     26|		if (r < 0 || cert_out->key == NULL) {
  ------------------
  |  Branch (238:7): [True: 26, False: 0]
  |  Branch (238:16): [True: 0, False: 0]
  ------------------
  239|     26|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|     26|#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|     26|			if (cert_out != NULL)
  ------------------
  |  Branch (240:8): [True: 0, False: 26]
  ------------------
  241|      0|				sc_pkcs15_free_certificate(cert_out);
  242|     26|			free(cert_der.value);
  243|     26|			continue;
  244|     26|		}
  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|    169|	r = (card->ops->card_ctl)(card, SC_CARDCTL_IDPRIME_FINAL_GET_OBJECTS, &count);
  346|    169|	LOG_TEST_GOTO_ERR(card->ctx, r, "Can not finalize cert objects.");
  ------------------
  |  |  184|    169|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    169|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    169|	int _ret = (r); \
  |  |  |  |  178|    169|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  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|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 169]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|       |
  348|    169|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 169]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  5.80k|{
  882|  5.80k|	sc_card_t *card = p15card->card;
  883|  5.80k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  5.80k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.80k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.80k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.80k]
  |  |  ------------------
  ------------------
  884|       |
  885|       |	/* Check card */
  886|  5.80k|	if (! (
  887|  5.80k|			(card->type > SC_CARD_TYPE_ITACNS_BASE &&
  ------------------
  |  Branch (887:5): [True: 1.71k, False: 4.08k]
  ------------------
  888|  1.71k|			card->type < SC_CARD_TYPE_ITACNS_BASE + 1000)
  ------------------
  |  Branch (888:4): [True: 210, False: 1.50k]
  ------------------
  889|  5.59k|		|| card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (889:6): [True: 0, False: 5.59k]
  ------------------
  890|  5.80k|		)
  891|  5.59k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  5.59k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  892|       |
  893|       |	/* Init card */
  894|    210|	return itacns_init(p15card);
  895|  5.80k|}
pkcs15-itacns.c:itacns_init:
  761|    210|{
  762|    210|	int r;
  763|    210|	sc_path_t path;
  764|    210|	int certificate_count = 0;
  765|    210|	int found_certs;
  766|    210|	int card_is_cie_v1, cns0_secenv;
  767|       |
  768|    210|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    210|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    210|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    210|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 210]
  |  |  ------------------
  ------------------
  769|       |
  770|    210|	set_string(&p15card->tokeninfo->label, p15card->card->name);
  771|    210|	if(p15card->card->drv_data) {
  ------------------
  |  Branch (771:5): [True: 210, False: 0]
  ------------------
  772|    210|		unsigned int mask_code, ic_code;
  773|    210|		char buffer[256];
  774|    210|		itacns_drv_data_t *data =
  775|    210|			(itacns_drv_data_t*) p15card->card->drv_data;
  776|    210|		mask_code = data->mask_manufacturer_code;
  777|    210|		if (mask_code >= sizeof(itacns_mask_manufacturers)
  ------------------
  |  Branch (777:7): [True: 186, False: 24]
  ------------------
  778|    210|			/sizeof(itacns_mask_manufacturers[0]))
  779|    186|			mask_code = 0;
  780|    210|		ic_code = data->ic_manufacturer_code;
  781|    210|		if (ic_code >= sizeof(iso7816_ic_manufacturers)
  ------------------
  |  Branch (781:7): [True: 178, False: 32]
  ------------------
  782|    210|			/sizeof(iso7816_ic_manufacturers[0]))
  783|    178|			ic_code = 0;
  784|    210|		snprintf(buffer, sizeof(buffer), "IC: %s; mask: %s",
  785|    210|			iso7816_ic_manufacturers[ic_code],
  786|    210|			itacns_mask_manufacturers[mask_code]);
  787|    210|		set_string(&p15card->tokeninfo->manufacturer_id, buffer);
  788|    210|	}
  789|       |
  790|       |	/* Read and set serial */
  791|    210|	{
  792|    210|		u8 serial[17];
  793|    210|		int bytes;
  794|    210|		sc_format_path(path_serial, &path);
  795|    210|		bytes = loadFile(p15card, &path, serial, 16);
  796|    210|		if (bytes < 0) return bytes;
  ------------------
  |  Branch (796:7): [True: 73, False: 137]
  ------------------
  797|    137|		if (bytes > 16) return -1;
  ------------------
  |  Branch (797:7): [True: 0, False: 137]
  ------------------
  798|    137|		serial[bytes] = '\0';
  799|    137|		set_string(&p15card->tokeninfo->serial_number, (char*)serial);
  800|    137|	}
  801|       |
  802|       |	/* Is the card a CIE v1? */
  803|      0|	card_is_cie_v1 =
  804|    137|		   (p15card->card->type == SC_CARD_TYPE_ITACNS_CIE_V1)
  ------------------
  |  Branch (804:6): [True: 0, False: 137]
  ------------------
  805|    137|		|| (p15card->card->type == SC_CARD_TYPE_CARDOS_CIE_V1);
  ------------------
  |  Branch (805:6): [True: 0, False: 137]
  ------------------
  806|    137|	cns0_secenv = (card_is_cie_v1 ? 0x31 : 0x01);
  ------------------
  |  Branch (806:17): [True: 0, False: 137]
  ------------------
  807|       |
  808|       |	/* If it's a Siemens CIE v1 card, set algo flags accordingly. */
  809|    137|	if (card_is_cie_v1) {
  ------------------
  |  Branch (809:6): [True: 0, False: 137]
  ------------------
  810|      0|		int i;
  811|      0|		for (i = 0; i < p15card->card->algorithm_count; i++) {
  ------------------
  |  Branch (811:15): [True: 0, False: 0]
  ------------------
  812|      0|			sc_algorithm_info_t *info =
  813|      0|				&p15card->card->algorithms[i];
  814|       |
  815|      0|			if (info->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (815:8): [True: 0, False: 0]
  ------------------
  816|      0|				continue;
  817|      0|			info->flags &= ~(SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  818|      0|				| SC_ALGORITHM_RSA_HASH_NONE);
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  819|      0|			info->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 */
  |  |  ------------------
  ------------------
  820|      0|				| SC_ALGORITHM_RSA_HASHES);
  ------------------
  |  |  142|      0|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  821|      0|		}
  822|      0|	}
  823|       |
  824|       |	/* Data files */
  825|    137|	r = itacns_add_data_files(p15card);
  826|    137|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    137|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    137|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    137|	int _ret = (r); \
  |  |  |  |  178|    137|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 137]
  |  |  |  |  ------------------
  |  |  |  |  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|    137|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 137]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|    137|		"Could not add data files");
  828|       |
  829|       |	/*** Certificate and keys. ***/
  830|       |	/* Standard CNS */
  831|    137|	r = itacns_check_and_add_keyset(p15card, "CNS0", cns0_secenv,
  832|    137|		0, "3F0011001101", "3F003F01", NULL,
  833|    137|		0x10, &found_certs);
  834|    137|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    137|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    137|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    137|	int _ret = (r); \
  |  |  |  |  178|    137|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 72, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     72|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     72|		goto err; \
  |  |  |  |  182|     72|	} \
  |  |  |  |  183|    137|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|     65|		"Could not add CNS0");
  836|     65|	certificate_count += found_certs;
  837|       |
  838|       |	/* Infocamere 1204 */
  839|     65|	r = itacns_check_and_add_keyset(p15card, "CNS01", 0x21,
  840|     65|		5, "3F002FFF8228", NULL, "3F002FFF0000",
  841|     65|		0x10, &found_certs);
  842|     65|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     65|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     65|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     65|	int _ret = (r); \
  |  |  |  |  178|     65|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 31, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     31|		goto err; \
  |  |  |  |  182|     31|	} \
  |  |  |  |  183|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     34|		"Could not add CNS01");
  844|     34|	certificate_count += found_certs;
  845|       |
  846|       |	/* Digital signature */
  847|     34|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x10,
  848|     34|		0, "3F0014009010", "3F00140081108010", "3F0014008110",
  849|     34|		0x1a, &found_certs);
  850|     34|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     34|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     34|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     34|	int _ret = (r); \
  |  |  |  |  178|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 15, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|     19|		"Could not add CNS1");
  852|     19|	certificate_count += found_certs;
  853|       |
  854|       |	/* Idemia card */
  855|     19|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x02,
  856|     19|		0, "3F00140090012002", "3F0011001102", "3F0014009002",
  857|     19|		0x10, &found_certs);
  858|     19|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  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: 8, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|     11|		"Could not add CNS1");
  860|     11|	certificate_count += found_certs;
  861|       |
  862|       |	/* Did we find anything? */
  863|     11|	if (certificate_count == 0)
  ------------------
  |  Branch (863:6): [True: 11, False: 0]
  ------------------
  864|     11|		sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|     11|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  865|     11|			"Warning: no certificates found!");
  866|       |
  867|       |	/* Back to Master File */
  868|     11|	sc_format_path("3F00", &path);
  869|     11|	r = sc_select_file(p15card->card, &path, NULL);
  870|     11|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     11|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     11|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     11|	int _ret = (r); \
  |  |  |  |  178|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  871|      6|		"Could not select master file again");
  872|       |
  873|      6|	LOG_FUNC_RETURN(p15card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  874|       |
  875|    123|err:
  876|    123|	sc_pkcs15_card_clear(p15card);
  877|    123|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    123|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    123|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    123|	int _ret = r; \
  |  |  |  |  155|    123|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 123, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    123|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    123|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 123, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    123|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    123|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    123|	return _ret; \
  |  |  |  |  163|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    123|}
pkcs15-itacns.c:loadFile:
  169|    261|{
  170|    261|	int sc_res;
  171|    261|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    261|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    261|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    261|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 261]
  |  |  ------------------
  ------------------
  172|       |
  173|    261|	sc_res = sc_select_file(p15card->card, path, NULL);
  174|    261|	if(sc_res != SC_SUCCESS)
  ------------------
  |  |   28|    261|#define SC_SUCCESS				0
  ------------------
  |  Branch (174:5): [True: 61, False: 200]
  ------------------
  175|     61|		return sc_res;
  176|       |
  177|    200|	sc_res = sc_read_binary(p15card->card, 0, buf, buflen, 0);
  178|    200|	return sc_res;
  179|    261|}
pkcs15-itacns.c:itacns_add_data_files:
  482|    137|{
  483|    137|	const size_t array_size =
  484|    137|		sizeof(itacns_data_files)/sizeof(itacns_data_files[0]);
  485|    137|	unsigned int i;
  486|    137|	int rv;
  487|    137|	sc_pkcs15_data_t *p15_personaldata = NULL;
  488|    137|	sc_pkcs15_data_info_t dinfo;
  489|    137|	struct sc_pkcs15_object *objs[32];
  490|    137|	struct sc_pkcs15_data_info *cinfo;
  491|    137|	int private_obj;
  492|       |
  493|  2.05k|	for(i=0; i < array_size; i++) {
  ------------------
  |  Branch (493:11): [True: 1.91k, False: 137]
  ------------------
  494|  1.91k|		sc_path_t path;
  495|  1.91k|		sc_pkcs15_data_info_t data;
  496|  1.91k|		sc_pkcs15_object_t    obj;
  497|       |
  498|  1.91k|		if (itacns_data_files[i].cie_only &&
  ------------------
  |  Branch (498:7): [True: 548, False: 1.37k]
  ------------------
  499|    548|			p15card->card->type != SC_CARD_TYPE_ITACNS_CIE_V2)
  ------------------
  |  Branch (499:4): [True: 540, False: 8]
  ------------------
  500|    540|			continue;
  501|       |
  502|  1.37k|		sc_format_path(itacns_data_files[i].path, &path);
  503|       |
  504|  1.37k|		memset(&data, 0, sizeof(data));
  505|  1.37k|		memset(&obj, 0, sizeof(obj));
  506|  1.37k|		strlcpy(data.app_label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.37k|#define strlcpy _strlcpy
  ------------------
  507|  1.37k|			sizeof(data.app_label));
  508|  1.37k|		strlcpy(obj.label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.37k|#define strlcpy _strlcpy
  ------------------
  509|  1.37k|			sizeof(obj.label));
  510|  1.37k|		data.path = path;
  511|  1.37k|		rv = sc_pkcs15emu_add_data_object(p15card, &obj, &data);
  512|  1.37k|		LOG_TEST_RET(p15card->card->ctx, rv,
  ------------------
  |  |  174|  1.37k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.37k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.37k|	int _ret = (r); \
  |  |  |  |  168|  1.37k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.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|  1.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|  1.37k|			"Could not add data file");
  514|  1.37k|	}
  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|    137|	memset(&dinfo, 0, sizeof(dinfo));
  522|    137|	strlcpy(dinfo.app_label, "EF_DatiPersonali", sizeof(dinfo.app_label));
  ------------------
  |  |   43|    137|#define strlcpy _strlcpy
  ------------------
  523|       |
  524|       |	/* Find EF_DatiPersonali */
  525|       |
  526|    137|	rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    137|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  527|    137|		objs, 32);
  528|    137|	if(rv < 0) {
  ------------------
  |  Branch (528:5): [True: 0, False: 137]
  ------------------
  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|    413|	for(i=0; i<32; i++) {
  ------------------
  |  Branch (534:11): [True: 413, False: 0]
  ------------------
  535|    413|		cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  536|    413|		if(!strcmp("EF_DatiPersonali", objs[i]->label))
  ------------------
  |  Branch (536:6): [True: 137, False: 276]
  ------------------
  537|    137|			break;
  538|    413|	}
  539|       |
  540|    137|	if(i>=32) {
  ------------------
  |  Branch (540:5): [True: 0, False: 137]
  ------------------
  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|    137|	private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    137|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  548|    137|	rv = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &p15_personaldata);
  549|    137|	if (rv) {
  ------------------
  |  Branch (549:6): [True: 51, False: 86]
  ------------------
  550|     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__
  |  |  ------------------
  ------------------
  551|     51|			"Could not read EF_DatiPersonali: "
  552|     51|			"keeping generic card name");
  553|     51|		return SC_SUCCESS;
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  554|     51|	}
  555|       |
  556|     86|	if (p15_personaldata->data) {
  ------------------
  |  Branch (556:6): [True: 71, False: 15]
  ------------------
  557|     71|		char fullname[160];
  558|     71|		if (get_name_from_EF_DatiPersonali(p15_personaldata->data,
  ------------------
  |  Branch (558:7): [True: 70, False: 1]
  ------------------
  559|     71|			p15_personaldata->data_len, fullname, sizeof(fullname))) {
  560|     70|			sc_log(p15card->card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  561|     70|				"Could not parse EF_DatiPersonali: "
  562|     70|				"keeping generic card name");
  563|     70|			sc_pkcs15_free_data_object(p15_personaldata);
  564|     70|			free(cinfo->data.value);
  565|     70|			cinfo->data.value = NULL;
  566|     70|			return SC_SUCCESS;
  ------------------
  |  |   28|     70|#define SC_SUCCESS				0
  ------------------
  567|     70|		}
  568|      1|		set_string(&p15card->tokeninfo->label, fullname);
  569|      1|	}
  570|     16|	free(cinfo->data.value);
  571|     16|	cinfo->data.value = NULL;
  572|     16|	sc_pkcs15_free_data_object(p15_personaldata);
  573|     16|	return SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  574|     86|}
pkcs15-itacns.c:get_name_from_EF_DatiPersonali:
  387|     71|{
  388|     71|	const unsigned int EF_personaldata_maxlen = 400;
  389|     71|	const unsigned int tlv_length_size = 6;
  390|     71|	char *file = NULL;
  391|     71|	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|     71|	if (EFdata_len < tlv_length_size) {
  ------------------
  |  Branch (397:6): [True: 3, False: 68]
  ------------------
  398|       |		/* We need at least 6 bytes for file length here */
  399|      3|		return -1;
  400|      3|	}
  401|     68|	file_size = hextoint((char*)EFdata, tlv_length_size);
  402|     68|	if (EFdata_len < (file_size + tlv_length_size)) {
  ------------------
  |  Branch (402:6): [True: 14, False: 54]
  ------------------
  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|     14|		return -1;
  408|     14|	}
  409|     54|	file = (char*)&EFdata[tlv_length_size];
  410|       |
  411|     54|	enum {
  412|     54|		f_issuer_code = 0,
  413|     54|		f_issuing_date,
  414|     54|		f_expiry_date,
  415|     54|		f_last_name,
  416|     54|		f_first_name,
  417|     54|		f_birth_date,
  418|     54|		f_sex,
  419|     54|		f_height,
  420|     54|		f_codice_fiscale,
  421|     54|		f_citizenship_code,
  422|     54|		f_birth_township_code,
  423|     54|		f_birth_country,
  424|     54|		f_birth_certificate,
  425|     54|		f_residence_township_code,
  426|     54|		f_residence_address,
  427|     54|		f_expat_notes
  428|     54|	};
  429|       |
  430|       |	/* Read the fields up to f_first_name */
  431|     54|	struct {
  432|     54|		int len;
  433|     54|		char value[256];
  434|     54|	} fields[f_first_name+1];
  435|     54|	int i=0; /* offset inside the file */
  436|     54|	int f; /* field number */
  437|       |
  438|     54|	if (file_size < 0)
  ------------------
  |  Branch (438:6): [True: 46, False: 8]
  ------------------
  439|     46|		return -1;
  440|       |
  441|       |	/*
  442|       |	 * This shouldn't happen, but let us be protected against wrong
  443|       |	 * or malicious cards
  444|       |	 */
  445|      8|	if(file_size > (int)EF_personaldata_maxlen - (int)tlv_length_size)
  ------------------
  |  Branch (445:5): [True: 0, False: 8]
  ------------------
  446|      0|		file_size = EF_personaldata_maxlen - tlv_length_size;
  447|       |
  448|       |
  449|      8|	memset(fields, 0, sizeof(fields));
  450|       |
  451|     21|	for(f=0; f<f_first_name+1; f++) {
  ------------------
  |  Branch (451:11): [True: 20, False: 1]
  ------------------
  452|     20|		int field_size;
  453|       |
  454|       |		/* Don't read beyond the allocated buffer */
  455|     20|		if(i+2 > file_size)
  ------------------
  |  Branch (455:6): [True: 3, False: 17]
  ------------------
  456|      3|			return -1;
  457|     17|		field_size = hextoint((char*) &file[i], 2);
  458|     17|		i += 2;
  459|       |
  460|     17|		if (field_size < 0
  ------------------
  |  Branch (460:7): [True: 2, False: 15]
  ------------------
  461|     15|				|| i + field_size > file_size
  ------------------
  |  Branch (461:8): [True: 2, False: 13]
  ------------------
  462|     13|				|| field_size >= (int)sizeof(fields[f].value))
  ------------------
  |  Branch (462:8): [True: 0, False: 13]
  ------------------
  463|      4|			return -1;
  464|       |
  465|     13|		fields[f].len = field_size;
  466|     13|		strncpy(fields[f].value, &file[i], field_size);
  467|     13|		fields[f].value[field_size] = '\0';
  468|     13|		i += field_size;
  469|     13|	}
  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|     85|{
  371|     85|	char hex[16];
  372|     85|	char *end;
  373|     85|	int res;
  374|       |
  375|     85|	if(len >= sizeof(hex))
  ------------------
  |  Branch (375:5): [True: 0, False: 85]
  ------------------
  376|      0|		return -1;
  377|     85|	strncpy(hex, src, len);
  378|     85|	hex[len] = '\0';
  379|     85|	res = (int)strtol(hex, &end, 0x10);
  380|     85|	if(end != (char*)&hex[len])
  ------------------
  |  Branch (380:5): [True: 48, False: 37]
  ------------------
  381|     48|		return -1;
  382|     37|	return res;
  383|     85|}
pkcs15-itacns.c:itacns_check_and_add_keyset:
  654|    255|{
  655|    255|	int r;
  656|    255|	sc_path_t path;
  657|    255|	sc_pkcs15_id_t cert_id;
  658|    255|	int ext_info_ok;
  659|    255|	int ku = 0, xku = 0;
  660|    255|	size_t modulus_len = 0;
  661|    255|	int pubkey_usage_flags = 0, prkey_usage_flags = 0;
  662|       |
  663|    255|	cert_id.len = 1;
  664|    255|	cert_id.value[0] = sec_env;
  665|    255|	*found_certificates = 0;
  666|       |
  667|       |	/* Certificate */
  668|    255|	if (!cert_path) {
  ------------------
  |  Branch (668:6): [True: 0, False: 255]
  ------------------
  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|    255|	sc_format_path(cert_path, &path);
  675|    255|	r = sc_select_file(p15card->card, &path, NULL);
  676|    255|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    255|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (676:6): [True: 14, False: 241]
  ------------------
  677|     14|		return 0;
  678|    241|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    241|#define SC_SUCCESS				0
  ------------------
  |  Branch (678:6): [True: 69, False: 172]
  ------------------
  679|     69|		sc_log(p15card->card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  680|     69|			"Could not find certificate for %s", label);
  681|     69|		return r;
  682|     69|	}
  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|    172|	if (cert_offset) {
  ------------------
  |  Branch (689:6): [True: 51, False: 121]
  ------------------
  690|     51|		u8 certlen[3];
  691|     51|		memset(certlen, 0, sizeof certlen);
  692|     51|		r = loadFile(p15card, &path, certlen, sizeof(certlen));
  693|     51|		LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     51|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     51|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     51|	int _ret = (r); \
  |  |  |  |  168|     51|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|     43|			"Could not read certificate file");
  695|     43|		if (r < 3)
  ------------------
  |  Branch (695:7): [True: 1, False: 42]
  ------------------
  696|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  697|     42|		path.index = (int)cert_offset;
  698|     42|		path.count = (certlen[1] << 8) + certlen[2];
  699|       |		/* If those bytes are 00, then we are probably dealing with an
  700|       |		 * empty file. */
  701|     42|		if (path.count == 0)
  ------------------
  |  Branch (701:7): [True: 1, False: 41]
  ------------------
  702|      1|			return 0;
  703|     42|	}
  704|       |
  705|    162|	r = itacns_add_cert(p15card, SC_PKCS15_TYPE_CERT_X509, 0,
  ------------------
  |  |  439|    162|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  706|    162|		&path, &cert_id, label, 0, &ext_info_ok, &ku, &xku, &modulus_len);
  707|    162|	if (r == SC_ERROR_INVALID_ASN1_OBJECT)
  ------------------
  |  |   82|    162|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (707:6): [True: 114, False: 48]
  ------------------
  708|    114|		return 0;
  709|     48|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  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: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|} 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|    162|{
  190|    162|	int r;
  191|       |	/* const char *label = "Certificate"; */
  192|    162|	sc_pkcs15_cert_info_t info;
  193|    162|	sc_pkcs15_object_t    obj;
  194|    162|#ifdef ENABLE_OPENSSL
  195|    162|	X509 *x509;
  196|    162|	sc_pkcs15_cert_t *cert;
  197|    162|	int private_obj;
  198|    162|#endif
  199|       |
  200|    162|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    162|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    162|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    162|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 162]
  |  |  ------------------
  ------------------
  201|       |
  202|    162|	if(type != SC_PKCS15_TYPE_CERT_X509) {
  ------------------
  |  |  439|    162|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (202:5): [True: 0, False: 162]
  ------------------
  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|    162|	*ext_info_ok = 0;
  209|       |
  210|       |
  211|    162|	memset(&info, 0, sizeof(info));
  212|    162|	memset(&obj,  0, sizeof(obj));
  213|       |
  214|    162|	info.id                = *id;
  215|    162|	info.authority         = authority;
  216|    162|	if (path)
  ------------------
  |  Branch (216:6): [True: 162, False: 0]
  ------------------
  217|    162|		info.path = *path;
  218|       |
  219|    162|	strlcpy(obj.label, label, sizeof(obj.label));
  ------------------
  |  |   43|    162|#define strlcpy _strlcpy
  ------------------
  220|       |
  221|       |	/* If we have OpenSSL, read keyUsage */
  222|    162|#ifdef ENABLE_OPENSSL
  223|    162|	private_obj = obj_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    162|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  224|    162|	r = sc_pkcs15_read_certificate(p15card, &info, private_obj, &cert);
  225|    162|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|    162|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    162|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    162|	int _ret = (r); \
  |  |  |  |  168|    162|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 162, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    162|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    162|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    162|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    162|		return _ret; \
  |  |  |  |  172|    162|	} \
  |  |  |  |  173|    162|} 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|  3.81k|{
  249|  3.81k|	if (p15card->card->type != SC_CARD_TYPE_JPKI_BASE)
  ------------------
  |  Branch (249:6): [True: 3.71k, False: 100]
  ------------------
  250|  3.71k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.71k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  251|    100|	return sc_pkcs15emu_jpki_init(p15card);
  252|  3.81k|}
pkcs15-jpki.c:sc_pkcs15emu_jpki_init:
   38|    100|{
   39|    100|	sc_card_t *card = p15card->card;
   40|    100|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|    100|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   41|    100|	int i, rc;
   42|       |
   43|    100|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|    100|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    100|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    100|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    100|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|       |
   45|    100|	set_string(&p15card->tokeninfo->label, "JPKI");
   46|    100|	set_string(&p15card->tokeninfo->manufacturer_id, "JPKI");
   47|       |	/* set dummy until we found serial number */
   48|    100|	set_string(&p15card->tokeninfo->serial_number, "00000000");
   49|       |
   50|       |	/* Select application directory */
   51|    100|	if (drvdata->selected != SELECT_JPKI_AP) {
  ------------------
  |  |   25|    100|#define SELECT_JPKI_AP 1
  ------------------
  |  Branch (51:6): [True: 100, False: 0]
  ------------------
   52|    100|		rc = jpki_select_ap(card);
   53|    100|		LOG_TEST_RET(card->ctx, rc, "select AP failed");
  ------------------
  |  |  174|    100|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    100|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    100|	int _ret = (r); \
  |  |  |  |  168|    100|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 83]
  |  |  |  |  ------------------
  |  |  |  |  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|    100|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 83]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   54|     83|		drvdata->selected = SELECT_JPKI_AP;
  ------------------
  |  |   25|     83|#define SELECT_JPKI_AP 1
  ------------------
   55|     83|	}
   56|       |
   57|       |	/* add certificates */
   58|    415|	for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (58:14): [True: 332, False: 83]
  ------------------
   59|    332|		static const char *jpki_cert_names[4] = {
   60|    332|			"User Authentication Certificate",
   61|    332|			"Digital Signature Certificate",
   62|    332|			"User Authentication Certificate CA",
   63|    332|			"Digital Signature Certificate CA"
   64|    332|		};
   65|    332|		static char const *jpki_cert_paths[4] = {
   66|    332|			"000A",
   67|    332|			"0001",
   68|    332|			"000B",
   69|    332|			"0002"
   70|    332|		};
   71|    332|		static int jpki_cert_ids[4] = { 1, 2, 3, 4 };
   72|    332|		static int jpki_cert_flags[4] = {
   73|    332|			0,
   74|    332|			SC_PKCS15_CO_FLAG_PRIVATE,
  ------------------
  |  |   50|    332|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   75|    332|			0,
   76|    332|			0,
   77|    332|		};
   78|    332|		static int jpki_cert_auth_id[4] = { 0, 2, 0, 0 };
   79|    332|		static int jpki_cert_authority[4] = {0, 0, 1, 1};
   80|    332|		struct sc_pkcs15_cert_info cert_info;
   81|    332|		struct sc_pkcs15_object cert_obj;
   82|    332|		memset(&cert_info, 0, sizeof(cert_info));
   83|    332|		memset(&cert_obj, 0, sizeof(cert_obj));
   84|       |
   85|    332|		cert_info.id.value[0] = jpki_cert_ids[i];
   86|    332|		cert_info.id.len = 1;
   87|    332|		sc_format_path(jpki_cert_paths[i], &cert_info.path);
   88|    332|		cert_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    332|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
   89|       |
   90|    332|		strlcpy(cert_obj.label, jpki_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|    332|#define strlcpy _strlcpy
  ------------------
   91|    332|		cert_info.authority = jpki_cert_authority[i];
   92|    332|		cert_obj.flags = jpki_cert_flags[i];
   93|    332|		if (jpki_cert_auth_id[i]) {
  ------------------
  |  Branch (93:7): [True: 83, False: 249]
  ------------------
   94|     83|			cert_obj.auth_id.len = 1;
   95|     83|			cert_obj.auth_id.value[0] = jpki_cert_auth_id[i];
   96|     83|		}
   97|    332|		rc = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
   98|    332|		if (rc < 0) {
  ------------------
  |  Branch (98:7): [True: 0, False: 332]
  ------------------
   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|    332|	}
  104|       |
  105|       |	/* add pins */
  106|    130|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (106:14): [True: 111, False: 19]
  ------------------
  107|    111|		static const char *jpki_pin_names[2] = {
  108|    111|			"User Authentication PIN",
  109|    111|			"Digital Signature PIN"
  110|    111|		};
  111|    111|		static const int jpki_pin_min[2] = { 4, 6 };
  112|    111|		static const int jpki_pin_max[2] = { 4, 16 };
  113|    111|		static const int jpki_pin_ref[2] = { 1, 2 };
  114|    111|		static const int jpki_pin_authid[2] = { 1, 2 };
  115|    111|		static const int jpki_pin_flags[2] = {
  116|    111|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    111|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  117|    111|			SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    111|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  118|    111|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    111|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  119|    111|			SC_PKCS15_PIN_FLAG_LOCAL
  ------------------
  |  |   55|    111|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  120|    111|		};
  121|    111|		static const int jpki_pin_max_tries[2] = {
  122|    111|			JPKI_AUTH_PIN_MAX_TRIES,
  ------------------
  |  |   30|    111|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  123|    111|			JPKI_SIGN_PIN_MAX_TRIES
  ------------------
  |  |   34|    111|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  124|    111|		};
  125|       |
  126|    111|		struct sc_pkcs15_auth_info pin_info;
  127|    111|		struct sc_pkcs15_object pin_obj;
  128|    111|		struct sc_pin_cmd_data pin_cmd_data;
  129|    111|		memset(&pin_info, 0, sizeof (pin_info));
  130|    111|		memset(&pin_obj, 0, sizeof (pin_obj));
  131|    111|		memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  132|       |
  133|    111|		pin_info.auth_id.len = 1;
  134|    111|		pin_info.auth_id.value[0] = jpki_pin_authid[i];
  135|    111|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    111|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  136|    111|		pin_info.attrs.pin.reference = jpki_pin_ref[i];
  137|    111|		pin_info.attrs.pin.flags = jpki_pin_flags[i];
  138|    111|		pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    111|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  139|    111|		pin_info.attrs.pin.min_length = jpki_pin_min[i];
  140|    111|		pin_info.attrs.pin.stored_length = 0;
  141|    111|		pin_info.attrs.pin.max_length = jpki_pin_max[i];
  142|    111|		pin_info.attrs.pin.pad_char = '\0';
  143|    111|		pin_info.max_tries = jpki_pin_max_tries[i];
  144|    111|		pin_info.tries_left = -1;
  145|    111|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    111|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  146|       |
  147|    111|		pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    111|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  148|    111|		pin_cmd_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|    111|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  149|    111|		pin_cmd_data.pin_reference = jpki_pin_ref[i];
  150|    111|		rc = sc_pin_cmd(card, &pin_cmd_data);
  151|    111|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  152|    111|		LOG_TEST_RET(card->ctx, rc, "sc_pin_cmd failed");
  ------------------
  |  |  174|    111|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    111|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    111|	int _ret = (r); \
  |  |  |  |  168|    111|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 64, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  169|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     64|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     64|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     64|		return _ret; \
  |  |  |  |  172|     64|	} \
  |  |  |  |  173|    111|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  153|     47|		strlcpy(pin_obj.label, jpki_pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|     47|#define strlcpy _strlcpy
  ------------------
  154|     47|		pin_obj.flags = jpki_pin_flags[i];
  155|       |
  156|     47|		rc = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  157|     47|		if (rc < 0) {
  ------------------
  |  Branch (157:7): [True: 0, False: 47]
  ------------------
  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|     47|	}
  162|       |
  163|       |	/* add private keys */
  164|     57|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (164:14): [True: 38, False: 19]
  ------------------
  165|     38|		static int prkey_pin[2] = { 1, 2 };
  166|     38|		static int prkey_usage[2] = {
  167|     38|			SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|     38|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  168|     38|			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  307|     38|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  314|     38|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  169|     38|		};
  170|     38|		static const char *prkey_name[2] = {
  171|     38|			"User Authentication Key",
  172|     38|			"Digital Signature Key"
  173|     38|		};
  174|     38|		static int prkey_user_consent[2] = { 0, 1 };
  175|     38|		struct sc_pkcs15_prkey_info prkey_info;
  176|     38|		struct sc_pkcs15_object prkey_obj;
  177|       |
  178|     38|		memset(&prkey_info, 0, sizeof (prkey_info));
  179|     38|		memset(&prkey_obj, 0, sizeof (prkey_obj));
  180|       |
  181|     38|		prkey_info.id.len = 1;
  182|     38|		prkey_info.id.value[0] = prkey_pin[i];
  183|     38|		prkey_info.usage = prkey_usage[i];
  184|     38|		prkey_info.native = 1;
  185|     38|		prkey_info.key_reference = i + 1;
  186|     38|		prkey_info.modulus_length = 2048;
  187|       |
  188|     38|		strlcpy(prkey_obj.label, prkey_name[i], sizeof (prkey_obj.label));
  ------------------
  |  |   43|     38|#define strlcpy _strlcpy
  ------------------
  189|     38|		prkey_obj.auth_id.len = 1;
  190|     38|		prkey_obj.auth_id.value[0] = prkey_pin[i];
  191|     38|		prkey_obj.user_consent = prkey_user_consent[i];
  192|     38|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     38|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  193|       |
  194|     38|		rc = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  195|     38|		if (rc < 0) {
  ------------------
  |  Branch (195:7): [True: 0, False: 38]
  ------------------
  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|     38|	}
  200|       |
  201|       |	/* add public keys */
  202|     57|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (202:14): [True: 38, False: 19]
  ------------------
  203|     38|		static int pubkey_id[2] = { 1, 2 };
  204|     38|		static const char *jpki_pubkey_names[2] = {
  205|     38|			"User Authentication Public Key",
  206|     38|			"Digital Signature Public Key"
  207|     38|		};
  208|     38|		static int jpki_pubkey_flags[2] = {
  209|     38|				0,
  210|     38|				SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     38|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  211|     38|		static int jpki_pubkey_auth_id[2] = {0, 2};
  212|     38|		struct sc_pkcs15_pubkey_info pubkey_info;
  213|     38|		struct sc_pkcs15_object pubkey_obj;
  214|     38|		static char const *jpki_pubkey_paths[2] = {
  215|     38|			"000A",
  216|     38|			"0001"
  217|     38|		};
  218|       |
  219|     38|		memset(&pubkey_info, 0, sizeof (pubkey_info));
  220|     38|		memset(&pubkey_obj, 0, sizeof (pubkey_obj));
  221|       |
  222|     38|		strlcpy(pubkey_obj.label, jpki_pubkey_names[i], sizeof (pubkey_obj.label));
  ------------------
  |  |   43|     38|#define strlcpy _strlcpy
  ------------------
  223|     38|		pubkey_info.id.len = 1;
  224|     38|		pubkey_info.id.value[0] = pubkey_id[i];
  225|     38|		pubkey_info.native = 1;
  226|     38|		pubkey_info.key_reference = i + 1;
  227|       |
  228|     38|		sc_format_path(jpki_pubkey_paths[i], &pubkey_info.path);
  229|     38|		pubkey_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     38|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  230|     38|		pubkey_obj.flags = jpki_pubkey_flags[i];
  231|     38|		if (jpki_pubkey_auth_id[i]) {
  ------------------
  |  Branch (231:7): [True: 19, False: 19]
  ------------------
  232|     19|			pubkey_obj.auth_id.len = 1;
  233|     19|			pubkey_obj.auth_id.value[0] = jpki_pubkey_auth_id[i];
  234|     19|		}
  235|       |
  236|     38|		rc = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  237|     38|		if (rc < 0) {
  ------------------
  |  Branch (237:7): [True: 0, False: 38]
  ------------------
  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|     38|	}
  242|     19|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     19|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     19|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     19|	int _ret = r; \
  |  |  |  |  155|     19|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     19|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     19|	return _ret; \
  |  |  |  |  163|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|     19|}

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

sc_pkcs15emu_nqapplet_init_ex:
  179|  3.42k|{
  180|  3.42k|	int rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  181|  3.42k|	sc_context_t *ctx;
  182|  3.42k|	sc_card_t *card;
  183|       |
  184|  3.42k|	if (!p15card || !p15card->card || !p15card->card->ctx) {
  ------------------
  |  Branch (184:6): [True: 0, False: 3.42k]
  |  Branch (184:18): [True: 0, False: 3.42k]
  |  Branch (184:36): [True: 0, False: 3.42k]
  ------------------
  185|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  186|      0|	}
  187|       |
  188|  3.42k|	card = p15card->card;
  189|  3.42k|	ctx = card->ctx;
  190|       |
  191|  3.42k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  3.42k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.42k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.42k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.42k]
  |  |  ------------------
  ------------------
  192|       |
  193|  3.42k|	if (card->type < SC_CARD_TYPE_NQ_APPLET || card->type > SC_CARD_TYPE_NQ_APPLET_RFID) {
  ------------------
  |  Branch (193:6): [True: 3.42k, False: 0]
  |  Branch (193:45): [True: 0, False: 0]
  ------------------
  194|  3.42k|		sc_log(p15card->card->ctx, "Unsupported card type: %d", card->type);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  195|  3.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  196|  3.42k|	}
  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|  4.01k|{
 1161|  4.01k|	int rv;
 1162|       |
 1163|  4.01k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  4.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  4.01k|	rv = oberthur_detect_card(p15card);
 1165|  4.01k|	if (!rv)
  ------------------
  |  Branch (1165:6): [True: 0, False: 4.01k]
  ------------------
 1166|      0|		rv = sc_pkcs15emu_oberthur_init(p15card);
 1167|       |
 1168|  4.01k|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|  4.01k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.01k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.01k|	int _ret = r; \
  |  |  |  |  155|  4.01k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.01k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.01k|	return _ret; \
  |  |  |  |  163|  4.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|  4.01k|}
pkcs15-oberthur.c:oberthur_detect_card:
 1148|  4.01k|{
 1149|  4.01k|	struct sc_card *card = p15card->card;
 1150|       |
 1151|  4.01k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.01k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  ------------------
  ------------------
 1152|  4.01k|	if (p15card->card->type != SC_CARD_TYPE_OBERTHUR_64K)
  ------------------
  |  Branch (1152:6): [True: 4.01k, False: 0]
  ------------------
 1153|  4.01k|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  4.01k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.01k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.01k|	int _ret = r; \
  |  |  |  |  155|  4.01k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.01k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.01k|	return _ret; \
  |  |  |  |  163|  4.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1154|      0|	LOG_FUNC_RETURN(p15card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1155|      0|}

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

sc_pkcs15_decode_aodf_entry:
   86|      9|{
   87|      9|	sc_context_t *ctx = p15card->card->ctx;
   88|      9|	struct sc_pkcs15_auth_info info;
   89|      9|	int r;
   90|      9|	size_t flags_len = sizeof(info.attrs.pin.flags);
   91|      9|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   92|      9|	size_t padchar_len = 1;
   93|      9|	struct sc_asn1_entry asn1_com_ao_attr[2];
   94|      9|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   95|      9|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   96|      9|	struct sc_asn1_entry asn1_auth_type[2];
   97|      9|	struct sc_asn1_entry asn1_auth_type_choice[4];
   98|      9|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   99|      9|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
  100|       |
  101|      9|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|      9|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      9|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      9|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9]
  |  |  ------------------
  ------------------
  102|       |
  103|      9|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  104|      9|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  105|       |
  106|      9|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  107|       |
  108|      9|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  109|      9|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  110|       |
  111|      9|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  112|      9|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  113|       |
  114|      9|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  115|      9|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  116|      9|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  117|       |
  118|       |	/* pinAttributes */
  119|      9|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  120|      9|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  121|      9|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  122|      9|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  123|      9|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  124|      9|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  125|      9|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  126|      9|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  127|       |
  128|       |	/* authKeyAttributes */
  129|      9|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  130|      9|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  131|      9|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  132|       |
  133|       |	/* We don't support lastPinChange yet. */
  134|      9|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  135|       |
  136|      9|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  137|       |
  138|       |	/* Fill in defaults */
  139|      9|	memset(&info, 0, sizeof(info));
  140|      9|	info.tries_left = -1;
  141|      9|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      9|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  142|       |
  143|      9|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  144|      9|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      9|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (144:6): [True: 6, False: 3]
  ------------------
  145|      6|		return r;
  146|      3|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|      1|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      1|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (148:6): [True: 0, False: 1]
  ------------------
  149|      0|		sc_log(ctx, "AuthType: 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__
  |  |  ------------------
  ------------------
  150|      0|		obj->type = SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|      0|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  151|      0|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  152|      0|		info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  153|       |
  154|      0|		if (info.attrs.pin.max_length == 0) {
  ------------------
  |  Branch (154:7): [True: 0, False: 0]
  ------------------
  155|      0|			if (p15card->card->max_pin_len != 0)
  ------------------
  |  Branch (155:8): [True: 0, False: 0]
  ------------------
  156|      0|				info.attrs.pin.max_length = p15card->card->max_pin_len;
  157|      0|			else if (info.attrs.pin.stored_length != 0)
  ------------------
  |  Branch (157:13): [True: 0, False: 0]
  ------------------
  158|      0|				info.attrs.pin.max_length = info.attrs.pin.type != SC_PKCS15_PIN_TYPE_BCD ?
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (158:33): [True: 0, False: 0]
  ------------------
  159|      0|					info.attrs.pin.stored_length : 2 * info.attrs.pin.stored_length;
  160|      0|			else
  161|      0|				info.attrs.pin.max_length = 8; /* shouldn't happen */
  162|      0|		}
  163|       |
  164|       |		/* OpenSC 0.11.4 and older encoded "pinReference" as a negative
  165|       |		   value. Fixed in 0.11.5 we need to add a hack, so old cards
  166|       |		   continue to work.
  167|       |		   The same invalid encoding has some models of the proprietary PKCS#15 cards.
  168|       |		*/
  169|      0|		if (info.attrs.pin.reference < 0)
  ------------------
  |  Branch (169:7): [True: 0, False: 0]
  ------------------
  170|      0|			info.attrs.pin.reference += 256;
  171|       |
  172|      0|		if (info.attrs.pin.flags & SC_PKCS15_PIN_FLAG_LOCAL)   {
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  |  Branch (172:7): [True: 0, False: 0]
  ------------------
  173|       |			/* In OpenSC pkcs#15 framework 'path' is mandatory for the 'Local' PINs.
  174|       |			 * If 'path' do not present in PinAttributes, derive it from the PKCS#15 context. */
  175|      0|			if (!info.path.len)   {
  ------------------
  |  Branch (175:8): [True: 0, False: 0]
  ------------------
  176|       |				/* Give priority to AID defined in the application DDO */
  177|      0|				if (p15card->app && p15card->app->ddo.aid.len)
  ------------------
  |  Branch (177:9): [True: 0, False: 0]
  |  Branch (177:25): [True: 0, False: 0]
  ------------------
  178|      0|					info.path.aid = p15card->app->ddo.aid;
  179|      0|				else if (p15card->file_app && p15card->file_app->path.len)
  ------------------
  |  Branch (179:14): [True: 0, False: 0]
  |  Branch (179:35): [True: 0, False: 0]
  ------------------
  180|      0|					info.path = p15card->file_app->path;
  181|      0|				else
  182|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  183|      0|			}
  184|      0|		}
  185|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  186|      0|	}
  187|      1|	else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      1|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (187:11): [True: 1, False: 0]
  ------------------
  188|      1|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|      1|	}
  190|      0|	else if (asn1_auth_type_choice[2].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (190:11): [True: 0, False: 0]
  ------------------
  191|      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__
  |  |  ------------------
  ------------------
  192|      0|		obj->type = SC_PKCS15_TYPE_AUTH_AUTHKEY;
  ------------------
  |  |  447|      0|#define SC_PKCS15_TYPE_AUTH_AUTHKEY		0x603
  ------------------
  193|      0|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY;
  ------------------
  |  |   96|      0|#define SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY		2
  ------------------
  194|      0|		info.auth_method = SC_AC_AUT;
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  195|      0|		if (!(asn1_authkey_attr[0].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (195:7): [True: 0, False: 0]
  ------------------
  196|      0|			info.attrs.authkey.derived = 1;
  197|      0|	}
  198|      0|	else   {
  199|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|      0|	}
  201|       |
  202|      0|	obj->data = malloc(sizeof(info));
  203|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 0]
  ------------------
  204|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      0|	memcpy(obj->data, &info, sizeof(info));
  206|       |
  207|      0|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_SUCCESS);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  208|      0|}
sc_pkcs15_verify_pin:
  299|     22|{
  300|     22|	struct sc_context *ctx = p15card->card->ctx;
  301|     22|	struct sc_pkcs15_auth_info *auth_info;
  302|     22|	int r;
  303|       |
  304|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|     22|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (306:6): [True: 0, False: 22]
  |  Branch (306:18): [True: 0, False: 22]
  ------------------
  307|     22|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     22|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  309|       |
  310|       |	/* Check the provided pin matches pin requirements */
  311|     22|	r = _validate_pin(p15card, auth_info, pinlen);
  312|       |
  313|     22|	if (r)
  ------------------
  |  Branch (313:6): [True: 4, False: 18]
  ------------------
  314|     22|		LOG_FUNC_RETURN(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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|       |
  316|     18|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  317|       |
  318|     18|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (318:6): [True: 15, False: 3]
  ------------------
  319|     15|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  320|       |
  321|     18|	LOG_FUNC_RETURN(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|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|     18|}
_sc_pkcs15_verify_pin:
  328|     18|{
  329|     18|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  330|     18|			pinlen, NULL, NULL);
  331|     18|}
sc_pkcs15_verify_pin_with_session_pin:
  344|    115|{
  345|    115|	struct sc_context *ctx = p15card->card->ctx;
  346|    115|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  347|    115|	int r;
  348|    115|	sc_card_t *card;
  349|    115|	struct sc_pin_cmd_data data;
  350|       |
  351|    115|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|    115|	sc_log(ctx, "PIN(type:%X; method:%X; value(%p:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  353|    115|			auth_info->auth_type, auth_info->auth_method, pincode, pinlen);
  354|    115|	card = p15card->card;
  355|       |
  356|    115|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|    115|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (356:6): [True: 7, False: 108]
  ------------------
  357|      7|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  358|      7|				NOTIFY_PIN_BAD);
  359|      7|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_LENGTH, "Invalid PIN size");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|      7|	}
  361|       |
  362|       |	/* Initialize arguments */
  363|    108|	memset(&data, 0, sizeof(data));
  364|    108|	data.pin_type = auth_info->auth_method;
  365|       |
  366|    108|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    108|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (366:6): [True: 108, False: 0]
  ------------------
  367|    108|		data.pin_reference = auth_info->attrs.pin.reference;
  368|    108|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  369|    108|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  370|    108|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  371|    108|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  372|    108|		data.pin1.data = pincode;
  373|    108|		data.pin1.len = pinlen;
  374|       |
  375|    108|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    108|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (375:7): [True: 70, False: 38]
  ------------------
  376|     70|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     70|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  377|       |
  378|    108|		switch (auth_info->attrs.pin.type) {
  379|      0|		case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (379:3): [True: 0, False: 108]
  ------------------
  380|      0|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  381|      0|			break;
  382|    108|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    108|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (382:3): [True: 108, False: 0]
  ------------------
  383|    108|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    108|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  384|    108|			break;
  385|      0|		default:
  ------------------
  |  Branch (385:3): [True: 0, False: 108]
  ------------------
  386|       |			/* assume/hope the card driver knows how to encode the pin */
  387|      0|			data.pin1.encoding = 0;
  388|    108|		}
  389|    108|	}
  390|      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 (390:11): [True: 0, False: 0]
  ------------------
  391|      0|		struct sc_pkcs15_object *skey_obj = NULL;
  392|      0|		struct sc_pkcs15_id *skey_id =  &auth_info->attrs.authkey.skey_id;
  393|      0|		struct sc_pkcs15_skey_info *skey_info = NULL;
  394|       |
  395|      0|		r = sc_pkcs15_find_skey_by_id(p15card, skey_id, &skey_obj);
  396|      0|		if (r)   {
  ------------------
  |  Branch (396:7): [True: 0, False: 0]
  ------------------
  397|      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__
  |  |  ------------------
  ------------------
  398|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  399|      0|		}
  400|      0|		skey_info = (struct sc_pkcs15_skey_info *)skey_obj->data;
  401|       |
  402|      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__
  |  |  ------------------
  ------------------
  403|      0|		data.pin_reference = skey_info->key_reference;
  404|      0|	}
  405|       |
  406|    108|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    216|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (406:7): [True: 0, False: 108]
  ------------------
  407|    108|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|    108|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (407:8): [True: 0, False: 108]
  ------------------
  408|      0|		if (!pincode && !pinlen)
  ------------------
  |  Branch (408:7): [True: 0, False: 0]
  |  Branch (408:19): [True: 0, False: 0]
  ------------------
  409|      0|			data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  410|       |
  411|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN)
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (411:7): [True: 0, False: 0]
  ------------------
  412|      0|			data.pin1.prompt = "Please enter SO PIN";
  413|      0|		else
  414|      0|			data.pin1.prompt = "Please enter PIN";
  415|      0|	}
  416|       |
  417|    108|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  563|    216|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (417:6): [True: 0, False: 108]
  |  Branch (417:46): [True: 0, False: 0]
  |  Branch (417:60): [True: 0, False: 0]
  ------------------
  418|       |		/* session pin is requested and supported with standard verification*/
  419|      0|		data.cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  420|      0|		memcpy(&data.pin2, &data.pin1, sizeof (data.pin1));
  421|      0|		data.pin2.data = sessionpin;
  422|      0|		data.pin2.len = *sessionpinlen;
  423|    108|	} else {
  424|       |		/* perform a standard verify */
  425|    108|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    108|#define SC_PIN_CMD_VERIFY	0
  ------------------
  426|    108|		if (sessionpinlen)
  ------------------
  |  Branch (426:7): [True: 90, False: 18]
  ------------------
  427|     90|			*sessionpinlen = 0;
  428|    108|	}
  429|       |
  430|    108|	r = sc_lock(card);
  431|    108|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  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: 0, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  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|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 108]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|       |	/* the path in the pin object is optional */
  434|    108|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (434:6): [True: 0, False: 108]
  |  Branch (434:35): [True: 13, False: 95]
  ------------------
  435|     13|		r = sc_select_file(card, &auth_info->path, NULL);
  436|     13|		if (r)
  ------------------
  |  Branch (436:7): [True: 2, False: 11]
  ------------------
  437|      2|			goto out;
  438|     13|	}
  439|       |
  440|    106|	r = sc_pin_cmd(card, &data);
  441|    106|	auth_info->tries_left = data.pin1.tries_left;
  442|    106|	sc_log(ctx, "PIN cmd result %i", r);
  ------------------
  |  |   71|    106|#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|    106|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    106|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:6): [True: 26, False: 80]
  ------------------
  444|     26|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  445|     26|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|     52|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (445:7): [True: 0, False: 26]
  |  Branch (445:49): [True: 0, False: 0]
  ------------------
  446|      0|			*sessionpinlen = data.pin2.len;
  447|      0|		}
  448|     80|	} else {
  449|     80|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  450|     80|				NOTIFY_PIN_BAD);
  451|     80|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    160|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (451:7): [True: 0, False: 80]
  |  Branch (451:49): [True: 0, False: 0]
  ------------------
  452|      0|			*sessionpinlen = 0;
  453|      0|		}
  454|     80|	}
  455|       |
  456|    106|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|    212|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (456:6): [True: 106, False: 0]
  ------------------
  457|    106|			&& auth_info->auth_method != SC_AC_SESSION) {
  ------------------
  |  |  159|    106|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (457:7): [True: 106, False: 0]
  ------------------
  458|    106|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  459|    106|				r == SC_SUCCESS ? NOTIFY_PIN_GOOD : NOTIFY_PIN_BAD);
  ------------------
  |  |   28|    106|#define SC_SUCCESS				0
  ------------------
  |  Branch (459:5): [True: 26, False: 80]
  ------------------
  460|    106|	}
  461|       |
  462|    108|out:
  463|    108|	sc_unlock(card);
  464|    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: 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|     82|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 82, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|    108|}
sc_pkcs15_change_pin:
  476|    205|{
  477|    205|	struct sc_context *ctx = p15card->card->ctx;
  478|    205|	struct sc_pin_cmd_data data;
  479|    205|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  480|    205|	struct sc_card *card;
  481|    205|	int r;
  482|       |
  483|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|    205|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    205|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (484:6): [True: 0, False: 205]
  ------------------
  485|    205|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  486|       |
  487|       |	/* make sure the pins are in valid range */
  488|    205|	r = _validate_pin(p15card, auth_info, oldpinlen);
  489|    205|	LOG_TEST_RET(ctx, r, "Old PIN value do not conform PIN policy");
  ------------------
  |  |  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: 16, False: 189]
  |  |  |  |  ------------------
  |  |  |  |  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|    205|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 189]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|       |
  491|    189|	r = _validate_pin(p15card, auth_info, newpinlen);
  492|    189|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  174|    189|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    189|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    189|	int _ret = (r); \
  |  |  |  |  168|    189|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 45, False: 144]
  |  |  |  |  ------------------
  |  |  |  |  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|    189|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 144]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  493|       |
  494|    144|	card = p15card->card;
  495|    144|	r = sc_lock(card);
  496|    144|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    144|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    144|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    144|	int _ret = (r); \
  |  |  |  |  168|    144|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 144]
  |  |  |  |  ------------------
  |  |  |  |  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|    144|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 144]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|       |	/* the path in the pin object is optional */
  498|    144|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (498:6): [True: 0, False: 144]
  |  Branch (498:35): [True: 13, False: 131]
  ------------------
  499|     13|		r = sc_select_file(card, &auth_info->path, NULL);
  500|     13|		if (r)
  ------------------
  |  Branch (500:7): [True: 4, False: 9]
  ------------------
  501|      4|			goto out;
  502|     13|	}
  503|       |
  504|       |	/* set pin_cmd data */
  505|    140|	memset(&data, 0, sizeof(data));
  506|    140|	data.cmd             = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  416|    140|#define SC_PIN_CMD_CHANGE	1
  ------------------
  507|    140|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    140|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  508|    140|	data.pin_reference   = auth_info->attrs.pin.reference;
  509|    140|	data.pin1.data       = oldpin;
  510|    140|	data.pin1.len        = oldpinlen;
  511|    140|	data.pin1.pad_char   = auth_info->attrs.pin.pad_char;
  512|    140|	data.pin1.min_length = auth_info->attrs.pin.min_length;
  513|    140|	data.pin1.max_length = auth_info->attrs.pin.max_length;
  514|    140|	data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  515|    140|	data.pin2.data       = newpin;
  516|    140|	data.pin2.len        = newpinlen;
  517|    140|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  518|    140|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  519|    140|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  520|    140|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  521|       |
  522|    140|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    140|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (522:6): [True: 136, False: 4]
  ------------------
  523|    136|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    136|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  524|       |
  525|    140|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (525:10): [True: 140, False: 0]
  ------------------
  526|      0|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (526:2): [True: 0, False: 140]
  ------------------
  527|      0|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  528|      0|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  529|      0|		break;
  530|    140|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    140|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (530:2): [True: 140, False: 0]
  ------------------
  531|    140|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    140|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  532|    140|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    140|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  533|    140|		break;
  534|    140|	}
  535|       |
  536|    140|	if((!oldpin || !newpin)
  ------------------
  |  Branch (536:6): [True: 0, False: 140]
  |  Branch (536:17): [True: 0, False: 140]
  ------------------
  537|      0|			&& (p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (537:8): [True: 0, False: 0]
  ------------------
  538|      0|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|      0|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (538:8): [True: 0, False: 0]
  ------------------
  539|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  540|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (540:7): [True: 0, False: 0]
  ------------------
  541|      0|			data.pin1.prompt = "Please enter SO PIN";
  542|      0|			data.pin2.prompt = "Please enter new SO PIN";
  543|      0|		}
  544|      0|		else {
  545|      0|			data.pin1.prompt = "Please enter PIN";
  546|      0|			data.pin2.prompt = "Please enter new PIN";
  547|      0|		}
  548|      0|	}
  549|       |
  550|    140|	r = sc_pin_cmd(card, &data);
  551|    140|	auth_info->tries_left = data.pin1.tries_left;
  552|    140|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    140|#define SC_SUCCESS				0
  ------------------
  |  Branch (552:6): [True: 9, False: 131]
  ------------------
  553|      9|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  554|       |
  555|    144|out:
  556|    144|	sc_unlock(card);
  557|    144|	return r;
  558|    140|}
sc_pkcs15_unblock_pin:
  567|     13|{
  568|     13|	struct sc_context *ctx = p15card->card->ctx;
  569|     13|	struct sc_pin_cmd_data data;
  570|     13|	struct sc_pkcs15_object *puk_obj;
  571|     13|	struct sc_pkcs15_auth_info *puk_info = NULL;
  572|     13|	int pukref = 0;
  573|     13|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  574|     13|	struct sc_card *card = p15card->card;
  575|     13|	int r;
  576|       |
  577|     13|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     13|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     13|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     13|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     13|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|     13|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|     13|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (578:6): [True: 0, False: 13]
  ------------------
  579|     13|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|       |	/* make sure the pins are in valid range */
  582|     13|	r = _validate_pin(p15card, auth_info, newpinlen);
  583|     13|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  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: 5, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|       |
  585|       |	/* get pin_info object of the puk (this is a little bit complicated
  586|       |	 * as we don't have the id of the puk (at least now))
  587|       |	 * note: for compatibility reasons we give no error if no puk object
  588|       |	 * is found */
  589|       |	/* first step: try to get the pkcs15 object of the puk */
  590|      8|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &pin_obj->auth_id, &puk_obj);
  591|      8|	if (r >= 0 && puk_obj) {
  ------------------
  |  Branch (591:6): [True: 2, False: 6]
  |  Branch (591:16): [True: 2, False: 0]
  ------------------
  592|       |		/* second step:  get the pkcs15 info object of the puk */
  593|      2|		puk_info = (struct sc_pkcs15_auth_info *)puk_obj->data;
  594|      2|		pukref = puk_info->attrs.pin.reference;
  595|      2|	}
  596|       |
  597|      8|	if (!puk_info) {
  ------------------
  |  Branch (597:6): [True: 6, False: 2]
  ------------------
  598|      6|		sc_log(ctx, "Unable to get puk object, using pin object instead!");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  599|      6|		puk_info = auth_info;
  600|      6|	}
  601|       |	/* make sure the puk is in valid range */
  602|      8|	r = _validate_pin(p15card, puk_info, puklen);
  603|      8|	LOG_TEST_RET(ctx, r, "PIN do not conforms PIN policy");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  604|       |
  605|       |	/*
  606|       |	 * With the current card driver interface we have no way of specifying different padding
  607|       |	 * flags for the PIN and the PUK. Therefore reject this case.
  608|       |	 */
  609|      7|	if ((auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING) !=
  ------------------
  |  |   59|      7|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (609:6): [True: 0, False: 7]
  ------------------
  610|      7|	    (puk_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)) {
  ------------------
  |  |   59|      7|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  611|      0|		LOG_TEST_RET(ctx, r, "Padding mismatch for PIN/PUK");
  ------------------
  |  |  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|      0|	}
  613|       |
  614|      7|	r = sc_lock(card);
  615|      7|	LOG_TEST_RET(ctx, r, "sc_lock() 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  616|       |
  617|       |	/* the path in the pin object is optional */
  618|      7|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (618:6): [True: 0, False: 7]
  |  Branch (618:35): [True: 5, False: 2]
  ------------------
  619|      5|		r = sc_select_file(card, &auth_info->path, NULL);
  620|      5|		if (r)
  ------------------
  |  Branch (620:7): [True: 2, False: 3]
  ------------------
  621|      2|			goto out;
  622|      5|	}
  623|       |
  624|       |	/* set pin_cmd data */
  625|      5|	memset(&data, 0, sizeof(data));
  626|      5|	data.cmd             = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  417|      5|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  627|      5|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|      5|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  628|      5|	data.pin_reference   = auth_info->attrs.pin.reference;
  629|      5|	data.puk_reference   = pukref;
  630|      5|	data.pin1.data       = puk;
  631|      5|	data.pin1.len        = puklen;
  632|      5|	data.pin1.pad_char   = puk_info->attrs.pin.pad_char;
  633|      5|	data.pin1.min_length = puk_info->attrs.pin.min_length;
  634|      5|	data.pin1.max_length = puk_info->attrs.pin.max_length;
  635|      5|	data.pin1.pad_length = puk_info->attrs.pin.stored_length;
  636|      5|	data.pin2.data       = newpin;
  637|      5|	data.pin2.len        = newpinlen;
  638|      5|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  639|      5|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  640|      5|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  641|      5|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  642|       |
  643|      5|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|      5|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (643:6): [True: 5, False: 0]
  ------------------
  644|      5|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      5|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  645|       |
  646|      5|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (646:10): [True: 5, False: 0]
  ------------------
  647|      0|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (647:2): [True: 0, False: 5]
  ------------------
  648|      0|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  649|      0|		break;
  650|      5|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|      5|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (650:2): [True: 5, False: 0]
  ------------------
  651|      5|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      5|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  652|      5|		break;
  653|      5|	}
  654|       |
  655|      5|	switch (puk_info->attrs.pin.type) {
  ------------------
  |  Branch (655:10): [True: 5, False: 0]
  ------------------
  656|      0|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (656:2): [True: 0, False: 5]
  ------------------
  657|      0|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  658|      0|		break;
  659|      5|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|      5|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (659:2): [True: 5, False: 0]
  ------------------
  660|      5|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      5|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  661|      5|		break;
  662|      5|	}
  663|       |
  664|      5|	if((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|     10|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (664:6): [True: 0, False: 5]
  ------------------
  665|      5|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|      5|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (665:8): [True: 0, False: 5]
  ------------------
  666|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  667|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (667:7): [True: 0, False: 0]
  ------------------
  668|      0|			data.pin1.prompt = "Please enter PUK";
  669|      0|			data.pin2.prompt = "Please enter new SO PIN";
  670|      0|		}
  671|      0|		else {
  672|      0|			data.pin1.prompt = "Please enter PUK";
  673|      0|			data.pin2.prompt = "Please enter new PIN";
  674|      0|		}
  675|      0|	}
  676|       |
  677|      5|	r = sc_pin_cmd(card, &data);
  678|      5|	auth_info->tries_left = data.pin1.tries_left;
  679|      5|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
  |  Branch (679:6): [True: 2, False: 3]
  ------------------
  680|      2|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  681|       |
  682|      7|out:
  683|      7|	sc_unlock(card);
  684|      7|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  685|      7|}
sc_pkcs15_get_pin_info:
  689|  1.03k|{
  690|  1.03k|	int r;
  691|  1.03k|	struct sc_pin_cmd_data data;
  692|  1.03k|	struct sc_card *card = p15card->card;
  693|  1.03k|	struct sc_context *ctx = card->ctx;
  694|  1.03k|	struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) pin_obj->data;
  695|       |
  696|  1.03k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.03k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.03k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|  1.03k|	r = sc_lock(card);
  699|  1.03k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.03k|#define SC_SUCCESS				0
  ------------------
  |  Branch (699:6): [True: 0, False: 1.03k]
  ------------------
  700|      0|		return r;
  701|       |
  702|  1.03k|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  1.03k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (702:6): [True: 0, False: 1.03k]
  ------------------
  703|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|		goto out;
  705|      0|	}
  706|       |
  707|       |	/* the path in the pin object is optional */
  708|  1.03k|	if ((pin_info->path.len > 0) || ((pin_info->path.aid.len > 0))) {
  ------------------
  |  Branch (708:6): [True: 0, False: 1.03k]
  |  Branch (708:34): [True: 33, False: 1.00k]
  ------------------
  709|     33|		r = sc_select_file(card, &pin_info->path, NULL);
  710|     33|		if (r)
  ------------------
  |  Branch (710:7): [True: 26, False: 7]
  ------------------
  711|     26|			goto out;
  712|     33|	}
  713|       |
  714|       |	/* Try to update PIN info from card */
  715|  1.01k|	memset(&data, 0, sizeof(data));
  716|  1.01k|	data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|  1.01k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  717|  1.01k|	data.pin_type = pin_info->auth_method;
  718|  1.01k|	data.pin_reference = pin_info->attrs.pin.reference;
  719|       |
  720|  1.01k|	r = sc_pin_cmd(card, &data);
  721|  1.01k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.01k|#define SC_SUCCESS				0
  ------------------
  |  Branch (721:6): [True: 113, False: 897]
  ------------------
  722|    113|		if (data.pin1.max_tries > 0)
  ------------------
  |  Branch (722:7): [True: 0, False: 113]
  ------------------
  723|      0|			pin_info->max_tries = data.pin1.max_tries;
  724|    113|		pin_info->tries_left = data.pin1.tries_left;
  725|    113|		pin_info->logged_in = data.pin1.logged_in;
  726|    113|	}
  727|       |
  728|  1.03k|out:
  729|  1.03k|	sc_unlock(card);
  730|  1.03k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  1.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.03k|	int _ret = r; \
  |  |  |  |  155|  1.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    923|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 923, False: 113]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.03k|	} else { \
  |  |  |  |  159|      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.03k|	return _ret; \
  |  |  |  |  163|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|  1.03k|}
sc_pkcs15_free_auth_info:
  735|  3.36k|{
  736|  3.36k|	free(auth_info);
  737|  3.36k|}
sc_pkcs15_pincache_add:
  743|     52|{
  744|     52|	struct sc_context *ctx = p15card->card->ctx;
  745|     52|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  746|     52|	struct sc_pkcs15_object *obj = NULL;
  747|     52|	int r;
  748|       |
  749|     52|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     52|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     52|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     52|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     52|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 52]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|       |
  751|     52|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (751:6): [True: 1, False: 51]
  |  Branch (751:14): [True: 0, False: 51]
  ------------------
  752|      1|		sc_log(ctx, "No cache for zero length PIN");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  753|      1|		return;
  754|      1|	}
  755|     51|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (755:11): [True: 1, False: 50]
  ------------------
  756|      1|		sc_log(ctx, "PIN caching not 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__
  |  |  ------------------
  ------------------
  757|      1|		return;
  758|      1|	}
  759|     50|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|     50|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (759:11): [True: 0, False: 50]
  ------------------
  760|      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__
  |  |  ------------------
  ------------------
  761|      0|		return;
  762|      0|	}
  763|       |
  764|       |	/* If the PIN protects an object with user consent, don't cache it */
  765|       |
  766|     50|	obj = p15card->obj_list;
  767|    437|	while (obj != NULL) {
  ------------------
  |  Branch (767:9): [True: 390, False: 47]
  ------------------
  768|       |		/* Compare 'sc_pkcs15_object.auth_id' with 'sc_pkcs15_pin_info.auth_id'.
  769|       |		 * In accordance with PKCS#15 "6.1.8 CommonObjectAttributes" and
  770|       |		 * "6.1.16 CommonAuthenticationObjectAttributes" with the exception that
  771|       |		 * "CommonObjectAttributes.accessControlRules" are not taken into account. */
  772|       |
  773|    390|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (773:7): [True: 68, False: 322]
  ------------------
  774|       |			/* Caching is refused, if the protected object requires user consent */
  775|     68|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (775:8): [True: 68, False: 0]
  ------------------
  776|     68|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (776:9): [True: 3, False: 65]
  ------------------
  777|      3|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  778|      3|					return;
  779|      3|				}
  780|     68|			}
  781|     68|		}
  782|       |
  783|    387|		obj = obj->next;
  784|    387|	}
  785|       |
  786|     47|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  787|     47|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
  |  Branch (787:6): [True: 0, False: 47]
  ------------------
  788|      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__
  |  |  ------------------
  ------------------
  789|      0|		return;
  790|      0|	}
  791|       |
  792|     47|	pin_obj->usage_counter = 0;
  793|     47|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  794|     47|}
sc_pkcs15_pincache_clear:
  847|  2.53k|{
  848|  2.53k|	struct sc_pkcs15_object *objs[32];
  849|  2.53k|	int i, r;
  850|       |
  851|  2.53k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  2.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  852|  2.53k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|  2.53k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  853|  5.88k|	for (i = 0; i < r; i++)
  ------------------
  |  Branch (853:14): [True: 3.34k, False: 2.53k]
  ------------------
  854|  3.34k|		sc_pkcs15_free_object_content(objs[i]);
  855|  2.53k|}
pkcs15-pin.c:_validate_pin:
  261|    437|{
  262|    437|	size_t max_length;
  263|    437|	if (p15card == NULL) {
  ------------------
  |  Branch (263:6): [True: 0, False: 437]
  ------------------
  264|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  265|      0|	}
  266|       |
  267|       |	/* Ignore validation of the non-PIN authentication objects */
  268|    437|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    437|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (268:6): [True: 0, False: 437]
  ------------------
  269|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  270|       |
  271|       |	/* prevent buffer overflow from hostile card */
  272|    437|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|    437|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (272:6): [True: 0, False: 437]
  ------------------
  273|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  274|       |
  275|       |	/* if we use pinpad, no more checks are needed */
  276|    437|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    874|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (276:7): [True: 0, False: 437]
  ------------------
  277|    437|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    437|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (277:8): [True: 0, False: 437]
  ------------------
  278|      0|		   	&& !pinlen)
  ------------------
  |  Branch (278:10): [True: 0, False: 0]
  ------------------
  279|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  280|       |
  281|       |	/* If pin is given, make sure it is within limits */
  282|    437|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|    437|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (282:15): [True: 437, False: 0]
  ------------------
  283|    437|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (283:6): [True: 61, False: 376]
  |  Branch (283:29): [True: 10, False: 366]
  ------------------
  284|     71|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     71|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  285|       |
  286|    366|	return SC_SUCCESS;
  ------------------
  |  |   28|    366|#define SC_SUCCESS				0
  ------------------
  287|    437|}

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

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

sc_pkcs15emu_pteid_init_ex:
  349|  4.01k|{
  350|  4.01k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  4.01k|#define SC_SUCCESS				0
  ------------------
  351|  4.01k|	sc_context_t *ctx = p15card->card->ctx;
  352|  4.01k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.01k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.01k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|       |
  354|       |	/* check for proper card */
  355|  4.01k|	r = pteid_detect_card(p15card->card);
  356|  4.01k|	if (r == SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  4.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (356:6): [True: 4.01k, False: 0]
  ------------------
  357|  4.01k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  4.01k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.01k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.01k|	int _ret = r; \
  |  |  |  |  155|  4.01k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.01k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.01k|	return _ret; \
  |  |  |  |  163|  4.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|       |	/* ok: initialize and return */
  359|      0|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_pteid_init(p15card));
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|      0|}
pkcs15-pteid.c:pteid_detect_card:
  342|  4.01k|{
  343|  4.01k|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID)
  ------------------
  |  Branch (343:6): [True: 0, False: 4.01k]
  ------------------
  344|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  345|  4.01k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  4.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  346|  4.01k|}

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

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

sc_pkcs15emu_skeid_init_ex:
  181|  3.42k|{
  182|  3.42k|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  183|       |
  184|  3.42k|	if (p15card->card->type == SC_CARD_TYPE_SKEID_V3
  ------------------
  |  Branch (184:6): [True: 0, False: 3.42k]
  ------------------
  185|      0|		&& (aid == NULL || (aid->len == skeid_aid_qes.len && !memcmp(aid->value, &skeid_aid_qes.value, skeid_aid_qes.len))))
  ------------------
  |  Branch (185:7): [True: 0, False: 0]
  |  Branch (185:23): [True: 0, False: 0]
  |  Branch (185:56): [True: 0, False: 0]
  ------------------
  186|      0|		r = sc_pkcs15emu_skeid_init(p15card);
  187|       |
  188|  3.42k|	return r;
  189|  3.42k|}

sc_pkcs15_decode_skdf_entry:
  102|      2|{
  103|      2|        struct sc_context *ctx = p15card->card->ctx;
  104|      2|        struct sc_pkcs15_skey_info info;
  105|      2|	int r, i, ii;
  106|      2|	size_t usage_len = sizeof(info.usage);
  107|      2|	size_t af_len = sizeof(info.access_flags);
  108|      2|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  109|      2|	struct sc_asn1_entry asn1_com_skey_attr[C_ASN1_COM_SKEY_ATTR_SIZE];
  110|      2|	struct sc_asn1_entry asn1_generic_skey_attr[C_ASN1_COM_SKEY_GENERIC_ATTR_SIZE];
  111|      2|	struct sc_asn1_entry asn1_generic_skey_value_attr[C_ASN1_COM_SKEY_GENERIC_VALUE_ATTR_SIZE];
  112|      2|	struct sc_asn1_entry asn1_skey_choice[C_ASN1_SKEY_CHOICE_SIZE];
  113|      2|	struct sc_asn1_entry asn1_skey[C_ASN1_SKEY_SIZE];
  114|      2|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  115|      2|	struct sc_asn1_pkcs15_object skey_des_obj = {
  116|      2|		obj, asn1_com_key_attr, asn1_com_skey_attr, asn1_generic_skey_attr
  117|      2|	};
  118|      2|	static const struct sc_object_id id_aes = { { 2, 16, 840, 1, 101, 3, 4, 1, -1 } };
  119|      2|	struct sc_object_id temp_oid;
  120|       |
  121|      2|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|      2|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      2|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      2|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2]
  |  |  ------------------
  ------------------
  122|       |
  123|      2|	sc_copy_asn1_entry(c_asn1_skey, asn1_skey);
  124|      2|	sc_copy_asn1_entry(c_asn1_skey_choice, asn1_skey_choice);
  125|      2|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  126|       |
  127|      2|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  128|      2|	sc_copy_asn1_entry(c_asn1_com_skey_attr, asn1_com_skey_attr);
  129|      2|	sc_copy_asn1_entry(c_asn1_generic_skey_attr, asn1_generic_skey_attr);
  130|      2|	sc_copy_asn1_entry(c_asn1_generic_skey_value_attr, asn1_generic_skey_value_attr);
  131|       |
  132|      2|	sc_format_asn1_entry(asn1_skey + 0, asn1_skey_choice, NULL, 0);
  133|      2|	sc_format_asn1_entry(asn1_skey_choice + 0, &skey_des_obj, NULL, 0);
  134|      2|	sc_format_asn1_entry(asn1_skey_choice + 1, &skey_des_obj, NULL, 0);
  135|      2|	sc_format_asn1_entry(asn1_skey_choice + 2, &skey_des_obj, NULL, 0);
  136|      2|	sc_format_asn1_entry(asn1_skey_choice + 3, &skey_des_obj, NULL, 0);
  137|       |
  138|      2|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  139|      2|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  140|      2|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  141|      2|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  142|      2|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  143|     34|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|     68|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (143:12): [True: 32, False: 2]
  |  Branch (143:45): [True: 32, False: 0]
  ------------------
  144|     32|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  145|      2|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  146|       |
  147|      2|	sc_format_asn1_entry(asn1_com_skey_attr + 0, &info.value_len, NULL, 0);
  148|       |
  149|      2|	sc_format_asn1_entry(asn1_generic_skey_attr + 0, asn1_generic_skey_value_attr, NULL, 0);
  150|      2|	sc_format_asn1_entry(asn1_generic_skey_value_attr + 0, &info.path, NULL, 0);
  151|       |
  152|       |        /* Fill in defaults */
  153|      2|	memset(&info, 0, sizeof(info));
  154|      2|	info.native = 1;
  155|       |
  156|      2|	r = sc_asn1_decode(ctx, asn1_skey, *buf, *buflen, buf, buflen);
  157|      2|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      2|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (157:6): [True: 2, False: 0]
  ------------------
  158|      2|		return r;
  159|      0|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|      0|	if (asn1_skey_choice[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (160:6): [True: 0, False: 0]
  ------------------
  161|      0|		obj->type = SC_PKCS15_TYPE_SKEY_GENERIC;
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  162|       |
  163|       |		/* Check key type. framework-pkcs15 recognizes one type per key, and AES is the only algorithm supported for
  164|       |		* SKEY_GENERIC type keys, so just check if this key is AES compatible. */
  165|       |
  166|      0|		for (i = 0; i < SC_MAX_SUPPORTED_ALGORITHMS && info.algo_refs[i] != 0 && info.key_type == 0; i++) {
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (166:15): [True: 0, False: 0]
  |  Branch (166:50): [True: 0, False: 0]
  |  Branch (166:76): [True: 0, False: 0]
  ------------------
  167|      0|			for (ii = 0; ii < SC_MAX_SUPPORTED_ALGORITHMS && p15card->tokeninfo != 0; ii++) {
  ------------------
  |  |   61|      0|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (167:17): [True: 0, False: 0]
  |  Branch (167:53): [True: 0, False: 0]
  ------------------
  168|      0|				if (info.algo_refs[i] == p15card->tokeninfo->supported_algos[ii].reference) {
  ------------------
  |  Branch (168:9): [True: 0, False: 0]
  ------------------
  169|      0|					temp_oid = p15card->tokeninfo->supported_algos[ii].algo_id;
  170|      0|					temp_oid.value[8] = -1; /* strip off AES subtype octet*/
  171|       |
  172|      0|					if (sc_compare_oid(&id_aes, &temp_oid)) {
  ------------------
  |  Branch (172:10): [True: 0, False: 0]
  ------------------
  173|      0|						info.key_type = CKK_AES;
  ------------------
  |  |  485|      0|#define CKK_AES 0x0000001FUL
  ------------------
  174|      0|						break;
  175|      0|					}
  176|      0|				}
  177|      0|			}
  178|      0|		}
  179|      0|	}
  180|      0|	else if (asn1_skey_choice[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (180:11): [True: 0, False: 0]
  ------------------
  181|      0|		obj->type = SC_PKCS15_TYPE_SKEY_DES;
  ------------------
  |  |  434|      0|#define SC_PKCS15_TYPE_SKEY_DES			0x302
  ------------------
  182|      0|	else if (asn1_skey_choice[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (182:11): [True: 0, False: 0]
  ------------------
  183|      0|		obj->type = SC_PKCS15_TYPE_SKEY_2DES;
  ------------------
  |  |  435|      0|#define SC_PKCS15_TYPE_SKEY_2DES		0x303
  ------------------
  184|      0|	else if (asn1_skey_choice[3].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (184:11): [True: 0, False: 0]
  ------------------
  185|      0|		obj->type = SC_PKCS15_TYPE_SKEY_3DES;
  ------------------
  |  |  436|      0|#define SC_PKCS15_TYPE_SKEY_3DES		0x304
  ------------------
  186|      0|	else
  187|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported secret key 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|      0|	obj->data = malloc(sizeof(info));
  190|      0|	if (obj->data == NULL)
  ------------------
  |  Branch (190:6): [True: 0, False: 0]
  ------------------
  191|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|      0|	memcpy(obj->data, &info, sizeof(info));
  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_pkcs15emu_srbeid_init_ex:
  570|  3.42k|{
  571|  3.42k|	(void)aid;
  572|       |
  573|  3.42k|	if (p15card->card->type != SC_CARD_TYPE_SRBEID_BASE)
  ------------------
  |  Branch (573:6): [True: 3.42k, False: 0]
  ------------------
  574|  3.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  575|       |
  576|      0|	return sc_pkcs15emu_srbeid_init(p15card);
  577|  3.42k|}

sc_pkcs15emu_starcert_init_ex:
  274|  5.82k|{
  275|  5.82k|	if (starcert_detect_card(p15card))
  ------------------
  |  Branch (275:6): [True: 5.82k, False: 0]
  ------------------
  276|  5.82k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  5.82k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  277|      0|	return sc_pkcs15emu_starcert_init(p15card);
  278|  5.82k|}
pkcs15-starcert.c:starcert_detect_card:
  101|  5.82k|{
  102|  5.82k|	int       r;
  103|  5.82k|	u8        buf[128];
  104|  5.82k|	sc_path_t path;
  105|  5.82k|	sc_card_t *card = p15card->card;
  106|       |
  107|       |	/* check if we have the correct card OS */
  108|  5.82k|	if (strcmp(card->name, "STARCOS"))
  ------------------
  |  Branch (108:6): [True: 5.82k, False: 0]
  ------------------
  109|  5.82k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  5.82k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  110|       |	/* read EF_Info file */
  111|      0|	sc_format_path("3F00FE13", &path);
  112|      0|	r = sc_select_file(card, &path, NULL);
  113|      0|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (113:6): [True: 0, False: 0]
  ------------------
  114|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  115|      0|	r = sc_read_binary(card, 0, buf, 64, 0);
  116|      0|	if (r != 64)
  ------------------
  |  Branch (116:6): [True: 0, False: 0]
  ------------------
  117|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  118|      0|	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|      0|#define STARCERT	"StarCertV2201"
  ------------------
              	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|      0|#define STARCERT	"StarCertV2201"
  ------------------
  |  Branch (118:6): [True: 0, False: 0]
  ------------------
  119|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  120|       |
  121|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  122|      0|}

sc_pkcs15emu_starcos_esign_init_ex:
  355|  3.42k|{
  356|  3.42k|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  357|       |
  358|  3.42k|	if (!p15card || !p15card->card || !p15card->card->ctx)
  ------------------
  |  Branch (358:6): [True: 0, False: 3.42k]
  |  Branch (358:18): [True: 0, False: 3.42k]
  |  Branch (358:36): [True: 0, False: 3.42k]
  ------------------
  359|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  360|       |
  361|  3.42k|	r = starcos_esign_init(p15card, aid);
  362|  3.42k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  3.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.42k|	int _ret = r; \
  |  |  |  |  155|  3.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.42k|	return _ret; \
  |  |  |  |  163|  3.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|  3.42k|}
pkcs15-starcos-esign.c:starcos_esign_init:
  286|  3.42k|{
  287|  3.42k|	sc_card_t *card = p15card->card;
  288|  3.42k|	sc_context_t *ctx = card->ctx;
  289|  3.42k|	const char *label = name_Card;
  290|  3.42k|	int r;
  291|  3.42k|	int apps_added = 0;
  292|       |
  293|  3.42k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  3.42k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.42k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.42k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.42k]
  |  |  ------------------
  ------------------
  294|       |
  295|  3.42k|	if (card->type != SC_CARD_TYPE_STARCOS_V3_4_ESIGN && card->type != SC_CARD_TYPE_STARCOS_V3_5_ESIGN) {
  ------------------
  |  Branch (295:6): [True: 3.42k, False: 0]
  |  Branch (295:55): [True: 3.42k, False: 0]
  ------------------
  296|  3.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  297|  3.42k|	}
  298|       |
  299|      0|	if (aid == NULL) {
  ------------------
  |  Branch (299:6): [True: 0, False: 0]
  ------------------
  300|       |		// no aid: in this case all emulated apps are added, currently only the esign_app
  301|      0|		r = starcos_add_esign_app(p15card);
  302|      0|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (302:7): [True: 0, False: 0]
  ------------------
  303|      0|			apps_added++;
  304|      0|	} else {
  305|       |		// aid specified: only the matching app is added
  306|      0|		if (aid->len == sizeof(aid_ESIGN) && memcmp(aid->value, aid_ESIGN, sizeof(aid_ESIGN)) == 0) {
  ------------------
  |  Branch (306:7): [True: 0, False: 0]
  |  Branch (306:40): [True: 0, False: 0]
  ------------------
  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|      0|		if (apps_added > 0) {
  ------------------
  |  Branch (314:7): [True: 0, False: 0]
  ------------------
  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|      0|	}
  326|       |
  327|      0|	if (apps_added == 0) {
  ------------------
  |  Branch (327:6): [True: 0, False: 0]
  ------------------
  328|      0|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_CARD, "No supported app found on this 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  329|      0|	}
  330|       |
  331|      0|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  332|       |
  333|      0|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  334|      0|	if (!p15card->tokeninfo) {
  ------------------
  |  Branch (334:6): [True: 0, False: 0]
  ------------------
  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|      0|	} else {
  337|      0|		sc_serial_number_t serial;
  338|      0|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  339|      0|		r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  340|      0|		LOG_TEST_RET(ctx, r, "Failed to query card serial number");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|      0|		r = sc_bin_to_hex(serial.value, serial.len, serial_hex, sizeof serial_hex, 0);
  343|      0|		LOG_TEST_RET(ctx, r, "Failed to convert S/N to hex");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  344|      0|		p15card->tokeninfo->serial_number = strdup(serial_hex);
  345|      0|		p15card->tokeninfo->label = strdup(label);
  346|      0|		p15card->tokeninfo->manufacturer_id = strdup(name_Vendor);
  347|      0|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      0|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  348|      0|	}
  349|       |
  350|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|}

sc_pkcs15_is_emulation_only:
   90|  5.95k|{
   91|  5.95k|	switch (card->type) {
   92|      0|		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
  ------------------
  |  Branch (92:3): [True: 0, False: 5.95k]
  ------------------
   93|      2|		case SC_CARD_TYPE_OPENPGP_V1:
  ------------------
  |  Branch (93:3): [True: 2, False: 5.95k]
  ------------------
   94|      8|		case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (94:3): [True: 6, False: 5.94k]
  ------------------
   95|      8|		case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (95:3): [True: 0, False: 5.95k]
  ------------------
   96|     15|		case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (96:3): [True: 7, False: 5.94k]
  ------------------
   97|     15|		case SC_CARD_TYPE_SC_HSM:
  ------------------
  |  Branch (97:3): [True: 0, False: 5.95k]
  ------------------
   98|     15|		case SC_CARD_TYPE_SC_HSM_SOC:
  ------------------
  |  Branch (98:3): [True: 0, False: 5.95k]
  ------------------
   99|     15|		case SC_CARD_TYPE_DNIE_BASE:
  ------------------
  |  Branch (99:3): [True: 0, False: 5.95k]
  ------------------
  100|     15|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (100:3): [True: 0, False: 5.95k]
  ------------------
  101|     15|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (101:3): [True: 0, False: 5.95k]
  ------------------
  102|    289|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (102:3): [True: 274, False: 5.68k]
  ------------------
  103|    289|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (103:3): [True: 0, False: 5.95k]
  ------------------
  104|    289|		case SC_CARD_TYPE_IASECC_GEMALTO:
  ------------------
  |  Branch (104:3): [True: 0, False: 5.95k]
  ------------------
  105|    289|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (105:3): [True: 0, False: 5.95k]
  ------------------
  106|    289|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (106:3): [True: 0, False: 5.95k]
  ------------------
  107|    289|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (107:3): [True: 0, False: 5.95k]
  ------------------
  108|    289|		case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (108:3): [True: 0, False: 5.95k]
  ------------------
  109|    675|		case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (109:3): [True: 386, False: 5.56k]
  ------------------
  110|  1.15k|		case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (110:3): [True: 476, False: 5.47k]
  ------------------
  111|  1.15k|		case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (111:3): [True: 0, False: 5.95k]
  ------------------
  112|  1.15k|		case SC_CARD_TYPE_ESTEID_2018:
  ------------------
  |  Branch (112:3): [True: 0, False: 5.95k]
  ------------------
  113|  1.15k|		case SC_CARD_TYPE_CARDOS_V5_0:
  ------------------
  |  Branch (113:3): [True: 0, False: 5.95k]
  ------------------
  114|  1.53k|		case SC_CARD_TYPE_CARDOS_V5_3:
  ------------------
  |  Branch (114:3): [True: 380, False: 5.57k]
  ------------------
  115|  1.53k|		case SC_CARD_TYPE_NQ_APPLET:
  ------------------
  |  Branch (115:3): [True: 0, False: 5.95k]
  ------------------
  116|  1.53k|		case SC_CARD_TYPE_NQ_APPLET_RFID:
  ------------------
  |  Branch (116:3): [True: 0, False: 5.95k]
  ------------------
  117|  1.53k|		case SC_CARD_TYPE_STARCOS_V3_4_ESIGN:
  ------------------
  |  Branch (117:3): [True: 0, False: 5.95k]
  ------------------
  118|  1.53k|		case SC_CARD_TYPE_STARCOS_V3_5_ESIGN:
  ------------------
  |  Branch (118:3): [True: 0, False: 5.95k]
  ------------------
  119|  1.53k|		case SC_CARD_TYPE_SKEID_V3:
  ------------------
  |  Branch (119:3): [True: 0, False: 5.95k]
  ------------------
  120|  1.53k|		case SC_CARD_TYPE_EOI:
  ------------------
  |  Branch (120:3): [True: 0, False: 5.95k]
  ------------------
  121|  1.53k|		case SC_CARD_TYPE_EOI_CONTACTLESS:
  ------------------
  |  Branch (121:3): [True: 0, False: 5.95k]
  ------------------
  122|  1.53k|		case SC_CARD_TYPE_DTRUST_V4_1_STD:
  ------------------
  |  Branch (122:3): [True: 0, False: 5.95k]
  ------------------
  123|  1.53k|		case SC_CARD_TYPE_DTRUST_V4_4_STD:
  ------------------
  |  Branch (123:3): [True: 0, False: 5.95k]
  ------------------
  124|  1.53k|		case SC_CARD_TYPE_DTRUST_V4_1_MULTI:
  ------------------
  |  Branch (124:3): [True: 0, False: 5.95k]
  ------------------
  125|  1.53k|		case SC_CARD_TYPE_DTRUST_V4_1_M100:
  ------------------
  |  Branch (125:3): [True: 0, False: 5.95k]
  ------------------
  126|  1.53k|		case SC_CARD_TYPE_DTRUST_V4_4_MULTI:
  ------------------
  |  Branch (126:3): [True: 0, False: 5.95k]
  ------------------
  127|  1.53k|		case SC_CARD_TYPE_DTRUST_V5_1_STD:
  ------------------
  |  Branch (127:3): [True: 0, False: 5.95k]
  ------------------
  128|  1.53k|		case SC_CARD_TYPE_DTRUST_V5_4_STD:
  ------------------
  |  Branch (128:3): [True: 0, False: 5.95k]
  ------------------
  129|  1.53k|		case SC_CARD_TYPE_DTRUST_V5_1_MULTI:
  ------------------
  |  Branch (129:3): [True: 0, False: 5.95k]
  ------------------
  130|  1.53k|		case SC_CARD_TYPE_DTRUST_V5_1_M100:
  ------------------
  |  Branch (130:3): [True: 0, False: 5.95k]
  ------------------
  131|  1.53k|		case SC_CARD_TYPE_DTRUST_V5_4_MULTI:
  ------------------
  |  Branch (131:3): [True: 0, False: 5.95k]
  ------------------
  132|  1.53k|		case SC_CARD_TYPE_LTEID:
  ------------------
  |  Branch (132:3): [True: 0, False: 5.95k]
  ------------------
  133|  1.72k|		case SC_CARD_TYPE_CEDULAUY:
  ------------------
  |  Branch (133:3): [True: 194, False: 5.76k]
  ------------------
  134|  1.72k|			return 1;
  135|  4.23k|		default:
  ------------------
  |  Branch (135:3): [True: 4.23k, False: 1.72k]
  ------------------
  136|  4.23k|			return 0;
  137|  5.95k|	}
  138|  5.95k|}
sc_pkcs15_bind_synthetic:
  142|  5.82k|{
  143|  5.82k|	sc_context_t		*ctx = p15card->card->ctx;
  144|  5.82k|	scconf_block		*conf_block, **blocks, *blk;
  145|  5.82k|	int			i, r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  5.82k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  146|       |
  147|  5.82k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.82k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.82k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.82k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.82k]
  |  |  ------------------
  ------------------
  148|  5.82k|	conf_block = NULL;
  149|       |
  150|  5.82k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
  151|       |
  152|  5.82k|	if (!conf_block) {
  ------------------
  |  Branch (152:6): [True: 5.82k, False: 0]
  ------------------
  153|       |		/* no conf file found => try builtin drivers  */
  154|  5.82k|		sc_log(ctx, "no conf file (or section), trying all builtin emulators");
  ------------------
  |  |   71|  5.82k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  155|   122k|		for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (155:15): [True: 119k, False: 3.42k]
  ------------------
  156|   119k|			sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|   119k|#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|   119k|			r = builtin_emulators[i].handler(p15card, aid);
  158|   119k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|   119k|#define SC_SUCCESS				0
  ------------------
  |  Branch (158:8): [True: 2.39k, False: 117k]
  ------------------
  159|       |				/* we got a hit */
  160|  2.39k|				goto out;
  161|   119k|		}
  162|  5.82k|	} else {
  163|       |		/* we have a conf file => let's use it */
  164|      0|		int builtin_enabled;
  165|      0|		const scconf_list *list;
  166|       |
  167|      0|		builtin_enabled = scconf_get_bool(conf_block, "enable_builtin_emulation", 1);
  168|      0|		list = scconf_find_list(conf_block, "builtin_emulators"); /* FIXME: rename to enabled_emulators */
  169|       |
  170|      0|		if (builtin_enabled && list) {
  ------------------
  |  Branch (170:7): [True: 0, False: 0]
  |  Branch (170:26): [True: 0, False: 0]
  ------------------
  171|       |			/* filter enabled emulation drivers from conf file */
  172|      0|			struct _sc_pkcs15_emulators filtered_emulators;
  173|      0|			struct sc_pkcs15_emulator_handler** lst;
  174|      0|			int ret;
  175|       |
  176|      0|			filtered_emulators.ccount = 0;
  177|      0|			ret = set_emulators(ctx, &filtered_emulators, list, builtin_emulators, old_emulators);
  178|      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 (178:8): [True: 0, False: 0]
  |  Branch (178:29): [True: 0, False: 0]
  ------------------
  179|      0|				lst = filtered_emulators.list_of_handlers;
  180|       |
  181|      0|				if (ret == SC_ERROR_TOO_MANY_OBJECTS)
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
  |  Branch (181:9): [True: 0, False: 0]
  ------------------
  182|      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)
  |  |  ------------------
  |  |  |  |  182|      0|					sc_log(ctx, "trying first %d emulators from conf file", SC_MAX_PKCS15_EMULATORS);
  |  |  |  |  ------------------
  |  |  |  |  |  |   52|      0|#define SC_MAX_PKCS15_EMULATORS	48
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|      0|				for (i = 0; lst[i]; i++) {
  ------------------
  |  Branch (184:17): [True: 0, False: 0]
  ------------------
  185|      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__
  |  |  ------------------
  ------------------
  186|      0|					r = lst[i]->handler(p15card, aid);
  187|      0|					if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (187:10): [True: 0, False: 0]
  ------------------
  188|       |						/* we got a hit */
  189|      0|						goto out;
  190|      0|				}
  191|      0|			} else {
  192|      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__
  |  |  ------------------
  ------------------
  193|      0|			}
  194|      0|		}
  195|      0|		else if (builtin_enabled) {
  ------------------
  |  Branch (195:12): [True: 0, False: 0]
  ------------------
  196|      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__
  |  |  ------------------
  ------------------
  197|      0|			for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (197:16): [True: 0, False: 0]
  ------------------
  198|      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__
  |  |  ------------------
  ------------------
  199|      0|				r = builtin_emulators[i].handler(p15card, aid);
  200|      0|				if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (200:9): [True: 0, False: 0]
  ------------------
  201|       |					/* we got a hit */
  202|      0|					goto out;
  203|      0|			}
  204|      0|		}
  205|       |
  206|       |		/* search for 'emulate foo { ... }' entries in the conf file */
  207|      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__
  |  |  ------------------
  ------------------
  208|      0|		blocks = scconf_find_blocks(ctx->conf, conf_block, "emulate", NULL);
  209|      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__
  |  |  ------------------
  ------------------
  210|      0|		for (i = 0; blocks && (blk = blocks[i]) != NULL; i++) {
  ------------------
  |  Branch (210:15): [True: 0, False: 0]
  |  Branch (210:25): [True: 0, False: 0]
  ------------------
  211|      0|			const char *name = blk->name->data;
  212|      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__
  |  |  ------------------
  ------------------
  213|      0|			r = parse_emu_block(p15card, aid, blk);
  214|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (214:8): [True: 0, False: 0]
  ------------------
  215|      0|				free(blocks);
  216|      0|				goto out;
  217|      0|			}
  218|      0|		}
  219|      0|		if (blocks)
  ------------------
  |  Branch (219:7): [True: 0, False: 0]
  ------------------
  220|      0|			free(blocks);
  221|      0|	}
  222|       |
  223|  5.82k|out:
  224|  5.82k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  5.82k|#define SC_SUCCESS				0
  ------------------
  |  Branch (224:6): [True: 2.39k, False: 3.42k]
  ------------------
  225|  2.39k|		p15card->magic  = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  2.39k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  226|  2.39k|		p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
  ------------------
  |  |  601|  2.39k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  227|  3.42k|	} else {
  228|  3.42k|		if (r != SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  3.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (228:7): [True: 0, False: 3.42k]
  ------------------
  229|      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__
  |  |  ------------------
  ------------------
  230|  3.42k|	}
  231|       |
  232|  5.82k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  5.82k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.82k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.82k|	int _ret = r; \
  |  |  |  |  155|  5.82k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.82k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  3.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.42k, False: 2.39k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.82k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.82k|	return _ret; \
  |  |  |  |  163|  5.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|  5.82k|}
sc_pkcs15emu_add_pin_obj:
  369|  3.36k|{
  370|  3.36k|	sc_pkcs15_auth_info_t pin = *in_pin;
  371|       |
  372|  3.36k|	pin.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  3.36k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  373|  3.36k|	if(!pin.auth_method) /* or SC_AC_NONE */
  ------------------
  |  Branch (373:5): [True: 3.36k, False: 0]
  ------------------
  374|  3.36k|		pin.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|  3.36k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  375|       |
  376|  3.36k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_AUTH_PIN, obj, &pin);
  ------------------
  |  |  445|  3.36k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  377|  3.36k|}
sc_pkcs15emu_add_rsa_prkey:
  381|    341|{
  382|    341|	sc_pkcs15_prkey_info_t key = *in_key;
  383|       |
  384|    341|	if (key.access_flags == 0)
  ------------------
  |  Branch (384:6): [True: 341, False: 0]
  ------------------
  385|    341|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    341|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  386|    341|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    341|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  387|    341|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    341|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  388|    341|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    341|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  389|       |
  390|    341|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_RSA, obj, &key);
  ------------------
  |  |  419|    341|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  391|    341|}
sc_pkcs15emu_add_rsa_pubkey:
  395|     70|{
  396|     70|	sc_pkcs15_pubkey_info_t key = *in_key;
  397|       |
  398|     70|	if (key.access_flags == 0)
  ------------------
  |  Branch (398:6): [True: 70, False: 0]
  ------------------
  399|     70|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|     70|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  400|       |
  401|     70|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_RSA, obj, &key);
  ------------------
  |  |  426|     70|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  402|     70|}
sc_pkcs15emu_add_ec_prkey:
  406|    116|{
  407|    116|	sc_pkcs15_prkey_info_t key = *in_key;
  408|       |
  409|    116|	if (key.access_flags == 0)
  ------------------
  |  Branch (409:6): [True: 116, False: 0]
  ------------------
  410|    116|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    116|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  411|    116|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    116|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  412|    116|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    116|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  413|    116|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    116|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  414|       |
  415|    116|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EC, obj, &key);
  ------------------
  |  |  421|    116|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  416|    116|}
sc_pkcs15emu_add_ec_pubkey:
  420|    116|{
  421|    116|	sc_pkcs15_pubkey_info_t key = *in_key;
  422|       |
  423|    116|	if (key.access_flags == 0)
  ------------------
  |  Branch (423:6): [True: 116, False: 0]
  ------------------
  424|    116|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    116|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  425|       |
  426|    116|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EC, obj, &key);
  ------------------
  |  |  428|    116|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  427|    116|}
sc_pkcs15emu_add_x509_cert:
  481|    767|{
  482|    767|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_CERT_X509, obj, cert);
  ------------------
  |  |  439|    767|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  483|    767|}
sc_pkcs15emu_add_data_object:
  487|  2.15k|{
  488|  2.15k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, obj, data);
  ------------------
  |  |  442|  2.15k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  489|  2.15k|}
sc_pkcs15emu_object_add:
  493|  25.4k|{
  494|  25.4k|	sc_pkcs15_object_t *obj;
  495|  25.4k|	unsigned int	df_type;
  496|  25.4k|	size_t		data_len;
  497|       |
  498|  25.4k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  25.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  25.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  25.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 25.4k]
  |  |  ------------------
  ------------------
  499|       |
  500|  25.4k|	obj = calloc(1, sizeof(*obj));
  501|  25.4k|	if (!obj) {
  ------------------
  |  Branch (501:6): [True: 0, False: 25.4k]
  ------------------
  502|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  503|      0|	}
  504|       |
  505|  25.4k|	memcpy(obj, in_obj, sizeof(*obj));
  506|  25.4k|	obj->type = type;
  507|       |
  508|  25.4k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  25.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  509|  3.36k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  3.36k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (509:2): [True: 3.36k, False: 22.0k]
  ------------------
  510|  3.36k|		df_type  = SC_PKCS15_AODF;
  ------------------
  |  |  496|  3.36k|#define SC_PKCS15_AODF			8
  ------------------
  511|  3.36k|		data_len = sizeof(struct sc_pkcs15_auth_info);
  512|  3.36k|		break;
  513|    457|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|    457|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (513:2): [True: 457, False: 24.9k]
  ------------------
  514|    457|		df_type  = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|    457|#define SC_PKCS15_PRKDF			0
  ------------------
  515|    457|		data_len = sizeof(struct sc_pkcs15_prkey_info);
  516|    457|		break;
  517|    186|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    186|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (517:2): [True: 186, False: 25.2k]
  ------------------
  518|    186|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|    186|#define SC_PKCS15_PUKDF			1
  ------------------
  519|    186|		data_len = sizeof(struct sc_pkcs15_pubkey_info);
  520|    186|		break;
  521|    767|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|    767|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (521:2): [True: 767, False: 24.6k]
  ------------------
  522|    767|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|    767|#define SC_PKCS15_CDF			4
  ------------------
  523|    767|		data_len = sizeof(struct sc_pkcs15_cert_info);
  524|    767|		break;
  525|  20.6k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  20.6k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (525:2): [True: 20.6k, False: 4.77k]
  ------------------
  526|  20.6k|		df_type = SC_PKCS15_DODF;
  ------------------
  |  |  495|  20.6k|#define SC_PKCS15_DODF			7
  ------------------
  527|  20.6k|		data_len = sizeof(struct sc_pkcs15_data_info);
  528|  20.6k|		break;
  529|      0|	default:
  ------------------
  |  Branch (529:2): [True: 0, False: 25.4k]
  ------------------
  530|      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__
  |  |  ------------------
  ------------------
  531|      0|		free(obj);
  532|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  533|  25.4k|	}
  534|       |
  535|  25.4k|	obj->data = calloc(1, data_len);
  536|  25.4k|	if (obj->data == NULL) {
  ------------------
  |  Branch (536:6): [True: 0, False: 25.4k]
  ------------------
  537|      0|		free(obj);
  538|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|      0|	}
  540|  25.4k|	memcpy(obj->data, data, data_len);
  541|       |
  542|  25.4k|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  543|  25.4k|	sc_pkcs15_add_object(p15card, obj);
  544|       |
  545|       |	/* release memory ownership of buffers that are now contained in `p15card` */
  546|  25.4k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  25.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  547|  3.36k|	default:
  ------------------
  |  Branch (547:2): [True: 3.36k, False: 22.0k]
  ------------------
  548|       |		/* `data`'s members copied by value, no buffer to release */
  549|  3.36k|		break;
  550|  3.36k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|    457|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (550:2): [True: 457, False: 24.9k]
  ------------------
  551|    457|		((struct sc_pkcs15_prkey_info *)data)->subject.value = NULL;
  552|    457|		break;
  553|    186|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    186|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (553:2): [True: 186, False: 25.2k]
  ------------------
  554|    186|		((struct sc_pkcs15_pubkey_info *)data)->subject.value = NULL;
  555|    186|		((struct sc_pkcs15_pubkey_info *)data)->direct.raw.value = NULL;
  556|    186|		((struct sc_pkcs15_pubkey_info *)data)->direct.spki.value = NULL;
  557|    186|		break;
  558|    767|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|    767|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (558:2): [True: 767, False: 24.6k]
  ------------------
  559|    767|		((struct sc_pkcs15_cert_info *)data)->value.value = NULL;
  560|    767|		break;
  561|  20.6k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  20.6k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (561:2): [True: 20.6k, False: 4.77k]
  ------------------
  562|  20.6k|		((struct sc_pkcs15_data_info *)data)->data.value = NULL;
  563|  20.6k|		break;
  564|  25.4k|	}
  565|       |
  566|  25.4k|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  25.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  25.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  25.4k|	int _ret = r; \
  |  |  |  |  155|  25.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 25.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  25.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: 25.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  25.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  25.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|  25.4k|	return _ret; \
  |  |  |  |  163|  25.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  567|  25.4k|}
pkcs15-syn.c:sc_pkcs15emu_get_df:
  340|  25.4k|{
  341|  25.4k|	sc_pkcs15_df_t	*df;
  342|  25.4k|	sc_file_t	*file;
  343|  25.4k|	int		created = 0;
  344|       |
  345|  30.0k|	while (1) {
  ------------------
  |  Branch (345:9): [True: 30.0k, Folded]
  ------------------
  346|  40.9k|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (346:31): [True: 36.3k, False: 4.58k]
  ------------------
  347|  36.3k|			if (df->type == type) {
  ------------------
  |  Branch (347:8): [True: 25.4k, False: 10.9k]
  ------------------
  348|  25.4k|				if (created)
  ------------------
  |  Branch (348:9): [True: 4.58k, False: 20.8k]
  ------------------
  349|  4.58k|					df->enumerated = 1;
  350|  25.4k|				return df;
  351|  25.4k|			}
  352|  36.3k|		}
  353|       |
  354|  4.58k|		if (created != 0)
  ------------------
  |  Branch (354:7): [True: 0, False: 4.58k]
  ------------------
  355|      0|			return NULL;
  356|       |
  357|  4.58k|		file = sc_file_new();
  358|  4.58k|		if (!file)
  ------------------
  |  Branch (358:7): [True: 0, False: 4.58k]
  ------------------
  359|      0|			return NULL;
  360|  4.58k|		sc_format_path("11001101", &file->path);
  361|  4.58k|		sc_pkcs15_add_df(p15card, type, &file->path);
  362|  4.58k|		sc_file_free(file);
  363|  4.58k|		created++;
  364|  4.58k|	}
  365|  25.4k|}

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

sc_pkcs15_parse_tokeninfo:
  145|    435|{
  146|    435|	int r;
  147|    435|	size_t ii;
  148|    435|	u8 serial[128];
  149|    435|	size_t serial_len = sizeof(serial);
  150|    435|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  151|    435|	size_t mnfid_len  = sizeof(mnfid) - 1;
  152|    435|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  153|    435|	size_t label_len = sizeof(label) - 1;
  154|    435|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  155|    435|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  156|    435|	size_t flags_len   = sizeof(ti->flags);
  157|    435|	u8 preferred_language[64];
  158|    435|	size_t lang_length = sizeof(preferred_language) - 1;
  159|    435|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  160|    435|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  161|    435|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  162|    435|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  163|    435|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  164|    435|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  165|    435|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  166|    435|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  167|       |
  168|    435|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  169|    435|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  170|    435|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  171|       |
  172|    435|	memset(last_update, 0, sizeof(last_update));
  173|    435|	memset(label, 0, sizeof(label));
  174|    435|	memset(profile_indication, 0, sizeof(profile_indication));
  175|    435|	memset(mnfid, 0, sizeof(mnfid));
  176|       |
  177|    435|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  178|    435|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  179|    435|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  180|    435|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  181|    435|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  182|    435|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  183|       |
  184|  7.39k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  7.39k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (184:13): [True: 6.96k, False: 435]
  ------------------
  185|  6.96k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  186|  6.96k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  187|  6.96k|			asn1_algo_infos_parameters[ii]);
  188|  6.96k|	}
  189|    435|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  190|       |
  191|  7.39k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  7.39k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (191:13): [True: 6.96k, False: 435]
  ------------------
  192|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  193|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  194|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  195|  6.96k|			asn1_algo_infos_parameters[ii], NULL, 0);
  196|  6.96k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  197|  6.96k|			NULL, NULL, 0);
  198|  6.96k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  199|  6.96k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  200|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  201|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  202|  6.96k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  203|  6.96k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  204|  6.96k|	}
  205|       |
  206|    435|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  207|    435|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  208|       |
  209|    435|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  210|    435|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  211|       |
  212|    435|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  213|    435|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  214|    435|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  215|    435|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  216|    435|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  217|    435|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  218|    435|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  219|    435|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  220|    435|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  221|    435|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  222|    435|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  223|    435|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  224|    435|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  225|    435|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  226|    435|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  227|       |
  228|    435|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  229|    435|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    435|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:6): [True: 315, False: 120]
  ------------------
  230|       |		/* The decoding could have allocated something we need to free */
  231|    315|		sc_pkcs15_clear_tokeninfo(ti);
  232|    315|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    315|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    315|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    315|	int _ret = (r); \
  |  |  |  |  168|    315|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 315, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    315|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    315|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    315|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    315|		return _ret; \
  |  |  |  |  172|    315|	} \
  |  |  |  |  173|    315|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|    315|	}
  234|       |
  235|    120|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  147|    240|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 116, False: 4]
  |  Branch (235:52): [True: 116, False: 0]
  ------------------
  236|    116|		free(ti->serial_number);
  237|    116|		ti->serial_number = malloc(serial_len * 2 + 1);
  238|    116|		if (ti->serial_number == NULL)
  ------------------
  |  Branch (238:7): [True: 0, False: 116]
  ------------------
  239|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  240|    116|		sc_bin_to_hex(serial, serial_len, ti->serial_number, serial_len * 2 + 1, 0);
  241|    116|		sc_log(ctx, "TokenInfo.serialNunmber '%s'", ti->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  242|    116|	}
  243|       |
  244|    120|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (244:6): [True: 120, False: 0]
  ------------------
  245|    120|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    120|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (245:7): [True: 117, False: 3]
  ------------------
  246|    117|			ti->manufacturer_id = strdup((char *) mnfid);
  247|      3|		else
  248|      3|			ti->manufacturer_id = strdup("(unknown)");
  249|    120|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 120]
  ------------------
  250|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  251|    120|	}
  252|    120|	if (ti->label == NULL) {
  ------------------
  |  Branch (252:6): [True: 120, False: 0]
  ------------------
  253|    120|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  147|    240|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 114, False: 6]
  ------------------
  254|      6|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|      6|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (254:7): [True: 0, False: 6]
  ------------------
  255|    114|			ti->label = strdup((char *) label);
  256|      6|		else
  257|      6|			ti->label = strdup("(unknown)");
  258|    120|		if (ti->label == NULL)
  ------------------
  |  Branch (258:7): [True: 0, False: 120]
  ------------------
  259|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  260|    120|	}
  261|    120|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    120|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:6): [True: 12, False: 108]
  ------------------
  262|     12|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|     12|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (262:7): [True: 7, False: 5]
  ------------------
  263|      7|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  264|      7|			ti->last_update.gtime = strdup((char *)last_update);
  265|      7|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (265:8): [True: 0, False: 7]
  ------------------
  266|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  267|      7|		}
  268|      5|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|      5|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (268:12): [True: 3, False: 2]
  ------------------
  269|      3|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  270|      3|		}
  271|     12|	}
  272|    120|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    120|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:6): [True: 1, False: 119]
  ------------------
  273|      1|		preferred_language[lang_length] = 0;
  274|      1|		ti->preferred_language = strdup((char *)preferred_language);
  275|      1|		if (ti->preferred_language == NULL)
  ------------------
  |  Branch (275:7): [True: 0, False: 1]
  ------------------
  276|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  277|      1|	}
  278|       |
  279|    120|	sc_init_oid(&ti->profile_indication.oid);
  280|    120|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    120|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:6): [True: 25, False: 95]
  ------------------
  281|     25|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|     25|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (281:7): [True: 1, False: 24]
  ------------------
  282|      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__
  |  |  ------------------
  ------------------
  283|      1|		}
  284|     24|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|     24|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (284:12): [True: 2, False: 22]
  ------------------
  285|      2|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  286|      2|			ti->profile_indication.name = strdup((char *)profile_indication);
  287|      2|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (287:8): [True: 0, False: 2]
  ------------------
  288|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  289|      2|		}
  290|     25|	}
  291|       |
  292|    120|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  293|    120|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  294|    120|	return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  295|    120|}
sc_pkcs15_get_lastupdate:
  541|  1.60k|{
  542|  1.60k|	struct sc_context *ctx  = p15card->card->ctx;
  543|  1.60k|	struct sc_file *file = NULL;
  544|  1.60k|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  545|  1.60k|	unsigned char *content, last_update[32] = {0};
  546|  1.60k|	size_t lupdate_len = sizeof(last_update) - 1;
  547|  1.60k|	int r, content_len;
  548|  1.60k|	size_t size;
  549|       |
  550|  1.60k|	if (p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (550:6): [True: 15, False: 1.58k]
  ------------------
  551|     15|		goto done;
  552|       |
  553|  1.58k|	if (!p15card->tokeninfo->last_update.path.len)
  ------------------
  |  Branch (553:6): [True: 1.58k, False: 3]
  ------------------
  554|  1.58k|		return NULL;
  555|       |
  556|      3|	r = sc_select_file(p15card->card, &p15card->tokeninfo->last_update.path, &file);
  557|      3|	if (r < 0)
  ------------------
  |  Branch (557:6): [True: 3, False: 0]
  ------------------
  558|      3|		return NULL;
  559|       |
  560|      0|	size = file->size ? file->size : 1024;
  ------------------
  |  Branch (560:9): [True: 0, False: 0]
  ------------------
  561|      0|	sc_file_free(file);
  562|       |
  563|      0|	content = calloc(1, size);
  564|      0|	if (!content)
  ------------------
  |  Branch (564:6): [True: 0, False: 0]
  ------------------
  565|      0|		return NULL;
  566|       |
  567|      0|	r = sc_read_binary(p15card->card, 0, content, size, 0);
  568|      0|	if (r < 0) {
  ------------------
  |  Branch (568:6): [True: 0, False: 0]
  ------------------
  569|      0|		free(content);
  570|      0|		return NULL;
  571|      0|	}
  572|      0|	content_len = r;
  573|       |
  574|      0|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  575|      0|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  576|       |
  577|      0|	r = sc_asn1_decode(ctx, asn1_last_update, content, content_len, NULL, NULL);
  578|      0|	free(content);
  579|      0|	if (r < 0)
  ------------------
  |  Branch (579:6): [True: 0, False: 0]
  ------------------
  580|      0|		return NULL;
  581|       |
  582|      0|	if (asn1_last_update[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (582:6): [True: 0, False: 0]
  ------------------
  583|      0|		p15card->tokeninfo->last_update.gtime = strdup((char *)last_update);
  584|      0|		if (!p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (584:7): [True: 0, False: 0]
  ------------------
  585|      0|			return NULL;
  586|      0|	}
  587|     15|done:
  588|     15|	sc_log(ctx, "lastUpdate.gtime '%s'", p15card->tokeninfo->last_update.gtime);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  589|     15|	return p15card->tokeninfo->last_update.gtime;
  590|      0|}
sc_pkcs15_card_new:
  719|  5.95k|{
  720|  5.95k|	struct sc_pkcs15_card *p15card;
  721|       |
  722|  5.95k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  723|  5.95k|	if (p15card == NULL)
  ------------------
  |  Branch (723:6): [True: 0, False: 5.95k]
  ------------------
  724|      0|		return NULL;
  725|       |
  726|  5.95k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  727|  5.95k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (727:6): [True: 0, False: 5.95k]
  ------------------
  728|      0|		free(p15card);
  729|      0|		return NULL;
  730|      0|	}
  731|       |
  732|  5.95k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  5.95k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  733|  5.95k|	return p15card;
  734|  5.95k|}
sc_pkcs15_tokeninfo_new:
  739|  3.77k|{
  740|  3.77k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  741|       |
  742|  3.77k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  743|  3.77k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (743:6): [True: 0, False: 3.77k]
  ------------------
  744|      0|		return NULL;
  745|      0|	}
  746|       |
  747|  3.77k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  748|       |
  749|  3.77k|	return tokeninfo;
  750|  3.77k|}
sc_pkcs15_free_tokeninfo:
  781|  10.0k|{
  782|  10.0k|	if (!tokeninfo)
  ------------------
  |  Branch (782:6): [True: 330, False: 9.72k]
  ------------------
  783|    330|		return;
  784|       |
  785|  9.72k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  786|  9.72k|	free(tokeninfo);
  787|  9.72k|}
sc_pkcs15_free_app:
  791|  17.8k|{
  792|  17.8k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (792:6): [True: 17.8k, False: 0]
  |  Branch (792:17): [True: 470, False: 17.4k]
  ------------------
  793|    470|		free(p15card->app->label);
  794|    470|		free(p15card->app->ddo.value);
  795|    470|		free(p15card->app);
  796|       |		p15card->app = NULL;
  797|    470|	}
  798|  17.8k|}
sc_pkcs15_card_free:
  803|  5.95k|{
  804|  5.95k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  5.95k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (804:6): [True: 0, False: 5.95k]
  |  Branch (804:25): [True: 0, False: 5.95k]
  ------------------
  805|      0|		return;
  806|       |
  807|  5.95k|	if (p15card->ops.clear)
  ------------------
  |  Branch (807:6): [True: 0, False: 5.95k]
  ------------------
  808|      0|		p15card->ops.clear(p15card);
  809|       |
  810|       |	/* For more complicated MD data a dedicated release procedure
  811|       |	 * has to be implemented. */
  812|  5.95k|	if (p15card->md_data)
  ------------------
  |  Branch (812:6): [True: 0, False: 5.95k]
  ------------------
  813|      0|		free(p15card->md_data);
  814|       |
  815|  5.95k|	sc_pkcs15_free_app(p15card);
  816|  5.95k|	sc_pkcs15_remove_objects(p15card);
  817|  5.95k|	sc_pkcs15_remove_dfs(p15card);
  818|  5.95k|	sc_pkcs15_free_unusedspace(p15card);
  819|  5.95k|	p15card->unusedspace_read = 0;
  820|       |
  821|  5.95k|	sc_file_free(p15card->file_app);
  822|  5.95k|	sc_file_free(p15card->file_tokeninfo);
  823|  5.95k|	sc_file_free(p15card->file_odf);
  824|  5.95k|	sc_file_free(p15card->file_unusedspace);
  825|       |
  826|  5.95k|	p15card->magic = 0;
  827|  5.95k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  828|  5.95k|	sc_pkcs15_free_app(p15card);
  829|  5.95k|	free(p15card);
  830|  5.95k|}
sc_pkcs15_card_clear:
  835|  5.82k|{
  836|  5.82k|	if (p15card == NULL)
  ------------------
  |  Branch (836:6): [True: 0, False: 5.82k]
  ------------------
  837|      0|		return;
  838|       |
  839|  5.82k|	if (p15card->ops.clear)
  ------------------
  |  Branch (839:6): [True: 0, False: 5.82k]
  ------------------
  840|      0|		p15card->ops.clear(p15card);
  841|       |
  842|  5.82k|	p15card->flags = 0;
  843|  5.82k|	p15card->tokeninfo->version = 0;
  844|  5.82k|	p15card->tokeninfo->flags   = 0;
  845|       |
  846|  5.82k|	sc_pkcs15_remove_objects(p15card);
  847|  5.82k|	sc_pkcs15_remove_dfs(p15card);
  848|       |
  849|  5.82k|	p15card->df_list = NULL;
  850|  5.82k|	sc_file_free(p15card->file_app);
  851|  5.82k|	p15card->file_app = NULL;
  852|  5.82k|	sc_file_free(p15card->file_tokeninfo);
  853|  5.82k|	p15card->file_tokeninfo = NULL;
  854|  5.82k|	sc_file_free(p15card->file_odf);
  855|  5.82k|	p15card->file_odf = NULL;
  856|  5.82k|	sc_file_free(p15card->file_unusedspace);
  857|  5.82k|	p15card->file_unusedspace = NULL;
  858|       |
  859|  5.82k|	free(p15card->tokeninfo->label);
  860|  5.82k|	p15card->tokeninfo->label = NULL;
  861|  5.82k|	free(p15card->tokeninfo->serial_number);
  862|  5.82k|	p15card->tokeninfo->serial_number = NULL;
  863|  5.82k|	free(p15card->tokeninfo->manufacturer_id);
  864|  5.82k|	p15card->tokeninfo->manufacturer_id = NULL;
  865|  5.82k|	free(p15card->tokeninfo->last_update.gtime);
  866|  5.82k|	p15card->tokeninfo->last_update.gtime = NULL;
  867|  5.82k|	free(p15card->tokeninfo->preferred_language);
  868|  5.82k|	p15card->tokeninfo->preferred_language = NULL;
  869|  5.82k|	free(p15card->tokeninfo->profile_indication.name);
  870|  5.82k|	p15card->tokeninfo->profile_indication.name = NULL;
  871|  5.82k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (871:6): [True: 6, False: 5.81k]
  ------------------
  872|      6|		size_t i;
  873|     16|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (873:15): [True: 10, False: 6]
  ------------------
  874|     10|			free(p15card->tokeninfo->seInfo[i]);
  875|      6|		free(p15card->tokeninfo->seInfo);
  876|      6|		p15card->tokeninfo->seInfo     = NULL;
  877|      6|		p15card->tokeninfo->num_seInfo = 0;
  878|      6|	}
  879|       |
  880|  5.82k|	sc_pkcs15_free_app(p15card);
  881|  5.82k|}
sc_find_app:
  886|  5.13k|{
  887|  5.13k|	int ii;
  888|       |
  889|  5.13k|	if (card->app_count <= 0)
  ------------------
  |  Branch (889:6): [True: 4.97k, False: 159]
  ------------------
  890|  4.97k|		return NULL;
  891|       |
  892|    159|	if (!aid || !aid->len)
  ------------------
  |  Branch (892:6): [True: 143, False: 16]
  |  Branch (892:14): [True: 4, False: 12]
  ------------------
  893|    147|		return card->app[0];
  894|       |
  895|     31|	for (ii=0; ii < card->app_count; ii++) {
  ------------------
  |  Branch (895:13): [True: 19, False: 12]
  ------------------
  896|     19|		if (card->app[ii]->aid.len != aid->len)
  ------------------
  |  Branch (896:7): [True: 6, False: 13]
  ------------------
  897|      6|			continue;
  898|     13|		if (memcmp(card->app[ii]->aid.value, aid->value, aid->len))
  ------------------
  |  Branch (898:7): [True: 13, False: 0]
  ------------------
  899|     13|			continue;
  900|      0|		return card->app[ii];
  901|     13|	}
  902|     12|	return NULL;
  903|     12|}
sc_pkcs15_bind_internal_odf:
  983|    436|{
  984|    436|	struct sc_path tmppath;
  985|    436|	struct sc_card    *card = p15card->card;
  986|    436|	struct sc_context *ctx = card->ctx;
  987|    436|	struct sc_pkcs15_df *df;
  988|    436|	unsigned char *buf = NULL;
  989|    436|	size_t len;
  990|    436|	int    err, ok = 0;
  991|       |
  992|    436|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    436|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    436|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    436|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    436|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 436]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  993|    436|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (993:6): [True: 436, False: 0]
  ------------------
  994|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
  995|    436|		sc_format_path("5031", &tmppath);
  996|    436|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
  997|    436|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    436|#define SC_SUCCESS				0
  ------------------
  |  Branch (997:7): [True: 0, False: 436]
  ------------------
  998|      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__
  |  |  ------------------
  ------------------
  999|      0|			goto end;
 1000|      0|		}
 1001|    436|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|    436|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1002|    436|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1003|    436|	}
 1004|      0|	else {
 1005|      0|		tmppath = p15card->file_odf->path;
 1006|      0|		sc_file_free(p15card->file_odf);
 1007|      0|		p15card->file_odf = NULL;
 1008|      0|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1009|      0|	}
 1010|       |
 1011|    436|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|    436|#define SC_SUCCESS				0
  ------------------
  |  Branch (1011:6): [True: 212, False: 224]
  ------------------
 1012|    212|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1013|    212|		goto end;
 1014|    212|	}
 1015|       |
 1016|    224|	len = p15card->file_odf->size;
 1017|    224|	if (!len) {
  ------------------
  |  Branch (1017:6): [True: 63, False: 161]
  ------------------
 1018|     63|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   71|     63|#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|     63|		goto end;
 1020|     63|	}
 1021|    161|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    161|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1021:6): [True: 2, False: 159]
  ------------------
 1022|      2|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1023|      2|		goto end;
 1024|      2|	}
 1025|    159|	buf = malloc(len);
 1026|    159|	if(buf == NULL) {
  ------------------
  |  Branch (1026:5): [True: 0, False: 159]
  ------------------
 1027|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1028|      0|		goto end;
 1029|      0|	}
 1030|       |
 1031|    159|	err = -1; /* file state: not in cache */
 1032|    159|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1032:6): [True: 123, False: 36]
  ------------------
 1033|    123|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1034|    123|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    123|#define SC_SUCCESS				0
  ------------------
  |  Branch (1034:7): [True: 24, False: 99]
  ------------------
 1035|     24|			err = (int)len;
 1036|    123|	}
 1037|    159|	if (err < 0) {
  ------------------
  |  Branch (1037:6): [True: 135, False: 24]
  ------------------
 1038|    135|		err = sc_read_binary(card, 0, buf, len, 0);
 1039|    135|		if (err < 2) {
  ------------------
  |  Branch (1039:7): [True: 42, False: 93]
  ------------------
 1040|     42|			if (err < 0) {
  ------------------
  |  Branch (1040:8): [True: 37, False: 5]
  ------------------
 1041|     37|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1042|     37|			} else {
 1043|      5|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|      5|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1044|      5|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1045|      5|			}
 1046|     42|			goto end;
 1047|     42|		}
 1048|       |		/* sc_read_binary may return less than requested */
 1049|     93|		len = err;
 1050|       |
 1051|     93|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1051:7): [True: 77, False: 16]
  ------------------
 1052|     77|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1053|     77|		}
 1054|     93|	}
 1055|       |
 1056|    117|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1056:6): [True: 43, False: 74]
  ------------------
 1057|     43|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     43|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1058|     43|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1059|     43|		goto end;
 1060|     43|	}
 1061|     74|	free(buf);
 1062|     74|	buf = NULL;
 1063|       |
 1064|     74|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1065|    334|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1065:30): [True: 260, False: 74]
  ------------------
 1066|    260|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   71|    334|#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|     74|				sc_print_path(&df->path), df->path.index, df->path.count);
 1068|       |
 1069|     74|	ok = 1;
 1070|    436|end:
 1071|    436|	if (buf != NULL)
  ------------------
  |  Branch (1071:6): [True: 85, False: 351]
  ------------------
 1072|     85|		free(buf);
 1073|    436|	if (!ok) {
  ------------------
  |  Branch (1073:6): [True: 362, False: 74]
  ------------------
 1074|    362|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|    362|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    362|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    362|	int _ret = r; \
  |  |  |  |  155|    362|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 362, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    362|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    297|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 297, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  157|    362|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    362|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    362|	return _ret; \
  |  |  |  |  163|    362|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1075|    362|	}
 1076|       |
 1077|     74|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     74|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     74|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     74|	int _ret = r; \
  |  |  |  |  155|     74|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 74, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     74|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  157|     74|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     74|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     74|	return _ret; \
  |  |  |  |  163|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1078|     74|}
sc_pkcs15_bind_internal_tokeninfo:
 1082|  4.94k|{
 1083|  4.94k|	struct sc_path tmppath;
 1084|  4.94k|	struct sc_card *card = p15card->card;
 1085|  4.94k|	struct sc_context *ctx = card->ctx;
 1086|  4.94k|	struct sc_pkcs15_tokeninfo tokeninfo;
 1087|  4.94k|	unsigned char *buf = NULL;
 1088|  4.94k|	size_t len;
 1089|  4.94k|	int err, ok = 0;
 1090|       |
 1091|  4.94k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.94k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.94k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.94k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.94k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.94k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1092|       |
 1093|  4.94k|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1093:6): [True: 4.94k, False: 0]
  ------------------
 1094|  4.94k|		sc_format_path("5032", &tmppath);
 1095|  4.94k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1096|  4.94k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  4.94k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1096:7): [True: 1, False: 4.94k]
  ------------------
 1097|      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__
  |  |  ------------------
  ------------------
 1098|      1|			goto end;
 1099|      1|		}
 1100|  4.94k|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1101|  4.94k|	}
 1102|      0|	else {
 1103|      0|		tmppath = p15card->file_tokeninfo->path;
 1104|      0|		sc_file_free(p15card->file_tokeninfo);
 1105|      0|		p15card->file_tokeninfo = NULL;
 1106|      0|	}
 1107|       |
 1108|  4.94k|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1109|  4.94k|	if (err)   {
  ------------------
  |  Branch (1109:6): [True: 4.26k, False: 684]
  ------------------
 1110|  4.26k|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   71|  4.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1111|  4.26k|		goto end;
 1112|  4.26k|	}
 1113|       |
 1114|    684|	len = p15card->file_tokeninfo->size;
 1115|    684|	if (!len) {
  ------------------
  |  Branch (1115:6): [True: 276, False: 408]
  ------------------
 1116|    276|		sc_log(ctx, "EF(TokenInfo) is empty");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1117|    276|		goto end;
 1118|    276|	}
 1119|    408|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    408|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1119:6): [True: 55, False: 353]
  ------------------
 1120|     55|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1121|     55|		goto end;
 1122|     55|	}
 1123|    353|	buf = malloc(len);
 1124|    353|	if(buf == NULL) {
  ------------------
  |  Branch (1124:5): [True: 0, False: 353]
  ------------------
 1125|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1126|      0|		goto end;
 1127|      0|	}
 1128|       |
 1129|    353|	err = -1; /* file state: not in cache */
 1130|    353|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1130:6): [True: 163, False: 190]
  ------------------
 1131|    163|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1132|    163|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    163|#define SC_SUCCESS				0
  ------------------
  |  Branch (1132:7): [True: 0, False: 163]
  ------------------
 1133|      0|			err = (int)len;
 1134|    163|	}
 1135|    353|	if (err < 0) {
  ------------------
  |  Branch (1135:6): [True: 353, False: 0]
  ------------------
 1136|    353|		err = sc_read_binary(card, 0, buf, len, 0);
 1137|    353|		if (err <= 2) {
  ------------------
  |  Branch (1137:7): [True: 127, False: 226]
  ------------------
 1138|    127|			if (err < 0)   {
  ------------------
  |  Branch (1138:8): [True: 110, False: 17]
  ------------------
 1139|    110|				sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1140|    110|			} else {
 1141|     17|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     17|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1142|     17|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1143|     17|			}
 1144|    127|			goto end;
 1145|    127|		}
 1146|       |		/* sc_read_binary may return less than requested */
 1147|    226|		len = err;
 1148|       |
 1149|    226|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1149:7): [True: 135, False: 91]
  ------------------
 1150|    135|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1151|    135|		}
 1152|    226|	}
 1153|       |
 1154|    226|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1155|    226|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1156|    226|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    226|#define SC_SUCCESS				0
  ------------------
  |  Branch (1156:6): [True: 121, False: 105]
  ------------------
 1157|    121|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1158|    121|		goto end;
 1159|    121|	}
 1160|       |
 1161|    105|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1162|    105|	*(p15card->tokeninfo) = tokeninfo;
 1163|       |
 1164|    105|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1164:6): [True: 2, False: 103]
  |  Branch (1164:44): [True: 2, False: 0]
  ------------------
 1165|      2|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1166|      2|	}
 1167|       |
 1168|    105|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1168:6): [True: 2, False: 103]
  |  Branch (1168:44): [True: 1, False: 1]
  ------------------
 1169|      1|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1170|      1|		size_t ii;
 1171|      1|		if (!serial) {
  ------------------
  |  Branch (1171:7): [True: 0, False: 1]
  ------------------
 1172|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1173|      0|			goto end;
 1174|      0|		}
 1175|       |
 1176|     11|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1176:12): [True: 10, False: 1]
  ------------------
 1177|     10|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1178|       |
 1179|      1|		p15card->tokeninfo->serial_number = serial;
 1180|      1|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1181|      1|	}
 1182|       |
 1183|    105|	ok = 1;
 1184|  4.94k|end:
 1185|  4.94k|	if (buf != NULL)
  ------------------
  |  Branch (1185:6): [True: 353, False: 4.59k]
  ------------------
 1186|    353|		free(buf);
 1187|  4.94k|	if (!ok) {
  ------------------
  |  Branch (1187:6): [True: 4.84k, False: 105]
  ------------------
 1188|  4.84k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  4.84k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.84k|	int _ret = r; \
  |  |  |  |  155|  4.84k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.50k, False: 331]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.84k|	} else { \
  |  |  |  |  159|      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.84k|	return _ret; \
  |  |  |  |  163|  4.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|  4.84k|	}
 1190|       |
 1191|    105|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    105|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    105|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    105|	int _ret = r; \
  |  |  |  |  155|    105|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 105, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    105|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 105]
  |  |  |  |  ------------------
  |  |  |  |  157|    105|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    105|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    105|	return _ret; \
  |  |  |  |  163|    105|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1192|    105|}
sc_pkcs15_bind_internal:
 1196|  5.13k|{
 1197|  5.13k|	struct sc_card *card = p15card->card;
 1198|  5.13k|	struct sc_context *ctx = card->ctx;
 1199|  5.13k|	const struct sc_app_info *info = NULL;
 1200|  5.13k|	int err, ok = 0;
 1201|       |
 1202|  5.13k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.13k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.13k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.13k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.13k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.13k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|       |	/* Enumerate apps now */
 1204|  5.13k|	if (card->app_count < 0) {
  ------------------
  |  Branch (1204:6): [True: 4.82k, False: 310]
  ------------------
 1205|  4.82k|		err = sc_enum_apps(card);
 1206|  4.82k|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|  4.82k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1206:7): [True: 4.61k, False: 212]
  ------------------
 1207|  4.61k|			sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(err));
  ------------------
  |  |   71|  4.61k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1208|  4.82k|	}
 1209|  5.13k|	sc_file_free(p15card->file_app);
 1210|  5.13k|	p15card->file_app = sc_file_new();
 1211|  5.13k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (1211:6): [True: 0, False: 5.13k]
  ------------------
 1212|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1213|      0|		goto end;
 1214|      0|	}
 1215|       |
 1216|  5.13k|	sc_format_path("3F005015", &p15card->file_app->path);
 1217|       |
 1218|  5.13k|	info = sc_find_app(card, aid);
 1219|  5.13k|	if (info) {
  ------------------
  |  Branch (1219:6): [True: 147, False: 4.98k]
  ------------------
 1220|    147|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|    147|#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|    147|		sc_pkcs15_free_app(p15card);
 1222|    147|		p15card->app = sc_dup_app_info(info);
 1223|    147|		if (!p15card->app) {
  ------------------
  |  Branch (1223:7): [True: 0, False: 147]
  ------------------
 1224|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1225|      0|			goto end;
 1226|      0|		}
 1227|       |
 1228|    147|		if (info->path.len)
  ------------------
  |  Branch (1228:7): [True: 131, False: 16]
  ------------------
 1229|    131|			p15card->file_app->path = info->path;
 1230|       |
 1231|    147|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1231:7): [True: 23, False: 124]
  |  Branch (1231:26): [True: 19, False: 4]
  ------------------
 1232|     19|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1233|       |
 1234|  4.98k|	} else if (aid) {
  ------------------
  |  Branch (1234:13): [True: 95, False: 4.89k]
  ------------------
 1235|     95|		sc_log(ctx, "Application '%s' not found", sc_dump_hex(aid->value, aid->len));
  ------------------
  |  |   71|     95|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1236|     95|		err = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     95|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1237|     95|		goto end;
 1238|     95|	}
 1239|  5.03k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
 1240|       |
 1241|       |	/* Check if pkcs15 directory exists */
 1242|  5.03k|	err = sc_select_file(card, &p15card->file_app->path, NULL);
 1243|       |
 1244|       |	/* If the above test failed on cards without EF(DIR),
 1245|       |	 * try to continue read ODF from 3F005031. -aet
 1246|       |	 */
 1247|  5.03k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  5.03k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1247:6): [True: 4.05k, False: 987]
  |  Branch (1247:29): [True: 3.95k, False: 92]
  ------------------
 1248|  3.95k|		sc_format_path("3F00", &p15card->file_app->path);
 1249|  3.95k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  3.95k|#define SC_SUCCESS				0
  ------------------
 1250|  3.95k|	}
 1251|       |
 1252|  5.03k|	if (err < 0) {
  ------------------
  |  Branch (1252:6): [True: 92, False: 4.94k]
  ------------------
 1253|     92|		sc_log(ctx, "Cannot select application path");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1254|     92|		goto end;
 1255|     92|	}
 1256|       |
 1257|  4.94k|	err = sc_pkcs15_bind_internal_tokeninfo(p15card);
 1258|  4.94k|	if (err < 0) {
  ------------------
  |  Branch (1258:6): [True: 4.50k, False: 436]
  ------------------
 1259|  4.50k|		sc_log(ctx, "Cannot bind tokeninfo");
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 1260|  4.50k|		goto end;
 1261|  4.50k|	}
 1262|       |
 1263|    436|	err = sc_pkcs15_bind_internal_odf(p15card);
 1264|    436|	if (err < 0) {
  ------------------
  |  Branch (1264:6): [True: 297, False: 139]
  ------------------
 1265|    297|		sc_log(ctx, "Cannot bind ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1266|    297|		goto end;
 1267|    297|	}
 1268|       |
 1269|    139|	ok = 1;
 1270|  5.13k|end:
 1271|  5.13k|	if (!ok) {
  ------------------
  |  Branch (1271:6): [True: 4.99k, False: 139]
  ------------------
 1272|  4.99k|		sc_pkcs15_card_clear(p15card);
 1273|  4.99k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  4.99k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1273:7): [True: 823, False: 4.17k]
  ------------------
 1274|    823|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    823|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1275|  4.99k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  4.99k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.99k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.99k|	int _ret = r; \
  |  |  |  |  155|  4.99k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.99k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.99k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.99k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.99k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.99k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.99k|	} else { \
  |  |  |  |  159|      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.99k|	return _ret; \
  |  |  |  |  163|  4.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1276|  4.99k|	}
 1277|       |
 1278|    139|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    139|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    139|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    139|	int _ret = r; \
  |  |  |  |  155|    139|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 139, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    139|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 139]
  |  |  |  |  ------------------
  |  |  |  |  157|    139|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    139|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    139|	return _ret; \
  |  |  |  |  163|    139|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1279|    139|}
pkcs15_get_default_use_file_cache:
 1282|  5.95k|{
 1283|       |	/* enable file caching by default for cards with static content to avoid
 1284|       |	 * synchronization problems.
 1285|       |	 *
 1286|       |	 * The following list was initialized with the cards that can't be modified
 1287|       |	 * with OpenSC i.e. which don't have a profile/driver for pkcs15-init. */
 1288|  5.95k|	const char *card_drivers_with_file_cache[] = {
 1289|  5.95k|			"atrust-acos",
 1290|  5.95k|			"belpic",
 1291|  5.95k|			"cac1",
 1292|  5.95k|			"cac",
 1293|  5.95k|			"cedulauy",
 1294|  5.95k|			"coolkey",
 1295|  5.95k|			"edo",
 1296|  5.95k|			"esteid2018",
 1297|  5.95k|			"esteid2025",
 1298|  5.95k|			"flex",
 1299|  5.95k|			"cyberflex",
 1300|  5.95k|			"gemsafeV1",
 1301|  5.95k|			"idprime",
 1302|  5.95k|			"itacns",
 1303|  5.95k|			"jpki",
 1304|  5.95k|			"MaskTech",
 1305|  5.95k|			"mcrd",
 1306|  5.95k|			"myeid",
 1307|  5.95k|			"npa",
 1308|  5.95k|			"nqapplet",
 1309|  5.95k|			"tcos",
 1310|  5.95k|			"dtrust",
 1311|  5.95k|			"lteid",
 1312|  5.95k|	};
 1313|       |
 1314|  5.95k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1314:6): [True: 0, False: 5.95k]
  |  Branch (1314:22): [True: 0, False: 5.95k]
  |  Branch (1314:46): [True: 0, False: 5.95k]
  ------------------
 1315|      0|		return "no";
 1316|   110k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1316:21): [True: 107k, False: 3.34k]
  ------------------
 1317|   107k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1317:7): [True: 2.61k, False: 104k]
  ------------------
 1318|  2.61k|			return "public";
 1319|   107k|	}
 1320|       |
 1321|  3.34k|	return "no";
 1322|  5.95k|}
sc_pkcs15_bind:
 1327|  5.95k|{
 1328|  5.95k|	struct sc_pkcs15_card *p15card = NULL;
 1329|  5.95k|	struct sc_context *ctx;
 1330|  5.95k|	scconf_block *conf_block = NULL;
 1331|  5.95k|	int r, emu_first, enable_emu;
 1332|  5.95k|	const char *use_file_cache;
 1333|  5.95k|	const char *pin_protected_certificate, *private_certificate;
 1334|       |
 1335|  5.95k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1335:6): [True: 0, False: 5.95k]
  |  Branch (1335:22): [True: 0, False: 5.95k]
  ------------------
 1336|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1337|      0|	}
 1338|  5.95k|	ctx = card->ctx;
 1339|       |
 1340|  5.95k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.95k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.95k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.95k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.95k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.95k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|  5.95k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 125, False: 5.83k]
  |  |  ------------------
  ------------------
 1342|       |
 1343|  5.95k|	p15card = sc_pkcs15_card_new();
 1344|  5.95k|	if (p15card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 5.95k]
  ------------------
 1345|  5.95k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|       |
 1347|  5.95k|	p15card->card = card;
 1348|  5.95k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  5.95k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1349|  5.95k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1350|  5.95k|	p15card->opts.use_pin_cache = 1;
 1351|  5.95k|	p15card->opts.pin_cache_counter = 10;
 1352|  5.95k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1353|  5.95k|	pin_protected_certificate = "protect";
 1354|  5.95k|	private_certificate = "";
 1355|       |
 1356|  5.95k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1357|  5.95k|	if (conf_block) {
  ------------------
  |  Branch (1357:6): [True: 0, False: 5.95k]
  ------------------
 1358|      0|		use_file_cache = scconf_get_str(conf_block, "use_file_caching", use_file_cache);
 1359|      0|		p15card->opts.use_pin_cache = scconf_get_bool(conf_block, "use_pin_caching", p15card->opts.use_pin_cache);
 1360|      0|		p15card->opts.pin_cache_counter = scconf_get_int(conf_block, "pin_cache_counter", p15card->opts.pin_cache_counter);
 1361|      0|		p15card->opts.pin_cache_ignore_user_consent = scconf_get_bool(conf_block, "pin_cache_ignore_user_consent",
 1362|      0|				p15card->opts.pin_cache_ignore_user_consent);
 1363|      0|		pin_protected_certificate = scconf_get_str(conf_block, "pin_protected_certificate", pin_protected_certificate);
 1364|       |		/* read also the old value to keep backward compatibility */
 1365|      0|		private_certificate = scconf_get_str(conf_block, "private_certificate", private_certificate);
 1366|      0|	}
 1367|       |
 1368|  5.95k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1368:6): [True: 0, False: 5.95k]
  ------------------
 1369|      0|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_ALL_FILES;
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
 1370|  5.95k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1370:13): [True: 2.61k, False: 3.34k]
  ------------------
 1371|  2.61k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  2.61k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1372|  3.34k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1372:13): [True: 3.34k, False: 0]
  ------------------
 1373|  3.34k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  3.34k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1374|  3.34k|	}
 1375|       |
 1376|  5.95k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1376:6): [True: 5.95k, False: 0]
  ------------------
 1377|  5.95k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  5.95k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1378|  5.95k|	} else if (0 == strcmp(pin_protected_certificate, "ignore")) {
  ------------------
  |  Branch (1378:13): [True: 0, False: 0]
  ------------------
 1379|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1380|      0|	} else if (0 == strcmp(pin_protected_certificate, "declassify")) {
  ------------------
  |  Branch (1380:13): [True: 0, False: 0]
  ------------------
 1381|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1382|      0|	}
 1383|       |	/* overwrite pin_protected_certificate when private_certificate set */
 1384|  5.95k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1384:6): [True: 0, False: 5.95k]
  ------------------
 1385|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1386|  5.95k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1386:13): [True: 0, False: 5.95k]
  ------------------
 1387|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1388|  5.95k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1388:13): [True: 0, False: 5.95k]
  ------------------
 1389|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1390|      0|	}
 1391|  5.95k|	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|  5.95k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1392|  5.95k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1393|  5.95k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1394|       |
 1395|  5.95k|	r = sc_lock(card);
 1396|  5.95k|	if (r) {
  ------------------
  |  Branch (1396:6): [True: 0, False: 5.95k]
  ------------------
 1397|      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__
  |  |  ------------------
  ------------------
 1398|      0|		sc_pkcs15_card_free(p15card);
 1399|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1400|      0|	}
 1401|       |
 1402|  5.95k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1403|  5.95k|	if (enable_emu) {
  ------------------
  |  Branch (1403:6): [True: 5.95k, False: 0]
  ------------------
 1404|  5.95k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  5.95k|#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|  5.95k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1406|  5.95k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1406:7): [True: 0, False: 5.95k]
  |  Branch (1406:20): [True: 1.72k, False: 4.23k]
  ------------------
 1407|  1.72k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1408|  1.72k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  1.72k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1408:8): [True: 1.13k, False: 588]
  ------------------
 1409|  1.13k|				goto done;
 1410|    588|			r = sc_pkcs15_bind_internal(p15card, aid);
 1411|    588|			if (r < 0)
  ------------------
  |  Branch (1411:8): [True: 585, False: 3]
  ------------------
 1412|    585|				goto error;
 1413|  4.23k|		} else {
 1414|  4.23k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1415|  4.23k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  4.23k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1415:8): [True: 132, False: 4.09k]
  ------------------
 1416|    132|				goto done;
 1417|  4.09k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1418|  4.09k|			if (r < 0)
  ------------------
  |  Branch (1418:8): [True: 2.83k, False: 1.26k]
  ------------------
 1419|  2.83k|				goto error;
 1420|  4.09k|		}
 1421|  5.95k|	}
 1422|      0|	else {
 1423|      0|		r = sc_pkcs15_bind_internal(p15card, aid);
 1424|      0|		if (r < 0)
  ------------------
  |  Branch (1424:7): [True: 0, False: 0]
  ------------------
 1425|      0|			goto error;
 1426|      0|	}
 1427|  2.53k|done:
 1428|  2.53k|	*p15card_out = p15card;
 1429|  2.53k|	sc_unlock(card);
 1430|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1431|  3.42k|error:
 1432|  3.42k|	sc_unlock(card);
 1433|  3.42k|	sc_pkcs15_card_free(p15card);
 1434|  3.42k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  3.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.42k|	int _ret = r; \
  |  |  |  |  155|  3.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.42k|	return _ret; \
  |  |  |  |  163|  3.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1435|  3.42k|}
sc_pkcs15_unbind:
 1440|  8.50k|{
 1441|  8.50k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC) {
  ------------------
  |  |  519|  2.53k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (1441:6): [True: 5.96k, False: 2.53k]
  |  Branch (1441:25): [True: 0, False: 2.53k]
  ------------------
 1442|  5.96k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  5.96k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1443|  5.96k|	}
 1444|       |
 1445|  2.53k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  2.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1446|  2.53k|	if (p15card->dll_handle)
  ------------------
  |  Branch (1446:6): [True: 0, False: 2.53k]
  ------------------
 1447|      0|		sc_dlclose(p15card->dll_handle);
 1448|  2.53k|	sc_pkcs15_pincache_clear(p15card);
 1449|  2.53k|	sc_pkcs15_card_free(p15card);
 1450|  2.53k|	return 0;
 1451|  8.50k|}
sc_pkcs15_get_objects:
 1539|  9.71k|{
 1540|  9.71k|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1541|  9.71k|}
sc_pkcs15_get_objects_cond:
 1734|  9.71k|{
 1735|  9.71k|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1736|  9.71k|			func, func_arg, ret, ret_size);
 1737|  9.71k|}
sc_pkcs15_find_object_by_id:
 1743|    366|{
 1744|    366|	struct sc_pkcs15_search_key sk;
 1745|    366|	int	r;
 1746|       |
 1747|    366|	memset(&sk, 0, sizeof(sk));
 1748|    366|	sk.id = id;
 1749|       |
 1750|    366|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1751|    366|	if (r < 0)
  ------------------
  |  Branch (1751:6): [True: 0, False: 366]
  ------------------
 1752|      0|		return r;
 1753|    366|	if (r == 0)
  ------------------
  |  Branch (1753:6): [True: 270, False: 96]
  ------------------
 1754|    270|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    270|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1755|     96|	return 0;
 1756|    366|}
sc_pkcs15_find_cert_by_id:
 1762|     29|{
 1763|     29|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|     29|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1764|     29|}
sc_pkcs15_find_pubkey_by_id:
 1778|     29|{
 1779|     29|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_PUBKEY, id, out);
  ------------------
  |  |  425|     29|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
 1780|     29|}
sc_pkcs15_find_pin_by_auth_id:
 1794|    308|{
 1795|    308|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|    308|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1796|    308|}
sc_pkcs15_add_object:
 1986|  25.4k|{
 1987|  25.4k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1988|       |
 1989|  25.4k|	if (!obj)
  ------------------
  |  Branch (1989:6): [True: 0, False: 25.4k]
  ------------------
 1990|      0|		return 0;
 1991|  25.4k|	obj->next = obj->prev = NULL;
 1992|  25.4k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1992:6): [True: 2.31k, False: 23.1k]
  ------------------
 1993|  2.31k|		p15card->obj_list = obj;
 1994|  2.31k|		return 0;
 1995|  2.31k|	}
 1996|   212k|	while (p->next != NULL)
  ------------------
  |  Branch (1996:9): [True: 189k, False: 23.1k]
  ------------------
 1997|   189k|		p = p->next;
 1998|  23.1k|	p->next = obj;
 1999|  23.1k|	obj->prev = p;
 2000|       |
 2001|  23.1k|	return 0;
 2002|  25.4k|}
sc_pkcs15_free_object:
 2037|  25.4k|{
 2038|  25.4k|	if (!obj)
  ------------------
  |  Branch (2038:6): [True: 0, False: 25.4k]
  ------------------
 2039|      0|		return;
 2040|  25.4k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  25.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 2041|    457|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|    457|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2041:2): [True: 457, False: 25.0k]
  ------------------
 2042|    457|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 2043|    457|		break;
 2044|    186|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|    186|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2044:2): [True: 186, False: 25.2k]
  ------------------
 2045|       |		/* This is normally passed to framework-pkcs15,
 2046|       |		 * but if something fails on the way, it would not get freed */
 2047|    186|		if (obj->emulated) {
  ------------------
  |  Branch (2047:7): [True: 148, False: 38]
  ------------------
 2048|    148|			sc_pkcs15_free_pubkey(obj->emulated);
 2049|    148|		}
 2050|    186|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 2051|    186|		break;
 2052|    767|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|    767|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (2052:2): [True: 767, False: 24.6k]
  ------------------
 2053|    767|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 2054|    767|		break;
 2055|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2055:2): [True: 0, False: 25.4k]
  ------------------
 2056|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2057|      0|		break;
 2058|  20.6k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  20.6k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2058:2): [True: 20.6k, False: 4.77k]
  ------------------
 2059|  20.6k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2060|  20.6k|		break;
 2061|  3.36k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  3.36k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2061:2): [True: 3.36k, False: 22.0k]
  ------------------
 2062|  3.36k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2063|  3.36k|		break;
 2064|      0|	default:
  ------------------
  |  Branch (2064:2): [True: 0, False: 25.4k]
  ------------------
 2065|      0|		free(obj->data);
 2066|  25.4k|	}
 2067|       |
 2068|  25.4k|	sc_pkcs15_free_object_content(obj);
 2069|       |
 2070|  25.4k|	free(obj);
 2071|  25.4k|}
sc_pkcs15_add_df:
 2076|  4.87k|{
 2077|  4.87k|	struct sc_pkcs15_df *p, *newdf;
 2078|       |
 2079|  4.87k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2080|  4.87k|	if (newdf == NULL)
  ------------------
  |  Branch (2080:6): [True: 0, False: 4.87k]
  ------------------
 2081|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2082|  4.87k|	newdf->path = *path;
 2083|  4.87k|	newdf->type = type;
 2084|       |
 2085|  4.87k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2085:6): [True: 2.39k, False: 2.48k]
  ------------------
 2086|  2.39k|		p15card->df_list = newdf;
 2087|  2.39k|		return 0;
 2088|  2.39k|	}
 2089|       |
 2090|  2.48k|	p = p15card->df_list;
 2091|  4.22k|	while (p->next != NULL)
  ------------------
  |  Branch (2091:9): [True: 1.73k, False: 2.48k]
  ------------------
 2092|  1.73k|		p = p->next;
 2093|  2.48k|	p->next = newdf;
 2094|  2.48k|	newdf->prev = p;
 2095|       |
 2096|  2.48k|	return 0;
 2097|  4.87k|}
sc_pkcs15_parse_df:
 2192|    293|{
 2193|    293|	struct sc_context *ctx = p15card->card->ctx;
 2194|    293|	unsigned char *buf;
 2195|    293|	const unsigned char *p;
 2196|    293|	size_t bufsize;
 2197|    293|	int r;
 2198|    293|	struct sc_pkcs15_object *obj = NULL;
 2199|    293|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2200|    293|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2201|       |
 2202|    293|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|    293|#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|    293|	if (df->enumerated)
  ------------------
  |  Branch (2204:6): [True: 0, False: 293]
  ------------------
 2205|    293|		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|    293|	switch (df->type) {
  ------------------
  |  Branch (2207:10): [True: 292, False: 1]
  ------------------
 2208|     70|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|     70|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2208:2): [True: 70, False: 223]
  ------------------
 2209|     70|		func = sc_pkcs15_decode_prkdf_entry;
 2210|     70|		break;
 2211|     26|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|     26|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2211:2): [True: 26, False: 267]
  ------------------
 2212|     26|		func = sc_pkcs15_decode_pukdf_entry;
 2213|     26|		break;
 2214|     19|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|     19|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2214:2): [True: 19, False: 274]
  ------------------
 2215|     19|		func = sc_pkcs15_decode_skdf_entry;
 2216|     19|		break;
 2217|     31|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|     31|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2217:2): [True: 31, False: 262]
  ------------------
 2218|     63|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|     63|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2218:2): [True: 32, False: 261]
  ------------------
 2219|     80|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|     80|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2219:2): [True: 17, False: 276]
  ------------------
 2220|     80|		func = sc_pkcs15_decode_cdf_entry;
 2221|     80|		break;
 2222|     43|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|     43|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2222:2): [True: 43, False: 250]
  ------------------
 2223|     43|		func = sc_pkcs15_decode_dodf_entry;
 2224|     43|		break;
 2225|     54|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|     54|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2225:2): [True: 54, False: 239]
  ------------------
 2226|     54|		func = sc_pkcs15_decode_aodf_entry;
 2227|     54|		break;
 2228|    293|	}
 2229|    293|	if (func == NULL) {
  ------------------
  |  Branch (2229:6): [True: 1, False: 292]
  ------------------
 2230|      1|		sc_log(ctx, "unknown DF type: %d", df->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2231|      1|		LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2232|      1|	}
 2233|    292|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2234|    292|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|    292|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    292|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    292|	int _ret = (r); \
  |  |  |  |  168|    292|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 230, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  169|    230|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    230|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    230|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    230|		return _ret; \
  |  |  |  |  172|    230|	} \
  |  |  |  |  173|    292|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2235|       |
 2236|     62|	p = buf;
 2237|     70|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2237:9): [True: 69, False: 1]
  |  Branch (2237:20): [True: 68, False: 1]
  ------------------
 2238|       |
 2239|     68|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2240|     68|		if (obj == NULL) {
  ------------------
  |  Branch (2240:7): [True: 0, False: 68]
  ------------------
 2241|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2242|      0|			goto ret;
 2243|      0|		}
 2244|     68|		r = func(p15card, obj, &p, &bufsize);
 2245|     68|		if (r) {
  ------------------
  |  Branch (2245:7): [True: 60, False: 8]
  ------------------
 2246|     60|			free(obj);
 2247|     60|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|     60|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2247:8): [True: 27, False: 33]
  ------------------
 2248|     27|				r = 0;
 2249|     27|				break;
 2250|     27|			}
 2251|     33|			sc_log(ctx, "%s: Error decoding DF entry", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2252|     33|			goto ret;
 2253|     60|		}
 2254|       |
 2255|      8|		obj->df = df;
 2256|      8|		r = sc_pkcs15_add_object(p15card, obj);
 2257|      8|		if (r) {
  ------------------
  |  Branch (2257:7): [True: 0, False: 8]
  ------------------
 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|    131|		while (bufsize > 0 && *p == 00) {
  ------------------
  |  Branch (2264:10): [True: 131, False: 0]
  |  Branch (2264:25): [True: 123, False: 8]
  ------------------
 2265|    123|			bufsize--;
 2266|    123|			p++;
 2267|    123|		}
 2268|     29|	};
 2269|       |
 2270|     29|	if (r > 0)
  ------------------
  |  Branch (2270:6): [True: 0, False: 29]
  ------------------
 2271|      0|		r = 0;
 2272|     62|ret:
 2273|     62|	df->enumerated = 1;
 2274|     62|	free(buf);
 2275|     62|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 29]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|     62|}
sc_pkcs15_read_file:
 2528|  18.0k|{
 2529|  18.0k|	struct sc_context *ctx;
 2530|  18.0k|	struct sc_file *file = NULL;
 2531|  18.0k|	unsigned char *data = NULL;
 2532|  18.0k|	size_t	len = 0, offset = 0;
 2533|  18.0k|	int	r;
 2534|       |
 2535|  18.0k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2535:6): [True: 0, False: 18.0k]
  |  Branch (2535:25): [True: 0, False: 18.0k]
  |  Branch (2535:50): [True: 0, False: 18.0k]
  |  Branch (2535:69): [True: 0, False: 18.0k]
  ------------------
 2536|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2537|      0|	}
 2538|  18.0k|	ctx = p15card->card->ctx;
 2539|       |
 2540|  18.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  18.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2541|  18.0k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2542|       |
 2543|  18.0k|	r = -1; /* file state: not in cache */
 2544|  18.0k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2544:6): [True: 3.57k, False: 14.5k]
  ------------------
 2545|  3.57k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  3.57k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2545:10): [True: 0, False: 3.57k]
  |  Branch (2545:77): [True: 3.51k, False: 60]
  ------------------
 2546|  3.51k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2547|       |
 2548|  3.51k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2548:7): [True: 97, False: 3.41k]
  |  Branch (2548:13): [True: 4, False: 93]
  |  Branch (2548:37): [True: 4, False: 0]
  ------------------
 2549|      4|			struct sc_path parent = *in_path;
 2550|       |
 2551|      4|			parent.len -= 2;
 2552|      4|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|      4|#define SC_PATH_TYPE_PATH		2
  ------------------
 2553|      4|			r = sc_select_file(p15card->card, &parent, NULL);
 2554|      4|		}
 2555|  3.51k|	}
 2556|       |
 2557|  18.0k|	if (r) {
  ------------------
  |  Branch (2557:6): [True: 18.0k, False: 93]
  ------------------
 2558|  18.0k|		r = sc_lock(p15card->card);
 2559|  18.0k|		if (r)
  ------------------
  |  Branch (2559:7): [True: 0, False: 18.0k]
  ------------------
 2560|      0|			goto fail;
 2561|  18.0k|		r = sc_select_file(p15card->card, in_path, &file);
 2562|  18.0k|		if (r)
  ------------------
  |  Branch (2562:7): [True: 15.4k, False: 2.60k]
  ------------------
 2563|  15.4k|			goto fail_unlock;
 2564|       |
 2565|       |		/* Handle the case where the ASN.1 Path object specified
 2566|       |		 * index and length values */
 2567|       |
 2568|  2.60k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  2.60k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2568:7): [True: 32, False: 2.57k]
  ------------------
 2569|       |
 2570|       |			// in_path->index: record_no
 2571|       |			// in_path->count: ignored!
 2572|       |
 2573|     32|			if(file->record_length > 0) {
  ------------------
  |  Branch (2573:7): [True: 25, False: 7]
  ------------------
 2574|     25|				if(file->record_length > MAX_FILE_SIZE) {
  ------------------
  |  |  220|     25|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2574:8): [True: 0, False: 25]
  ------------------
 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|     25|				} else {
 2578|     25|					len = file->record_length;
 2579|     25|				}
 2580|     25|			} else {
 2581|      7|				len = MAX_FILE_SIZE;
  ------------------
  |  |  220|      7|#define MAX_FILE_SIZE 65535
  ------------------
 2582|      7|			}
 2583|       |
 2584|     32|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2584:8): [True: 26, False: 6]
  |  Branch (2584:33): [True: 1, False: 5]
  ------------------
 2585|     27|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2586|     27|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     27|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2587|     27|				goto fail_unlock;
 2588|     27|			}
 2589|       |
 2590|  2.57k|		} else {
 2591|       |
 2592|  2.57k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2592:8): [True: 1.87k, False: 693]
  ------------------
 2593|  1.87k|				if (file->size)
  ------------------
  |  Branch (2593:9): [True: 1.67k, False: 207]
  ------------------
 2594|  1.67k|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|  1.67k|#define MAX_FILE_SIZE 65535
  ------------------
              					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|      3|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2594:12): [True: 3, False: 1.66k]
  ------------------
 2595|    207|				else
 2596|    207|					len = 1024;
 2597|  1.87k|				offset = 0;
 2598|  1.87k|			}
 2599|    693|			else {
 2600|    693|				offset = in_path->index;
 2601|    693|				len = in_path->count;
 2602|       |				/* Make sure we're within proper bounds */
 2603|    693|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2603:9): [True: 7, False: 686]
  |  Branch (2603:33): [True: 16, False: 670]
  ------------------
 2604|     23|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     23|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2605|     23|					goto fail_unlock;
 2606|     23|				}
 2607|    693|			}
 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: 113, False: 2.44k]
  ------------------
 2618|    113|			unsigned int i;
 2619|    113|			size_t l, record_len;
 2620|    113|			unsigned char *head = data;
 2621|       |
 2622|  1.86k|			for (i=1; ; i++) {
 2623|  1.86k|				l = len - (head - data);
 2624|  1.86k|				if (l > 256) {
  ------------------
  |  Branch (2624:9): [True: 1.45k, False: 416]
  ------------------
 2625|  1.45k|					l = 256;
 2626|  1.45k|				}
 2627|  1.86k|				r = sc_read_record(p15card->card, i, 0, head, l, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  1.86k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2628|  1.86k|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.86k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2628:9): [True: 1, False: 1.86k]
  ------------------
 2629|      1|					break;
 2630|  1.86k|				if (r < 0) {
  ------------------
  |  Branch (2630:9): [True: 89, False: 1.77k]
  ------------------
 2631|     89|					goto fail_unlock;
 2632|     89|				}
 2633|  1.77k|				if (r < 2)
  ------------------
  |  Branch (2633:9): [True: 22, False: 1.75k]
  ------------------
 2634|     22|					break;
 2635|  1.75k|				record_len = head[1];
 2636|  1.75k|				if (record_len != 0xff) {
  ------------------
  |  Branch (2636:9): [True: 1.70k, False: 54]
  ------------------
 2637|  1.70k|					memmove(head, head+2, r-2);
 2638|  1.70k|					head += (r-2);
 2639|  1.70k|				}
 2640|     54|				else {
 2641|     54|					if (r < 4)
  ------------------
  |  Branch (2641:10): [True: 1, False: 53]
  ------------------
 2642|      1|						break;
 2643|     53|					memmove(head, head+4, r-4);
 2644|     53|					head += (r-4);
 2645|     53|				}
 2646|  1.75k|			}
 2647|     24|			len = head-data;
 2648|     24|		}
 2649|  2.44k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  2.44k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2649:12): [True: 5, False: 2.43k]
  ------------------
 2650|      5|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|      5|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2651|      5|			if (r < 0) {
  ------------------
  |  Branch (2651:8): [True: 1, False: 4]
  ------------------
 2652|      1|				goto fail_unlock;
 2653|      1|			}
 2654|       |			/* sc_read_record may return less than requested */
 2655|      4|			len = r;
 2656|      4|		}
 2657|  2.43k|		else {
 2658|  2.43k|			unsigned long flags = 0;
 2659|  2.43k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2660|  2.43k|			if (r < 0) {
  ------------------
  |  Branch (2660:8): [True: 488, False: 1.94k]
  ------------------
 2661|    488|				goto fail_unlock;
 2662|    488|			}
 2663|       |			/* sc_read_binary may return less than requested */
 2664|  1.94k|			len = r;
 2665|       |
 2666|  1.94k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  3.89k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2666:8): [True: 96, False: 1.85k]
  ------------------
 2667|  1.85k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  3.79k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2667:11): [True: 0, False: 1.85k]
  ------------------
 2668|  1.85k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  1.85k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2668:11): [True: 0, False: 1.85k]
  ------------------
 2669|     96|				unsigned char *decompressed_buf = NULL;
 2670|     96|				size_t decompressed_len = 0;
 2671|     96|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2672|     96|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
  |  Branch (2672:9): [True: 96, False: 0]
  ------------------
 2673|     96|					goto fail_unlock;
 2674|     96|				}
 2675|      0|				free(data);
 2676|      0|				data = decompressed_buf;
 2677|      0|				len = decompressed_len;
 2678|      0|			}
 2679|  1.94k|		}
 2680|  1.87k|		sc_unlock(p15card->card);
 2681|       |
 2682|  1.87k|		sc_file_free(file);
 2683|       |
 2684|  1.87k|		if (p15card->opts.use_file_cache && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    460|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2684:7): [True: 460, False: 1.41k]
  |  Branch (2684:40): [True: 0, False: 460]
  |  Branch (2684:107): [True: 455, False: 5]
  ------------------
 2685|    455|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2686|    455|		}
 2687|  1.87k|		if (len == 0) {
  ------------------
  |  Branch (2687:7): [True: 160, False: 1.71k]
  ------------------
 2688|    160|			free(data);
 2689|    160|			data = NULL;
 2690|    160|		}
 2691|  1.87k|	}
 2692|  1.97k|	*buf = data;
 2693|  1.97k|	*buflen = len;
 2694|  1.97k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.97k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.97k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.97k|	int _ret = r; \
  |  |  |  |  155|  1.97k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.97k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.97k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.97k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.97k|	return _ret; \
  |  |  |  |  163|  1.97k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2695|       |
 2696|  16.1k|fail_unlock:
 2697|  16.1k|	sc_unlock(p15card->card);
 2698|  16.1k|fail:
 2699|  16.1k|	free(data);
 2700|  16.1k|	sc_file_free(file);
 2701|  16.1k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  16.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.1k|	int _ret = r; \
  |  |  |  |  155|  16.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.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|  16.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.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|  16.1k|	return _ret; \
  |  |  |  |  163|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2702|  16.1k|}
sc_pkcs15_compare_id:
 2707|    973|{
 2708|    973|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2708:6): [True: 0, False: 973]
  |  Branch (2708:21): [True: 0, False: 973]
  ------------------
 2709|      0|		return 0;
 2710|    973|	if (id1->len != id2->len)
  ------------------
  |  Branch (2710:6): [True: 633, False: 340]
  ------------------
 2711|    633|		return 0;
 2712|    340|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2713|    973|}
sc_pkcs15_format_id:
 2718|   102k|{
 2719|   102k|	size_t len;
 2720|       |
 2721|   102k|	if (!id)
  ------------------
  |  Branch (2721:6): [True: 0, False: 102k]
  ------------------
 2722|      0|		return;
 2723|   102k|	len = sizeof(id->value);
 2724|       |
 2725|   102k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|   102k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2725:6): [True: 84, False: 102k]
  ------------------
 2726|     84|		id->len = 0;
 2727|   102k|	else
 2728|   102k|		id->len = len;
 2729|   102k|}
sc_pkcs15_print_id:
 2734|  4.46k|{
 2735|  4.46k|	static char buffer[256];
 2736|       |
 2737|  4.46k|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2738|  4.46k|	return buffer;
 2739|  4.46k|}
sc_pkcs15_hex_string_to_id:
 2744|    251|{
 2745|    251|	out->len = sizeof(out->value);
 2746|    251|	return sc_hex_to_bin(in, out->value, &out->len);
 2747|    251|}
sc_pkcs15_make_absolute_path:
 2752|  5.68k|{
 2753|       |	/* nothing to do if child has valid 'aid' */
 2754|  5.68k|	if (child->aid.len)
  ------------------
  |  Branch (2754:6): [True: 0, False: 5.68k]
  ------------------
 2755|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2756|       |
 2757|  5.68k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2757:6): [True: 0, False: 5.68k]
  ------------------
 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|  5.68k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  5.68k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2772:11): [True: 22, False: 5.65k]
  ------------------
 2773|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2774|     22|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2774:7): [True: 0, False: 22]
  ------------------
 2775|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2776|       |
 2777|     22|		memcpy(child->aid.value, parent->value, parent->len);
 2778|     22|		child->aid.len = parent->len;
 2779|       |
 2780|     22|		return SC_SUCCESS;
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
 2781|     22|	}
 2782|       |
 2783|       |	/* a 0 length path stays a 0 length path */
 2784|  5.65k|	if (child->len == 0)
  ------------------
  |  Branch (2784:6): [True: 18, False: 5.64k]
  ------------------
 2785|     18|		return SC_SUCCESS;
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
 2786|       |
 2787|  5.64k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2787:6): [True: 249, False: 5.39k]
  ------------------
 2788|    249|		return SC_SUCCESS;
  ------------------
  |  |   28|    249|#define SC_SUCCESS				0
  ------------------
 2789|       |
 2790|  5.39k|	return sc_concatenate_path(child, parent, child);
 2791|  5.64k|}
sc_pkcs15_free_object_content:
 2795|  28.8k|{
 2796|  28.8k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2796:6): [True: 47, False: 28.8k]
  |  Branch (2796:28): [True: 47, False: 0]
  ------------------
 2797|     47|		if (obj->content_free) {
  ------------------
  |  Branch (2797:7): [True: 47, False: 0]
  ------------------
 2798|     47|			obj->content_free(obj->content.value, obj->content.len);
 2799|     47|		} else {
 2800|      0|			free(obj->content.value);
 2801|      0|		}
 2802|     47|	}
 2803|       |	obj->content.value = NULL;
 2804|  28.8k|	obj->content.len = 0;
 2805|  28.8k|}
sc_pkcs15_allocate_object_content:
 2811|     47|{
 2812|     47|	unsigned char *tmp_buf;
 2813|       |
 2814|     47|	if (!obj)
  ------------------
  |  Branch (2814:6): [True: 0, False: 47]
  ------------------
 2815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2816|       |
 2817|     47|	if (!value || !len)   {
  ------------------
  |  Branch (2817:6): [True: 0, False: 47]
  |  Branch (2817:16): [True: 0, False: 47]
  ------------------
 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|     47|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|     47|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2825:6): [True: 47, 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|     47|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2827:7): [True: 0, False: 0]
  ------------------
 2828|     47|		tmp_buf = sc_mem_secure_alloc(len);
 2829|     47|		obj->content_free = sc_mem_secure_free;
 2830|     47|	} else {
 2831|      0|		tmp_buf = malloc(len);
 2832|      0|	}
 2833|     47|	if (!tmp_buf)
  ------------------
  |  Branch (2833:6): [True: 0, False: 47]
  ------------------
 2834|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2835|       |
 2836|     47|	memcpy(tmp_buf, value, len);
 2837|       |
 2838|     47|	sc_pkcs15_free_object_content(obj);
 2839|       |
 2840|     47|	obj->content.value = tmp_buf;
 2841|     47|	obj->content.len = len;
 2842|       |
 2843|     47|	return SC_SUCCESS;
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
 2844|     47|}
sc_pkcs15_get_object_id:
 2974|    294|{
 2975|    294|	if (!obj || !out)
  ------------------
  |  Branch (2975:6): [True: 0, False: 294]
  |  Branch (2975:14): [True: 0, False: 294]
  ------------------
 2976|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2977|       |
 2978|    294|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|    294|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 2979|      0|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|      0|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (2979:2): [True: 0, False: 294]
  ------------------
 2980|      0|		*out = ((struct sc_pkcs15_cert_info *) obj->data)->id;
 2981|      0|		break;
 2982|    294|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|    294|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2982:2): [True: 294, False: 0]
  ------------------
 2983|    294|		*out = ((struct sc_pkcs15_prkey_info *) obj->data)->id;
 2984|    294|		break;
 2985|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2985:2): [True: 0, False: 294]
  ------------------
 2986|      0|		*out = ((struct sc_pkcs15_pubkey_info *) obj->data)->id;
 2987|      0|		break;
 2988|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2988:2): [True: 0, False: 294]
  ------------------
 2989|      0|		*out = ((struct sc_pkcs15_skey_info *) obj->data)->id;
 2990|      0|		break;
 2991|      0|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|      0|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2991:2): [True: 0, False: 294]
  ------------------
 2992|      0|		*out = ((struct sc_pkcs15_auth_info *) obj->data)->auth_id;
 2993|      0|		break;
 2994|      0|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2994:2): [True: 0, False: 294]
  ------------------
 2995|      0|		*out = ((struct sc_pkcs15_data_info *) obj->data)->id;
 2996|      0|		break;
 2997|      0|	default:
  ------------------
  |  Branch (2997:2): [True: 0, False: 294]
  ------------------
 2998|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2999|    294|	}
 3000|       |
 3001|    294|	return SC_SUCCESS;
  ------------------
  |  |   28|    294|#define SC_SUCCESS				0
  ------------------
 3002|    294|}
sc_pkcs15_serialize_guid:
 3014|     82|{
 3015|     82|	if (in_size < 16)
  ------------------
  |  Branch (3015:6): [True: 0, False: 82]
  ------------------
 3016|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 3017|     82|	if (out_size < 39)
  ------------------
  |  Branch (3017:6): [True: 0, False: 82]
  ------------------
 3018|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 3019|       |
 3020|     82|	snprintf(out, out_size,
 3021|     82|			"%s%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%s",
 3022|     82|			flags ? "" : "{",
  ------------------
  |  Branch (3022:4): [True: 82, False: 0]
  ------------------
 3023|     82|			in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
 3024|     82|			in[8], in[9], in[10], in[11], in[12], in[13], in[14], in[15],
 3025|     82|			flags ? "" : "}");
  ------------------
  |  Branch (3025:4): [True: 82, False: 0]
  ------------------
 3026|       |
 3027|     82|	return SC_SUCCESS;
  ------------------
  |  |   28|     82|#define SC_SUCCESS				0
  ------------------
 3028|     82|}
sc_pkcs15_get_object_guid:
 3033|    294|{
 3034|    294|	struct sc_context *ctx = p15card->card->ctx;
 3035|    294|	struct sc_serial_number serialnr;
 3036|    294|	struct sc_pkcs15_id  id;
 3037|    294|	unsigned char guid_bin[SC_PKCS15_MAX_ID_SIZE + SC_MAX_SERIALNR];
 3038|    294|	int rv;
 3039|    294|	size_t guid_bin_size;
 3040|       |
 3041|    294|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3042|    294|	if(!out || !out_size)
  ------------------
  |  Branch (3042:5): [True: 0, False: 294]
  |  Branch (3042:13): [True: 0, False: 294]
  ------------------
 3043|    294|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3044|       |
 3045|    294|	if (p15card->ops.get_guid)   {
  ------------------
  |  Branch (3045:6): [True: 115, False: 179]
  ------------------
 3046|    115|		rv = p15card->ops.get_guid(p15card, obj, out, out_size);
 3047|    115|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    115|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    115|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    115|	int _ret = r; \
  |  |  |  |  155|    115|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 115, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    115|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     66|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 66, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  157|    115|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    115|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    115|	return _ret; \
  |  |  |  |  163|    115|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3048|    115|	}
 3049|       |
 3050|    179|	rv = sc_pkcs15_aux_get_md_guid(p15card, obj, flags, out, out_size);
 3051|    179|	if (rv == SC_SUCCESS)
  ------------------
  |  |   28|    179|#define SC_SUCCESS				0
  ------------------
  |  Branch (3051:6): [True: 0, False: 179]
  ------------------
 3052|    179|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3053|    179|	else if (rv != SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|    179|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (3053:11): [True: 0, False: 179]
  ------------------
 3054|      0|		LOG_TEST_RET(ctx, rv, "Failed to get alternative object GUID");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3055|       |
 3056|    179|	memset(out, 0, *out_size);
 3057|       |
 3058|    179|	rv = sc_pkcs15_get_object_id(obj, &id);
 3059|    179|	LOG_TEST_RET(ctx, rv, "Cannot get object's ID");
  ------------------
  |  |  174|    179|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    179|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    179|	int _ret = (r); \
  |  |  |  |  168|    179|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  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|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3060|       |
 3061|    179|	if (p15card->tokeninfo && p15card->tokeninfo->serial_number)   {
  ------------------
  |  Branch (3061:6): [True: 179, False: 0]
  |  Branch (3061:28): [True: 71, False: 108]
  ------------------
 3062|       |		/* The serial from EF(TokenInfo) is preferred because of the
 3063|       |		 * "--serial" parameter of pkcs15-init. */
 3064|     71|		serialnr.len = SC_MAX_SERIALNR;
  ------------------
  |  |  372|     71|#define SC_MAX_SERIALNR         32
  ------------------
 3065|     71|		rv = sc_hex_to_bin(p15card->tokeninfo->serial_number, serialnr.value, &serialnr.len);
 3066|     71|		if (rv) {
  ------------------
  |  Branch (3066:7): [True: 0, False: 71]
  ------------------
 3067|       |			/* Fallback in case hex_to_bin fails due to unexpected characters */
 3068|      0|			serialnr.len = strlen(p15card->tokeninfo->serial_number);
 3069|      0|			if (serialnr.len > SC_MAX_SERIALNR)
  ------------------
  |  |  372|      0|#define SC_MAX_SERIALNR         32
  ------------------
  |  Branch (3069:8): [True: 0, False: 0]
  ------------------
 3070|      0|				serialnr.len = SC_MAX_SERIALNR;
  ------------------
  |  |  372|      0|#define SC_MAX_SERIALNR         32
  ------------------
 3071|       |
 3072|      0|			memcpy(serialnr.value, p15card->tokeninfo->serial_number, serialnr.len);
 3073|      0|		}
 3074|    108|	} else if (p15card->card->serialnr.len)   {
  ------------------
  |  Branch (3074:13): [True: 6, False: 102]
  ------------------
 3075|      6|		serialnr = p15card->card->serialnr;
 3076|    102|	} else   {
 3077|    102|		rv = sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &serialnr);
 3078|    102|		LOG_TEST_RET(ctx, rv, "'GET_SERIALNR' CTL failed and other serial numbers not present");
  ------------------
  |  |  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: 97, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|     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
  |  |  |  |  ------------------
  |  |  |  |  170|     97|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     97|		return _ret; \
  |  |  |  |  172|     97|	} \
  |  |  |  |  173|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3079|    102|	}
 3080|       |
 3081|     82|	memset(guid_bin, 0, sizeof(guid_bin));
 3082|     82|	memcpy(guid_bin, id.value, id.len);
 3083|     82|	memcpy(guid_bin + id.len, serialnr.value, serialnr.len);
 3084|     82|	guid_bin_size = id.len + serialnr.len;
 3085|       |
 3086|       |	/*
 3087|       |	 * If OpenSSL is available (SHA1), then rather use the hash of the data
 3088|       |	 * - this also protects against data being too short
 3089|       |	 */
 3090|     82|#ifdef ENABLE_OPENSSL
 3091|     82|	SHA1(guid_bin, guid_bin_size, guid_bin);
 3092|     82|	guid_bin_size = SHA_DIGEST_LENGTH;
 3093|       |#else
 3094|       |	/* If guid_bin has a size larger than 16 bytes
 3095|       |	 * force the remaining bytes up to 16 bytes to be zero
 3096|       |	 * so sc_pkcs15_serialize_guid won't fail because the size is less than 16
 3097|       |	 */
 3098|       |	if (guid_bin_size < 16)
 3099|       |		guid_bin_size = 16;
 3100|       |#endif
 3101|       |
 3102|     82|	rv = sc_pkcs15_serialize_guid(guid_bin, guid_bin_size, flags, (char *)out, *out_size);
 3103|     82|	LOG_TEST_RET(ctx, rv, "Serialize GUID error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3104|       |
 3105|     82|	*out_size = strlen((char *)out);
 3106|     82|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3107|     82|}
sc_pkcs15_free_key_params:
 3137|    658|{
 3138|    658|	if (!params)
  ------------------
  |  Branch (3138:6): [True: 0, False: 658]
  ------------------
 3139|      0|		return;
 3140|    658|	if (params->data && params->free_params)
  ------------------
  |  Branch (3140:6): [True: 0, False: 658]
  |  Branch (3140:22): [True: 0, False: 0]
  ------------------
 3141|      0|		params->free_params(params->data);
 3142|    658|	else if (params->data)
  ------------------
  |  Branch (3142:11): [True: 0, False: 658]
  ------------------
 3143|      0|		free(params->data);
 3144|       |
 3145|       |	params->data = NULL;
 3146|    658|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  754|  10.1k|{
  755|  10.1k|	if (!tokeninfo)
  ------------------
  |  Branch (755:6): [True: 0, False: 10.1k]
  ------------------
  756|      0|		return;
  757|       |
  758|  10.1k|	free(tokeninfo->label);
  759|  10.1k|	tokeninfo->label = NULL;
  760|  10.1k|	free(tokeninfo->serial_number);
  761|  10.1k|	tokeninfo->serial_number = NULL;
  762|  10.1k|	free(tokeninfo->manufacturer_id);
  763|  10.1k|	tokeninfo->manufacturer_id = NULL;
  764|  10.1k|	free(tokeninfo->last_update.gtime);
  765|  10.1k|	tokeninfo->last_update.gtime = NULL;
  766|  10.1k|	free(tokeninfo->preferred_language);
  767|  10.1k|	tokeninfo->preferred_language = NULL;
  768|  10.1k|	free(tokeninfo->profile_indication.name);
  769|  10.1k|	tokeninfo->profile_indication.name = NULL;
  770|  10.1k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (770:6): [True: 4, False: 10.1k]
  ------------------
  771|      4|		unsigned i;
  772|     14|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (772:15): [True: 10, False: 4]
  ------------------
  773|     10|			free(tokeninfo->seInfo[i]);
  774|      4|		free(tokeninfo->seInfo);
  775|       |		tokeninfo->seInfo = NULL;
  776|      4|	}
  777|  10.1k|}
pkcs15.c:parse_odf:
  621|    117|{
  622|    117|	const unsigned char *p = buf;
  623|    117|	size_t left = buflen;
  624|    117|	int r, i, type;
  625|    117|	struct sc_path path;
  626|    117|	struct sc_asn1_entry asn1_obj_or_path[] = {
  627|    117|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  174|    117|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  141|    117|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  162|    117|#define SC_ASN1_SEQUENCE                16
  ------------------
  628|    117|		{ NULL, 0, 0, 0, NULL, NULL }
  629|    117|	};
  630|    117|	struct sc_asn1_entry asn1_odf[10];
  631|       |
  632|    117|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  633|  1.17k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (633:14): [True: 1.05k, False: 117]
  ------------------
  634|  1.05k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  635|    409|	while (left > 0) {
  ------------------
  |  Branch (635:9): [True: 408, False: 1]
  ------------------
  636|    408|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  637|    408|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    408|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (637:7): [True: 73, False: 335]
  ------------------
  638|     73|			break;
  639|    335|		if (r < 0)
  ------------------
  |  Branch (639:7): [True: 43, False: 292]
  ------------------
  640|     43|			return r;
  641|    292|		type = r;
  642|    292|		if (p15card->file_app) {
  ------------------
  |  Branch (642:7): [True: 292, False: 0]
  ------------------
  643|    292|			r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
  644|    292|			if (r < 0)
  ------------------
  |  Branch (644:8): [True: 0, False: 292]
  ------------------
  645|      0|				return r;
  646|    292|			r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  647|    292|			if (r)
  ------------------
  |  Branch (647:8): [True: 0, False: 292]
  ------------------
  648|      0|				return r;
  649|    292|		}
  650|    292|	}
  651|     74|	return 0;
  652|    117|}
pkcs15.c:sc_dup_app_info:
  908|    147|{
  909|    147|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  910|       |
  911|    147|	if (!out)
  ------------------
  |  Branch (911:6): [True: 0, False: 147]
  ------------------
  912|      0|		return NULL;
  913|       |
  914|    147|	memcpy(out, info, sizeof(struct sc_app_info));
  915|       |
  916|    147|	if (info->label) {
  ------------------
  |  Branch (916:6): [True: 64, False: 83]
  ------------------
  917|     64|		out->label = strdup(info->label);
  918|     64|		if (!out->label) {
  ------------------
  |  Branch (918:7): [True: 0, False: 64]
  ------------------
  919|      0|			free(out);
  920|      0|			return NULL;
  921|      0|		}
  922|     64|	} else
  923|     83|		out->label = NULL;
  924|       |
  925|    147|	out->ddo.value = malloc(info->ddo.len);
  926|    147|	if (!out->ddo.value) {
  ------------------
  |  Branch (926:6): [True: 0, False: 147]
  ------------------
  927|      0|		free(out->label);
  928|      0|		free(out);
  929|      0|		return NULL;
  930|      0|	}
  931|    147|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  932|    147|	out->ddo.len = info->ddo.len;
  933|       |
  934|    147|	return out;
  935|    147|}
pkcs15.c:parse_ddo:
  473|     19|{
  474|     19|	struct sc_context *ctx = p15card->card->ctx;
  475|     19|	struct sc_asn1_entry asn1_ddo[7];
  476|     19|	sc_path_t odf_path, ti_path, us_path;
  477|     19|	struct sc_iid iid;
  478|     19|	struct sc_aid aid;
  479|     19|	int r;
  480|       |
  481|     19|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|       |
  483|     19|	iid.len = sizeof(iid.value);
  484|     19|	aid.len = sizeof(aid.value);
  485|       |
  486|     19|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  487|     19|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  488|     19|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  489|     19|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  490|     19|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  491|     19|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  492|       |
  493|     19|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  494|     19|	LOG_TEST_RET(ctx, r, "DDO parsing 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: 6, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  495|       |
  496|     13|	if (asn1_ddo[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     13|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (496:6): [True: 0, False: 13]
  ------------------
  497|      0|		sc_file_free(p15card->file_odf);
  498|      0|		p15card->file_odf = sc_file_new();
  499|      0|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (499:7): [True: 0, False: 0]
  ------------------
  500|      0|			goto mem_err;
  501|      0|		p15card->file_odf->path = odf_path;
  502|      0|	}
  503|     13|	if (asn1_ddo[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     13|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (503:6): [True: 0, False: 13]
  ------------------
  504|      0|		sc_file_free(p15card->file_tokeninfo);
  505|      0|		p15card->file_tokeninfo = sc_file_new();
  506|      0|		if (p15card->file_tokeninfo == NULL)
  ------------------
  |  Branch (506:7): [True: 0, False: 0]
  ------------------
  507|      0|			goto mem_err;
  508|      0|		p15card->file_tokeninfo->path = ti_path;
  509|      0|	}
  510|     13|	if (asn1_ddo[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     13|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (510:6): [True: 0, False: 13]
  ------------------
  511|      0|		sc_file_free(p15card->file_unusedspace);
  512|      0|		p15card->file_unusedspace = sc_file_new();
  513|      0|		if (p15card->file_unusedspace == NULL)
  ------------------
  |  Branch (513:7): [True: 0, False: 0]
  ------------------
  514|      0|			goto mem_err;
  515|      0|		p15card->file_unusedspace->path = us_path;
  516|      0|	}
  517|     13|	if (asn1_ddo[4].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     13|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (517:6): [True: 1, False: 12]
  ------------------
  518|      1|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.IID '%s'", sc_dump_hex(iid.value, iid.len));
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  519|      1|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  520|      1|	}
  521|     13|	if (asn1_ddo[5].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     13|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (521:6): [True: 7, False: 6]
  ------------------
  522|      7|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.AID '%s'", sc_dump_hex(aid.value, aid.len));
  ------------------
  |  |   70|      7|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|      7|		memcpy(&p15card->app->ddo.aid, &aid, sizeof(struct sc_aid));
  524|      7|	}
  525|       |
  526|     13|	fix_authentic_ddo(p15card);
  527|     13|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  528|      0|mem_err:
  529|      0|	sc_file_free(p15card->file_odf);
  530|      0|	p15card->file_odf = NULL;
  531|      0|	sc_file_free(p15card->file_tokeninfo);
  532|      0|	p15card->file_tokeninfo = NULL;
  533|      0|	sc_file_free(p15card->file_unusedspace);
  534|      0|	p15card->file_unusedspace = NULL;
  535|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|      0|}
pkcs15.c:fix_authentic_ddo:
  459|     13|{
  460|       |	/* AuthentIC v3.2 card has invalid ODF and tokenInfo paths encoded into DDO.
  461|       |	 * Cleanup this attributes -- default values must be OK.
  462|       |	 */
  463|     13|	if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)   {
  ------------------
  |  Branch (463:6): [True: 0, False: 13]
  ------------------
  464|      0|		sc_file_free(p15card->file_odf);
  465|      0|		p15card->file_odf = NULL;
  466|      0|		sc_file_free(p15card->file_tokeninfo);
  467|       |		p15card->file_tokeninfo = NULL;
  468|      0|	}
  469|     13|}
pkcs15.c:__sc_pkcs15_search_objects:
 1458|  10.0k|{
 1459|  10.0k|	struct sc_pkcs15_object *obj = NULL;
 1460|  10.0k|	struct sc_pkcs15_df	*df = NULL;
 1461|  10.0k|	unsigned int	df_mask = 0;
 1462|  10.0k|	size_t		match_count = 0;
 1463|  10.0k|	int r;
 1464|       |
 1465|  10.0k|	if (type)
  ------------------
  |  Branch (1465:6): [True: 10.0k, False: 0]
  ------------------
 1466|  10.0k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  10.0k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1467|       |
 1468|       |	/* Make sure the class mask we have makes sense */
 1469|  10.0k|	if (class_mask == 0
  ------------------
  |  Branch (1469:6): [True: 0, False: 10.0k]
  ------------------
 1470|  10.0k|			|| (class_mask & ~(
  ------------------
  |  Branch (1470:7): [True: 0, False: 10.0k]
  ------------------
 1471|  10.0k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  10.0k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1472|  10.0k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  10.0k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1473|  10.0k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  10.0k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1474|  10.0k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  10.0k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1475|  10.0k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  10.0k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1476|  10.0k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  10.0k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
 1477|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1478|      0|	}
 1479|       |
 1480|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  10.0k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1480:6): [True: 1.70k, False: 8.38k]
  ------------------
 1481|  1.70k|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|  1.70k|#define SC_PKCS15_PRKDF			0
  ------------------
 1482|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  10.0k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1482:6): [True: 656, False: 9.42k]
  ------------------
 1483|    656|		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  489|    656|#define SC_PKCS15_PUKDF			1
  ------------------
              		df_mask |= (1 << SC_PKCS15_PUKDF) | (1 << SC_PKCS15_PUKDF_TRUSTED);
  ------------------
  |  |  490|    656|#define SC_PKCS15_PUKDF_TRUSTED		2
  ------------------
 1484|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  10.0k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1484:6): [True: 1.01k, False: 9.06k]
  ------------------
 1485|  1.01k|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|  1.01k|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|  1.01k|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|  1.01k|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1486|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  10.0k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1486:6): [True: 1.97k, False: 8.11k]
  ------------------
 1487|  1.97k|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|  1.97k|#define SC_PKCS15_DODF			7
  ------------------
 1488|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  10.0k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1488:6): [True: 4.11k, False: 5.96k]
  ------------------
 1489|  4.11k|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|  4.11k|#define SC_PKCS15_AODF			8
  ------------------
 1490|  10.0k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  10.0k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1490:6): [True: 618, False: 9.46k]
  ------------------
 1491|    618|		df_mask |= (1 << SC_PKCS15_SKDF);
  ------------------
  |  |  491|    618|#define SC_PKCS15_SKDF			3
  ------------------
 1492|       |
 1493|       |	/* Make sure all the DFs we want to search have been
 1494|       |	 * enumerated. */
 1495|  30.4k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1495:30): [True: 20.3k, False: 10.0k]
  ------------------
 1496|  20.3k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1496:7): [True: 14.7k, False: 5.62k]
  ------------------
 1497|  14.7k|			continue;
 1498|  14.7k|		}
 1499|  5.62k|		if (df->enumerated)
  ------------------
  |  Branch (1499:7): [True: 5.33k, False: 293]
  ------------------
 1500|  5.33k|			continue;
 1501|       |		/* Enumerate the DF's, so p15card->obj_list is populated. */
 1502|    293|		if (p15card->ops.parse_df)
  ------------------
  |  Branch (1502:7): [True: 0, False: 293]
  ------------------
 1503|      0|			r = p15card->ops.parse_df(p15card, df);
 1504|    293|		else
 1505|    293|			r = sc_pkcs15_parse_df(p15card, df);
 1506|    293|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|    293|#define SC_SUCCESS				0
  ------------------
  |  Branch (1506:7): [True: 264, False: 29]
  ------------------
 1507|    264|			continue;
 1508|    293|	}
 1509|       |
 1510|       |	/* And now loop over all objects */
 1511|   118k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1511:32): [True: 108k, False: 9.94k]
  ------------------
 1512|       |		/* Check object type */
 1513|   108k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|   108k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1513:7): [True: 85.6k, False: 23.3k]
  ------------------
 1514|  85.6k|			continue;
 1515|  23.3k|		if (type != 0
  ------------------
  |  Branch (1515:7): [True: 23.3k, False: 0]
  ------------------
 1516|  23.3k|		 && obj->type != type
  ------------------
  |  Branch (1516:7): [True: 2.07k, False: 21.2k]
  ------------------
 1517|  2.07k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  2.07k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1517:7): [True: 0, False: 2.07k]
  ------------------
 1518|      0|			continue;
 1519|       |
 1520|       |		/* Potential candidate, apply search function */
 1521|  23.3k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1521:7): [True: 574, False: 22.7k]
  |  Branch (1521:23): [True: 478, False: 96]
  ------------------
 1522|    478|			continue;
 1523|       |		/* Okay, we have a match. */
 1524|  22.8k|		match_count++;
 1525|  22.8k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1525:7): [True: 0, False: 22.8k]
  |  Branch (1525:15): [True: 0, False: 22.8k]
  ------------------
 1526|      0|			continue;
 1527|  22.8k|		ret[match_count-1] = obj;
 1528|  22.8k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1528:7): [True: 140, False: 22.6k]
  ------------------
 1529|    140|			break;
 1530|  22.8k|	}
 1531|       |
 1532|  10.0k|	return (int)match_count;
 1533|  10.0k|}
pkcs15.c:compare_obj_key:
 1678|    574|{
 1679|    574|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1680|       |
 1681|    574|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1681:6): [True: 574, False: 0]
  |  Branch (1681:16): [True: 478, False: 96]
  ------------------
 1682|    478|		return 0;
 1683|     96|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1683:6): [True: 0, False: 96]
  |  Branch (1683:21): [True: 0, False: 0]
  ------------------
 1684|      0|		return 0;
 1685|     96|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1685:6): [True: 0, False: 96]
  |  Branch (1685:24): [True: 0, False: 0]
  ------------------
 1686|      0|		return 0;
 1687|     96|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1687:6): [True: 0, False: 96]
  |  Branch (1687:24): [True: 0, False: 0]
  ------------------
 1688|      0|		return 0;
 1689|     96|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1689:6): [True: 0, False: 96]
  |  Branch (1689:29): [True: 0, False: 0]
  ------------------
 1690|      0|		return 0;
 1691|     96|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1691:6): [True: 0, False: 96]
  |  Branch (1691:18): [True: 0, False: 0]
  ------------------
 1692|      0|		return 0;
 1693|     96|	if (
 1694|     96|		sk->app_label && sk->label &&
  ------------------
  |  Branch (1694:3): [True: 0, False: 96]
  |  Branch (1694:20): [True: 0, False: 0]
  ------------------
 1695|      0|		!compare_obj_data_name(obj, sk->app_label, sk->label)
  ------------------
  |  Branch (1695:3): [True: 0, False: 0]
  ------------------
 1696|     96|	) {
 1697|      0|		return 0;
 1698|      0|	}
 1699|       |
 1700|     96|	return 1;
 1701|     96|}
pkcs15.c:compare_obj_id:
 1546|    574|{
 1547|    574|	void *data = obj->data;
 1548|       |
 1549|    574|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|    574|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1549:10): [True: 574, False: 0]
  ------------------
 1550|     41|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|     41|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1550:2): [True: 41, False: 533]
  ------------------
 1551|     41|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_cert_info *) data)->id, id);
 1552|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1552:2): [True: 0, False: 574]
  ------------------
 1553|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) data)->id, id);
 1554|     22|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|     22|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1554:2): [True: 22, False: 552]
  ------------------
 1555|     22|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_pubkey_info *) data)->id, id);
 1556|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1556:2): [True: 0, False: 574]
  ------------------
 1557|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1558|    511|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|    511|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1558:2): [True: 511, False: 63]
  ------------------
 1559|    511|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_auth_info *) data)->auth_id, id);
 1560|      0|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (1560:2): [True: 0, False: 574]
  ------------------
 1561|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1562|    574|	}
 1563|      0|	return 0;
 1564|    574|}
pkcs15.c:sc_pkcs15_remove_objects:
 2021|  11.7k|{
 2022|  11.7k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 2023|       |
 2024|  11.7k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (2024:6): [True: 0, False: 11.7k]
  |  Branch (2024:18): [True: 9.46k, False: 2.31k]
  ------------------
 2025|  9.46k|		return;
 2026|  27.7k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (2026:32): [True: 25.4k, False: 2.31k]
  ------------------
 2027|  25.4k|		next = cur->next;
 2028|  25.4k|		sc_pkcs15_free_object(cur);
 2029|  25.4k|	}
 2030|       |
 2031|       |	p15card->obj_list = NULL;
 2032|  2.31k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2102|  11.7k|{
 2103|  11.7k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2104|       |
 2105|  11.7k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2105:6): [True: 0, False: 11.7k]
  |  Branch (2105:18): [True: 9.38k, False: 2.39k]
  ------------------
 2106|  9.38k|		return;
 2107|       |
 2108|  7.27k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2108:31): [True: 4.87k, False: 2.39k]
  ------------------
 2109|  4.87k|		next = cur->next;
 2110|  4.87k|		free(cur);
 2111|  4.87k|	}
 2112|       |
 2113|       |	p15card->df_list = NULL;
 2114|  2.39k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2337|  5.95k|{
 2338|  5.95k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2339|       |
 2340|  5.95k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2340:6): [True: 0, False: 5.95k]
  |  Branch (2340:18): [True: 5.95k, False: 0]
  ------------------
 2341|  5.95k|		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|     96|{
 2478|     96|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     96|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     96|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     96|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     96|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 96]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2479|     96|#ifdef ENABLE_ZLIB
 2480|     96|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
 2481|     96|	int method = 0;
 2482|       |
 2483|     96|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|     96|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2483:6): [True: 0, False: 96]
  ------------------
 2484|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2485|     96|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|     96|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2485:13): [True: 0, False: 96]
  ------------------
 2486|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2487|     96|	} else {
 2488|     96|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|     96|#define COMPRESSION_AUTO	0
  ------------------
 2489|     96|	}
 2490|       |
 2491|     96|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2492|     96|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
  |  Branch (2492:6): [True: 96, False: 0]
  ------------------
 2493|     96|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2494|     96|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     96|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|     96|	}
 2496|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|      0|}
pkcs15.c:sc_pkcs15_aux_get_md_guid:
 3114|    179|{
 3115|    179|	struct sc_context *ctx = p15card->card->ctx;
 3116|    179|	struct sc_pkcs15_prkey_info *prkey_info = NULL;
 3117|    179|	int rv;
 3118|       |
 3119|    179|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    179|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    179|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    179|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    179|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3120|    179|	if(!out || !out_size)
  ------------------
  |  Branch (3120:5): [True: 0, False: 179]
  |  Branch (3120:13): [True: 0, False: 179]
  ------------------
 3121|    179|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3122|       |
 3123|    179|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) != SC_PKCS15_TYPE_PRKEY)
  ------------------
  |  |  416|    179|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) != SC_PKCS15_TYPE_PRKEY)
  ------------------
  |  |  418|    179|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (3123:6): [True: 0, False: 179]
  ------------------
 3124|    179|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3125|       |
 3126|    179|	prkey_info = (struct sc_pkcs15_prkey_info *)obj->data;
 3127|    179|	if (!prkey_info->aux_data || prkey_info->aux_data->type != SC_AUX_DATA_TYPE_MD_CMAP_RECORD)
  ------------------
  |  |   36|      0|#define SC_AUX_DATA_TYPE_MD_CMAP_RECORD	0x01
  ------------------
  |  Branch (3127:6): [True: 179, False: 0]
  |  Branch (3127:31): [True: 0, False: 0]
  ------------------
 3128|    179|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    179|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    179|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    179|	int _ret = r; \
  |  |  |  |  155|    179|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 179, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    179|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    179|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 179, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    179|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    179|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    179|	return _ret; \
  |  |  |  |  163|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3129|       |
 3130|      0|	rv = sc_aux_data_get_md_guid(ctx, prkey_info->aux_data, flags, out, out_size);
 3131|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3132|      0|}

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

card-epass2003.c:sc_evp_cipher:
  135|  1.35k|{
  136|  1.35k|	return (EVP_CIPHER *)EVP_get_cipherbyname(algorithm);
  137|  1.35k|}
card-epass2003.c:sc_evp_cipher_free:
  140|  1.35k|{
  141|  1.35k|	return;
  142|  1.35k|}

sc_get_version:
   59|  8.50k|{
   60|  8.50k|    return sc_version;
   61|  8.50k|}
sc_hex_to_bin:
   64|   280k|{
   65|   280k|	const char *sc_hex_to_bin_separators = " :";
   66|   280k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 84, False: 280k]
  |  Branch (66:20): [True: 0, False: 280k]
  |  Branch (66:35): [True: 0, False: 280k]
  ------------------
   67|     84|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     84|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|     84|	}
   69|       |
   70|   280k|	int byte_needs_nibble = 0;
   71|   280k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   280k|#define SC_SUCCESS				0
  ------------------
   72|   280k|	size_t left = *outlen;
   73|   280k|	u8 byte = 0;
   74|  4.11M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 3.83M, False: 279k]
  |  Branch (74:24): [True: 3.83M, False: 15]
  ------------------
   75|  3.83M|		char c = *in++;
   76|  3.83M|		u8 nibble;
   77|  3.83M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 3.83M, False: 572]
  |  Branch (77:24): [True: 2.00M, False: 1.83M]
  ------------------
   78|  2.00M|			nibble = c - '0';
   79|  1.83M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 361k, False: 1.47M]
  |  Branch (79:24): [True: 360k, False: 107]
  ------------------
   80|   360k|			nibble = c - 'a' + 10;
   81|  1.47M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 532k, False: 941k]
  |  Branch (81:24): [True: 532k, False: 126]
  ------------------
   82|   532k|			nibble = c - 'A' + 10;
   83|   941k|		else {
   84|   941k|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 941k, False: 302]
  ------------------
   85|   941k|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 3, False: 941k]
  ------------------
   86|      3|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      3|					goto err;
   88|      3|				}
   89|   941k|				continue;
   90|   941k|			}
   91|    302|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    302|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|    302|			goto err;
   93|   941k|		}
   94|       |
   95|  2.89M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 1.44M, False: 1.44M]
  ------------------
   96|  1.44M|			byte |= nibble;
   97|  1.44M|			*out++ = (u8) byte;
   98|  1.44M|			left--;
   99|  1.44M|			byte_needs_nibble = 0;
  100|  1.44M|		} else {
  101|  1.44M|			byte  = nibble << 4;
  102|  1.44M|			byte_needs_nibble = 1;
  103|  1.44M|		}
  104|  2.89M|	}
  105|       |
  106|   279k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 5.65k, False: 274k]
  |  Branch (106:25): [True: 2.46k, False: 3.18k]
  |  Branch (106:51): [True: 2.46k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  2.46k|		*out = (u8) byte>>4;
  110|  2.46k|		left--;
  111|  2.46k|		byte_needs_nibble = 0;
  112|  2.46k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   279k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 2, False: 279k]
  ------------------
  116|      2|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      2|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  117|      2|		goto err;
  118|      2|	}
  119|       |
  120|       |	/* skip all trailing separators to see if we missed something */
  121|   280k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 254, False: 279k]
  ------------------
  122|    254|		if (NULL == strchr(sc_hex_to_bin_separators, (int) *in))
  ------------------
  |  Branch (122:7): [True: 12, False: 242]
  ------------------
  123|     12|			break;
  124|    242|		in++;
  125|    242|	}
  126|   279k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 12, False: 279k]
  ------------------
  127|     12|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     12|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  128|     12|		goto err;
  129|     12|	}
  130|       |
  131|   280k|err:
  132|   280k|	*outlen -= left;
  133|   280k|	return r;
  134|   279k|}
sc_bin_to_hex:
  138|   212k|{
  139|   212k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 212k]
  |  Branch (139:20): [True: 0, False: 212k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   212k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 207k, False: 5.21k]
  ------------------
  144|   207k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 207k]
  |  Branch (144:29): [True: 0, False: 207k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   207k|	} else {
  147|  5.21k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 1, False: 5.21k]
  ------------------
  148|      1|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  5.21k|	}
  150|       |
  151|   212k|	const char hex[] = "0123456789abcdef";
  152|  2.53M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 2.32M, False: 212k]
  ------------------
  153|  2.32M|		unsigned char value = *in++;
  154|  2.32M|		*out++ = hex[(value >> 4) & 0xF];
  155|  2.32M|		*out++ = hex[ value       & 0xF];
  156|  2.32M|		in_len--;
  157|  2.32M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 2.18M, False: 135k]
  |  Branch (157:17): [True: 2.17M, False: 7.71k]
  ------------------
  158|  2.17M|			*out++ = (char)in_sep;
  159|  2.32M|	}
  160|   212k|	*out = '\0';
  161|       |
  162|   212k|	return SC_SUCCESS;
  ------------------
  |  |   28|   212k|#define SC_SUCCESS				0
  ------------------
  163|   212k|}
ulong2bebytes:
  189|  1.39k|{
  190|  1.39k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 1.39k, False: 0]
  ------------------
  191|  1.39k|		buf[3] = (u8) (x & 0xff);
  192|  1.39k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  1.39k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  1.39k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  1.39k|	}
  196|  1.39k|	return buf;
  197|  1.39k|}
bebytes2ulong:
  209|  5.25k|{
  210|  5.25k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 5.25k]
  ------------------
  211|      0|		return 0UL;
  212|  5.25k|	return (unsigned long)buf[0] << 24
  213|  5.25k|		| (unsigned long)buf[1] << 16
  214|  5.25k|		| (unsigned long)buf[2] << 8
  215|  5.25k|		| (unsigned long)buf[3];
  216|  5.25k|}
bebytes2ushort:
  219|  13.4k|{
  220|  13.4k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 13.4k]
  ------------------
  221|      0|		return 0U;
  222|  13.4k|	return (unsigned short)buf[0] << 8
  223|  13.4k|		| (unsigned short)buf[1];
  224|  13.4k|}
lebytes2ushort:
  227|  1.24k|{
  228|  1.24k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 1.24k]
  ------------------
  229|      0|		return 0U;
  230|  1.24k|	return (unsigned short)buf[1] << 8
  231|  1.24k|		| (unsigned short)buf[0];
  232|  1.24k|}
lebytes2ulong:
  235|    242|{
  236|    242|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 242]
  ------------------
  237|      0|		return 0UL;
  238|    242|	return (unsigned long)buf[3] << 24
  239|    242|		| (unsigned long)buf[2] << 16
  240|    242|		| (unsigned long)buf[1] << 8
  241|    242|		| (unsigned long)buf[0];
  242|    242|}
set_string:
  245|  7.59k|{
  246|  7.59k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 7.59k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  7.59k|	free(*strp);
  251|  7.59k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 7.59k, False: 0]
  ------------------
  252|  7.59k|}
sc_init_oid:
  255|  42.9k|{
  256|  42.9k|	int ii;
  257|       |
  258|  42.9k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 42.9k]
  ------------------
  259|      0|		return;
  260|   730k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   730k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 687k, False: 42.9k]
  ------------------
  261|   687k|		oid->value[ii] = -1;
  262|  42.9k|}
sc_format_oid:
  265|  26.6k|{
  266|  26.6k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  26.6k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  26.6k|	const char *p;
  268|  26.6k|	char       *q;
  269|       |
  270|  26.6k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 26.6k]
  |  Branch (270:21): [True: 0, False: 26.6k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  26.6k|	sc_init_oid(oid);
  274|       |
  275|  26.6k|	p = in;
  276|   211k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   211k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 211k, False: 0]
  ------------------
  277|   211k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   211k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 23.4k, False: 188k]
  ------------------
  279|  23.4k|			break;
  280|       |
  281|   188k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 185k, False: 3.08k]
  |  Branch (281:24): [True: 185k, False: 88]
  ------------------
  282|  3.17k|			goto out;
  283|       |
  284|   185k|		p = q + 1;
  285|   185k|	}
  286|       |
  287|  23.4k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 752, False: 22.7k]
  ------------------
  288|    752|		goto out;
  289|       |
  290|  22.7k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  22.7k|#define SC_SUCCESS				0
  ------------------
  291|  26.6k|out:
  292|  26.6k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 3.92k, False: 22.7k]
  ------------------
  293|  3.92k|		sc_init_oid(oid);
  294|       |
  295|  26.6k|	return ret;
  296|  22.7k|}
sc_compare_oid:
  299|  17.8k|{
  300|  17.8k|	int i;
  301|       |
  302|  17.8k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 17.8k]
  |  Branch (302:22): [True: 0, False: 17.8k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|  46.2k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|  46.2k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 46.2k, False: 0]
  ------------------
  307|  46.2k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 17.4k, False: 28.7k]
  ------------------
  308|  17.4k|			return 0;
  309|  28.7k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 421, False: 28.3k]
  ------------------
  310|    421|			break;
  311|  28.7k|	}
  312|       |
  313|    421|	return 1;
  314|  17.8k|}
sc_valid_oid:
  318|  33.9k|{
  319|  33.9k|	int ii;
  320|       |
  321|  33.9k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 33.9k]
  ------------------
  322|      0|		return 0;
  323|  33.9k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 100, False: 33.8k]
  |  Branch (323:29): [True: 360, False: 33.5k]
  ------------------
  324|    460|		return 0;
  325|  33.5k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 189, False: 33.3k]
  |  Branch (325:27): [True: 124, False: 33.2k]
  ------------------
  326|    313|		return 0;
  327|  40.7k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  40.7k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 40.2k, False: 468]
  ------------------
  328|  40.2k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 32.7k, False: 7.54k]
  ------------------
  329|  32.7k|			break;
  330|  33.2k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  33.2k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 468, False: 32.7k]
  ------------------
  331|    468|		return 0;
  332|  32.7k|	return 1;
  333|  33.2k|}
sc_path_set:
  355|  12.0k|{
  356|  12.0k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  12.0k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 12.0k]
  |  Branch (356:22): [True: 0, False: 12.0k]
  |  Branch (356:36): [True: 0, False: 12.0k]
  |  Branch (356:51): [True: 0, False: 12.0k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  12.0k|	memset(path, 0, sizeof(*path));
  360|  12.0k|	memcpy(path->value, id, id_len);
  361|  12.0k|	path->len   = id_len;
  362|  12.0k|	path->type  = type;
  363|  12.0k|	path->index = idx;
  364|  12.0k|	path->count = count;
  365|       |
  366|  12.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  12.0k|#define SC_SUCCESS				0
  ------------------
  367|  12.0k|}
sc_format_path:
  370|   110k|{
  371|   110k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   110k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   110k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 110k, False: 0]
  ------------------
  374|   110k|		memset(path, 0, sizeof(*path));
  375|   110k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 194, False: 109k]
  |  Branch (375:22): [True: 0, False: 109k]
  ------------------
  376|    194|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    194|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|    194|			str++;
  378|    194|		}
  379|   110k|		path->len = sizeof(path->value);
  380|   110k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 110k, False: 0]
  ------------------
  381|   110k|			path->type = type;
  382|   110k|		}
  383|   110k|		path->count = -1;
  384|   110k|	}
  385|   110k|}
sc_append_path_id:
  393|  33.6k|{
  394|  33.6k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  33.6k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 0, False: 33.6k]
  ------------------
  395|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  33.6k|	memcpy(dest->value + dest->len, id, idlen);
  397|  33.6k|	dest->len += idlen;
  398|  33.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  33.6k|#define SC_SUCCESS				0
  ------------------
  399|  33.6k|}
sc_append_file_id:
  402|  33.6k|{
  403|  33.6k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  33.6k|	return sc_append_path_id(dest, id, 2);
  406|  33.6k|}
sc_concatenate_path:
  409|  5.39k|{
  410|  5.39k|	sc_path_t tpath;
  411|       |
  412|  5.39k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 5.39k]
  |  Branch (412:19): [True: 0, False: 5.39k]
  |  Branch (412:33): [True: 0, False: 5.39k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  5.39k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  10.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  5.39k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 5.39k]
  |  Branch (415:42): [True: 0, False: 5.39k]
  ------------------
  416|       |		/* we do not support concatenation of AIDs at the moment */
  417|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  418|       |
  419|  5.39k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  5.39k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 1, False: 5.39k]
  ------------------
  420|      1|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  5.39k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  5.39k|	memcpy(tpath.value, p1->value, p1->len);
  424|  5.39k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  5.39k|	tpath.len  = p1->len + p2->len;
  426|  5.39k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  5.39k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  5.39k|	tpath.index = p2->index;
  429|  5.39k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  5.39k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  5.39k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  5.39k|	*d = tpath;
  434|       |
  435|  5.39k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.39k|#define SC_SUCCESS				0
  ------------------
  436|  5.39k|}
sc_print_path:
  439|   140k|{
  440|   140k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   140k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   140k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 140k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   140k|	return buffer;
  446|   140k|}
sc_path_print:
  449|   189k|{
  450|   189k|	size_t i;
  451|       |
  452|   189k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (452:6): [True: 0, False: 189k]
  |  Branch (452:21): [True: 0, False: 189k]
  ------------------
  453|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  454|       |
  455|   189k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (455:6): [True: 119, False: 189k]
  ------------------
  456|    119|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    119|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   189k|	buf[0] = '\0';
  459|   189k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 98.3k, False: 90.9k]
  ------------------
  460|   792k|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 694k, False: 98.3k]
  ------------------
  461|   694k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  462|  98.3k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  463|  98.3k|	}
  464|       |
  465|   589k|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 400k, False: 189k]
  ------------------
  466|   400k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   189k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  90.9k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 90.9k, False: 98.3k]
  |  Branch (467:24): [True: 12.4k, False: 78.5k]
  ------------------
  468|  12.4k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   189k|	return SC_SUCCESS;
  ------------------
  |  |   28|   189k|#define SC_SUCCESS				0
  ------------------
  471|   189k|}
sc_compare_path:
  474|  7.27k|{
  475|  7.27k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 6.83k, False: 442]
  ------------------
  476|  6.83k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 249, False: 6.58k]
  ------------------
  477|  7.27k|}
sc_compare_path_prefix:
  480|  5.64k|{
  481|  5.64k|	sc_path_t tpath;
  482|       |
  483|  5.64k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 6, False: 5.63k]
  ------------------
  484|      6|		return 0;
  485|       |
  486|  5.63k|	tpath     = *path;
  487|  5.63k|	tpath.len = prefix->len;
  488|       |
  489|  5.63k|	return sc_compare_path(&tpath, prefix);
  490|  5.64k|}
sc_get_mf_path:
  493|  8.28k|{
  494|  8.28k|	static const sc_path_t mf_path = {
  495|  8.28k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  8.28k|		0,
  497|  8.28k|		0,
  498|  8.28k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  8.28k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  8.28k|		{{0},0}
  500|  8.28k|	};
  501|  8.28k|	return &mf_path;
  502|  8.28k|}
sc_file_add_acl_entry:
  506|  56.5k|{
  507|  56.5k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|  56.5k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  56.5k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 56.5k]
  |  Branch (509:22): [True: 0, False: 56.5k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|  56.5k|	switch (method) {
  514|  19.8k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  19.8k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 19.8k, False: 36.6k]
  ------------------
  515|  19.8k|		sc_file_clear_acl_entries(file, operation);
  516|  19.8k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  19.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  19.8k|#define SC_SUCCESS				0
  ------------------
  518|  2.85k|	case SC_AC_NONE:
  ------------------
  |  |  150|  2.85k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 2.85k, False: 53.6k]
  ------------------
  519|  2.85k|		sc_file_clear_acl_entries(file, operation);
  520|  2.85k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  2.85k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.85k|#define SC_SUCCESS				0
  ------------------
  522|    180|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|    180|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 180, False: 56.3k]
  ------------------
  523|    180|		sc_file_clear_acl_entries(file, operation);
  524|    180|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|    180|		return SC_SUCCESS;
  ------------------
  |  |   28|    180|#define SC_SUCCESS				0
  ------------------
  526|  33.6k|	default:
  ------------------
  |  Branch (526:2): [True: 33.6k, False: 22.9k]
  ------------------
  527|       |		/* NONE and UNKNOWN get zapped when a new AC is added.
  528|       |		 * If the ACL is NEVER, additional entries will be
  529|       |		 * dropped silently. */
  530|  33.6k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 3, False: 33.6k]
  ------------------
  531|      3|			return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  532|  33.6k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 484, False: 33.1k]
  ------------------
  533|  33.1k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 3, False: 33.1k]
  ------------------
  534|    487|			file->acl[operation] = NULL;
  535|  56.5k|	}
  536|       |
  537|       |	/* If the entry is already present (e.g. due to the mapping)
  538|       |	 * of the card's AC with OpenSC's), don't add it again. */
  539|  46.6k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 15.9k, False: 30.7k]
  ------------------
  540|  15.9k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 12.5k, False: 3.39k]
  |  Branch (540:32): [True: 2.88k, False: 9.65k]
  ------------------
  541|  2.88k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.88k|#define SC_SUCCESS				0
  ------------------
  542|  15.9k|	}
  543|       |
  544|  30.7k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|  30.7k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 30.7k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|  30.7k|	_new->method = method;
  548|  30.7k|	_new->key_ref = (unsigned)key_ref;
  549|  30.7k|	_new->next = NULL;
  550|       |
  551|  30.7k|	p = file->acl[operation];
  552|  30.7k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 27.7k, False: 2.95k]
  ------------------
  553|  27.7k|		file->acl[operation] = _new;
  554|  27.7k|		return SC_SUCCESS;
  ------------------
  |  |   28|  27.7k|#define SC_SUCCESS				0
  ------------------
  555|  27.7k|	}
  556|  10.8k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 7.86k, False: 2.95k]
  ------------------
  557|  7.86k|		p = p->next;
  558|  2.95k|	p->next = _new;
  559|       |
  560|  2.95k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.95k|#define SC_SUCCESS				0
  ------------------
  561|  30.7k|}
sc_file_get_acl_entry:
  565|  14.4k|{
  566|  14.4k|	sc_acl_entry_t *p;
  567|  14.4k|	static const sc_acl_entry_t e_never = {
  568|  14.4k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|  14.4k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|  14.4k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|  14.4k|	};
  570|  14.4k|	static const sc_acl_entry_t e_none = {
  571|  14.4k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|  14.4k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|  14.4k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|  14.4k|	};
  573|  14.4k|	static const sc_acl_entry_t e_unknown = {
  574|  14.4k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|  14.4k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|  14.4k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|  14.4k|	};
  576|       |
  577|  14.4k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  14.4k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 14.4k]
  |  Branch (577:22): [True: 0, False: 14.4k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|  14.4k|	p = file->acl[operation];
  582|  14.4k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 36, False: 14.4k]
  ------------------
  583|     36|		return &e_never;
  584|  14.4k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 33, False: 14.4k]
  ------------------
  585|     33|		return &e_none;
  586|  14.4k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 0, False: 14.4k]
  ------------------
  587|      0|		return &e_unknown;
  588|       |
  589|  14.4k|	return file->acl[operation];
  590|  14.4k|}
sc_file_clear_acl_entries:
  593|  1.64M|{
  594|  1.64M|	sc_acl_entry_t *e;
  595|       |
  596|  1.64M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  1.64M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 1.64M]
  |  Branch (596:22): [True: 0, False: 1.64M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  1.64M|	e = file->acl[operation];
  601|  1.64M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 19.8k, False: 1.62M]
  ------------------
  602|  1.62M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 2.36k, False: 1.62M]
  ------------------
  603|  1.62M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 177, False: 1.62M]
  ------------------
  604|  22.4k|		file->acl[operation] = NULL;
  605|  22.4k|		return;
  606|  22.4k|	}
  607|       |
  608|  1.65M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 30.7k, False: 1.62M]
  ------------------
  609|  30.7k|		sc_acl_entry_t *tmp = e->next;
  610|  30.7k|		free(e);
  611|  30.7k|		e = tmp;
  612|  30.7k|	}
  613|       |	file->acl[operation] = NULL;
  614|  1.62M|}
sc_file_new:
  617|  52.2k|{
  618|  52.2k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|  52.2k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 52.2k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|  52.2k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  52.2k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|  52.2k|	return file;
  624|  52.2k|}
sc_file_free:
  627|   124k|{
  628|   124k|	unsigned int i;
  629|   124k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 72.6k, False: 52.2k]
  |  Branch (629:22): [True: 0, False: 52.2k]
  ------------------
  630|  72.6k|		return;
  631|  52.2k|	file->magic = 0;
  632|  1.67M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  1.67M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 1.62M, False: 52.2k]
  ------------------
  633|  1.62M|		sc_file_clear_acl_entries(file, i);
  634|  52.2k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 1.11k, False: 51.1k]
  ------------------
  635|  1.11k|		free(file->sec_attr);
  636|  52.2k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 539, False: 51.7k]
  ------------------
  637|    539|		free(file->prop_attr);
  638|  52.2k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 2.45k, False: 49.8k]
  ------------------
  639|  2.45k|		free(file->type_attr);
  640|  52.2k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 52.2k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|  52.2k|	free(file);
  643|  52.2k|}
sc_file_dup:
  646|    467|{
  647|    467|	sc_file_t *newf;
  648|    467|	const sc_acl_entry_t *e;
  649|    467|	unsigned int op;
  650|       |
  651|    467|	if (!dest)
  ------------------
  |  Branch (651:6): [True: 0, False: 467]
  ------------------
  652|      0|		return;
  653|    467|	*dest = NULL;
  654|    467|	if (!sc_file_valid(src))
  ------------------
  |  Branch (654:6): [True: 0, False: 467]
  ------------------
  655|      0|		return;
  656|    467|	newf = sc_file_new();
  657|    467|	if (newf == NULL)
  ------------------
  |  Branch (657:6): [True: 0, False: 467]
  ------------------
  658|      0|		return;
  659|    467|	*dest = newf;
  660|       |
  661|    467|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  662|    467|	memcpy(&newf->name, &src->name, sizeof(src->name));
  663|    467|	newf->namelen = src->namelen;
  664|    467|	newf->type    = src->type;
  665|    467|	newf->shareable    = src->shareable;
  666|    467|	newf->ef_structure = src->ef_structure;
  667|    467|	newf->size    = src->size;
  668|    467|	newf->id      = src->id;
  669|    467|	newf->status  = src->status;
  670|  14.9k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|  14.9k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (670:15): [True: 14.4k, False: 467]
  ------------------
  671|  14.4k|		newf->acl[op] = NULL;
  672|  14.4k|		e = sc_file_get_acl_entry(src, op);
  673|  14.4k|		if (e != NULL) {
  ------------------
  |  Branch (673:7): [True: 217, False: 14.2k]
  ------------------
  674|    217|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (674:8): [True: 0, False: 217]
  ------------------
  675|      0|				goto err;
  676|    217|		}
  677|  14.4k|	}
  678|    467|	newf->record_length = src->record_length;
  679|    467|	newf->record_count  = src->record_count;
  680|       |
  681|    467|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 467]
  ------------------
  682|      0|		goto err;
  683|    467|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 467]
  ------------------
  684|      0|		goto err;
  685|    467|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 467]
  ------------------
  686|      0|		goto err;
  687|    467|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (687:6): [True: 0, False: 467]
  ------------------
  688|      0|		goto err;
  689|    467|	return;
  690|    467|err:
  691|      0|	sc_file_free(newf);
  692|       |	*dest = NULL;
  693|      0|}
sc_file_set_sec_attr:
  697|  1.62k|{
  698|  1.62k|	u8 *tmp;
  699|  1.62k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (699:6): [True: 0, False: 1.62k]
  ------------------
  700|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  701|      0|	}
  702|       |
  703|  1.62k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (703:6): [True: 419, False: 1.20k]
  |  Branch (703:26): [True: 39, False: 1.16k]
  ------------------
  704|    458|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (704:7): [True: 10, False: 448]
  ------------------
  705|     10|			free(file->sec_attr);
  706|    458|		file->sec_attr = NULL;
  707|    458|		file->sec_attr_len = 0;
  708|    458|		return 0;
  709|    458|	 }
  710|  1.16k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  711|  1.16k|	if (!tmp) {
  ------------------
  |  Branch (711:6): [True: 0, False: 1.16k]
  ------------------
  712|      0|		if (file->sec_attr)
  ------------------
  |  Branch (712:7): [True: 0, False: 0]
  ------------------
  713|      0|			free(file->sec_attr);
  714|      0|		file->sec_attr     = NULL;
  715|      0|		file->sec_attr_len = 0;
  716|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  717|      0|	}
  718|  1.16k|	file->sec_attr = tmp;
  719|  1.16k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  720|  1.16k|	file->sec_attr_len = sec_attr_len;
  721|       |
  722|  1.16k|	return 0;
  723|  1.16k|}
sc_file_set_prop_attr:
  727|  1.10k|{
  728|  1.10k|	u8 *tmp;
  729|  1.10k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (729:6): [True: 0, False: 1.10k]
  ------------------
  730|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  731|      0|	}
  732|       |
  733|  1.10k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (733:6): [True: 379, False: 729]
  |  Branch (733:27): [True: 122, False: 607]
  ------------------
  734|    501|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (734:7): [True: 17, False: 484]
  ------------------
  735|     17|			free(file->prop_attr);
  736|    501|		file->prop_attr = NULL;
  737|    501|		file->prop_attr_len = 0;
  738|    501|		return SC_SUCCESS;
  ------------------
  |  |   28|    501|#define SC_SUCCESS				0
  ------------------
  739|    501|	 }
  740|    607|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  741|    607|	if (!tmp) {
  ------------------
  |  Branch (741:6): [True: 0, False: 607]
  ------------------
  742|      0|		if (file->prop_attr)
  ------------------
  |  Branch (742:7): [True: 0, False: 0]
  ------------------
  743|      0|			free(file->prop_attr);
  744|      0|		file->prop_attr = NULL;
  745|      0|		file->prop_attr_len = 0;
  746|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  747|      0|	}
  748|    607|	file->prop_attr = tmp;
  749|    607|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  750|    607|	file->prop_attr_len = prop_attr_len;
  751|       |
  752|    607|	return SC_SUCCESS;
  ------------------
  |  |   28|    607|#define SC_SUCCESS				0
  ------------------
  753|    607|}
sc_file_set_type_attr:
  757|  2.96k|{
  758|  2.96k|	u8 *tmp;
  759|  2.96k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (759:6): [True: 0, False: 2.96k]
  ------------------
  760|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  761|      0|	}
  762|       |
  763|  2.96k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (763:6): [True: 377, False: 2.58k]
  |  Branch (763:27): [True: 0, False: 2.58k]
  ------------------
  764|    377|		if (file->type_attr != NULL)
  ------------------
  |  Branch (764:7): [True: 0, False: 377]
  ------------------
  765|      0|			free(file->type_attr);
  766|    377|		file->type_attr = NULL;
  767|    377|		file->type_attr_len = 0;
  768|    377|		return SC_SUCCESS;
  ------------------
  |  |   28|    377|#define SC_SUCCESS				0
  ------------------
  769|    377|	 }
  770|  2.58k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  771|  2.58k|	if (!tmp) {
  ------------------
  |  Branch (771:6): [True: 0, False: 2.58k]
  ------------------
  772|      0|		if (file->type_attr)
  ------------------
  |  Branch (772:7): [True: 0, False: 0]
  ------------------
  773|      0|			free(file->type_attr);
  774|      0|		file->type_attr = NULL;
  775|      0|		file->type_attr_len = 0;
  776|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  777|      0|	}
  778|  2.58k|	file->type_attr = tmp;
  779|  2.58k|	memcpy(file->type_attr, type_attr, type_attr_len);
  780|  2.58k|	file->type_attr_len = type_attr_len;
  781|       |
  782|  2.58k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.58k|#define SC_SUCCESS				0
  ------------------
  783|  2.58k|}
sc_file_set_content:
  788|    467|{
  789|    467|	u8 *tmp;
  790|    467|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (790:6): [True: 0, False: 467]
  ------------------
  791|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  792|      0|	}
  793|       |
  794|    467|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (794:6): [True: 467, False: 0]
  |  Branch (794:25): [True: 0, False: 0]
  ------------------
  795|    467|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (795:7): [True: 0, False: 467]
  ------------------
  796|      0|			free(file->encoded_content);
  797|    467|		file->encoded_content = NULL;
  798|    467|		file->encoded_content_len = 0;
  799|    467|		return SC_SUCCESS;
  ------------------
  |  |   28|    467|#define SC_SUCCESS				0
  ------------------
  800|    467|	}
  801|       |
  802|      0|	tmp = (u8 *) realloc(file->encoded_content, content_len);
  803|      0|	if (!tmp) {
  ------------------
  |  Branch (803:6): [True: 0, False: 0]
  ------------------
  804|      0|		if (file->encoded_content)
  ------------------
  |  Branch (804:7): [True: 0, False: 0]
  ------------------
  805|      0|			free(file->encoded_content);
  806|      0|		file->encoded_content = NULL;
  807|      0|		file->encoded_content_len = 0;
  808|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  809|      0|	}
  810|       |
  811|      0|	file->encoded_content = tmp;
  812|      0|	memcpy(file->encoded_content, content, content_len);
  813|      0|	file->encoded_content_len = content_len;
  814|       |
  815|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  816|      0|}
sc_file_valid:
  819|  58.9k|int sc_file_valid(const sc_file_t *file) {
  820|  58.9k|	if (file == NULL)
  ------------------
  |  Branch (820:6): [True: 0, False: 58.9k]
  ------------------
  821|      0|		return 0;
  822|  58.9k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|  58.9k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  823|  58.9k|}
_sc_parse_atr:
  826|  8.49k|{
  827|  8.49k|	u8 *p = reader->atr.value;
  828|  8.49k|	int atr_len = (int) reader->atr.len;
  829|  8.49k|	int n_hist, x;
  830|  8.49k|	int tx[4] = {-1, -1, -1, -1};
  831|  8.49k|	int i, FI, DI;
  832|  8.49k|	const int Fi_table[] = {
  833|  8.49k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  834|  8.49k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  835|  8.49k|	const int f_table[] = {
  836|  8.49k|		40, 50, 60, 80, 120, 160, 200, -1,
  837|  8.49k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  838|  8.49k|	const int Di_table[] = {
  839|  8.49k|		-1, 1, 2, 4, 8, 16, 32, -1,
  840|  8.49k|		12, 20, -1, -1, -1, -1, -1, -1 };
  841|       |
  842|  8.49k|	reader->atr_info.hist_bytes_len = 0;
  843|  8.49k|	reader->atr_info.hist_bytes = NULL;
  844|       |
  845|  8.49k|	if (atr_len == 0) {
  ------------------
  |  Branch (845:6): [True: 2.42k, False: 6.06k]
  ------------------
  846|  2.42k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  847|  2.42k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.42k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  848|  2.42k|	}
  849|       |
  850|  6.06k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (850:6): [True: 342, False: 5.72k]
  |  Branch (850:22): [True: 303, False: 39]
  ------------------
  851|    303|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  852|    303|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    303|#define SC_ERROR_INTERNAL			-1400
  ------------------
  853|    303|	}
  854|  5.76k|	n_hist = p[1] & 0x0F;
  855|  5.76k|	x = p[1] >> 4;
  856|  5.76k|	p += 2;
  857|  5.76k|	atr_len -= 2;
  858|  28.7k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (858:14): [True: 23.0k, False: 5.74k]
  |  Branch (858:23): [True: 23.0k, False: 16]
  ------------------
  859|  23.0k|                if (x & (1 << i)) {
  ------------------
  |  Branch (859:21): [True: 16.2k, False: 6.72k]
  ------------------
  860|  16.2k|                        tx[i] = *p;
  861|  16.2k|                        p++;
  862|  16.2k|                        atr_len--;
  863|  16.2k|                } else
  864|  6.72k|                        tx[i] = -1;
  865|  23.0k|        }
  866|  5.76k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (866:6): [True: 5.10k, False: 654]
  ------------------
  867|  5.10k|		reader->atr_info.FI = FI = tx[0] >> 4;
  868|  5.10k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  869|  5.10k|		reader->atr_info.Fi = Fi_table[FI];
  870|  5.10k|		reader->atr_info.f = f_table[FI];
  871|  5.10k|		reader->atr_info.Di = Di_table[DI];
  872|  5.10k|	} else {
  873|    654|		reader->atr_info.Fi = -1;
  874|    654|		reader->atr_info.f = -1;
  875|    654|		reader->atr_info.Di = -1;
  876|    654|	}
  877|  5.76k|	if (tx[2] >= 0)
  ------------------
  |  Branch (877:6): [True: 3.50k, False: 2.25k]
  ------------------
  878|  3.50k|		reader->atr_info.N = tx[3];
  879|  2.25k|	else
  880|  2.25k|		reader->atr_info.N = -1;
  881|  12.6k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (881:9): [True: 7.31k, False: 5.38k]
  |  Branch (881:22): [True: 6.96k, False: 346]
  |  Branch (881:38): [True: 6.93k, False: 36]
  ------------------
  882|  6.93k|		x = tx[3] >> 4;
  883|  34.6k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (883:15): [True: 27.6k, False: 6.90k]
  |  Branch (883:24): [True: 27.6k, False: 25]
  ------------------
  884|  27.6k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (884:22): [True: 10.2k, False: 17.4k]
  ------------------
  885|  10.2k|	                        tx[i] = *p;
  886|  10.2k|	                        p++;
  887|  10.2k|	                        atr_len--;
  888|  10.2k|	                } else
  889|  17.4k|	                        tx[i] = -1;
  890|  27.6k|		}
  891|  6.93k|	}
  892|  5.76k|	if (atr_len <= 0)
  ------------------
  |  Branch (892:6): [True: 57, False: 5.70k]
  ------------------
  893|     57|		return SC_SUCCESS;
  ------------------
  |  |   28|     57|#define SC_SUCCESS				0
  ------------------
  894|  5.70k|	if (n_hist > atr_len)
  ------------------
  |  Branch (894:6): [True: 436, False: 5.27k]
  ------------------
  895|    436|		n_hist = atr_len;
  896|  5.70k|	reader->atr_info.hist_bytes_len = n_hist;
  897|  5.70k|	reader->atr_info.hist_bytes = p;
  898|  5.70k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.70k|#define SC_SUCCESS				0
  ------------------
  899|  5.76k|}
sc_mem_secure_alloc:
  902|     47|{
  903|     47|	void *p;
  904|       |
  905|       |#ifdef _WIN32
  906|       |	p = VirtualAlloc(NULL, len, MEM_COMMIT, PAGE_READWRITE);
  907|       |	if (p != NULL) {
  908|       |		VirtualLock(p, len);
  909|       |	}
  910|       |#else
  911|     47|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  912|     47|	if (p != NULL) {
  ------------------
  |  Branch (912:6): [True: 47, False: 0]
  ------------------
  913|     47|		mlock(p, len);
  914|     47|	}
  915|     47|#endif
  916|       |
  917|     47|	return p;
  918|     47|}
sc_mem_secure_free:
  921|     47|{
  922|       |#ifdef _WIN32
  923|       |	VirtualUnlock(ptr, len);
  924|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  925|       |#else
  926|     47|	munlock(ptr, len);
  927|     47|	munmap(ptr, len);
  928|     47|#endif
  929|     47|}
sc_mem_clear:
  932|  19.4k|{
  933|  19.4k|	if (len > 0)   {
  ------------------
  |  Branch (933:6): [True: 19.4k, False: 0]
  ------------------
  934|       |#ifdef HAVE_MEMSET_S
  935|       |		memset_s(ptr, len, 0, len);
  936|       |#elif _WIN32
  937|       |		SecureZeroMemory(ptr, len);
  938|       |#elif HAVE_EXPLICIT_BZERO
  939|       |		explicit_bzero(ptr, len);
  940|       |#elif ENABLE_OPENSSL
  941|       |		OPENSSL_cleanse(ptr, len);
  942|       |#else
  943|       |		memset(ptr, 0, len);
  944|       |#endif
  945|  19.4k|	}
  946|  19.4k|}
sc_compacttlv_find_tag:
 1060|    885|{
 1061|    885|	if (buf != NULL) {
  ------------------
  |  Branch (1061:6): [True: 885, False: 0]
  ------------------
 1062|    885|		size_t idx;
 1063|    885|		u8 plain_tag = tag & 0xF0;
 1064|    885|		size_t expected_len = tag & 0x0F;
 1065|       |
 1066|  9.75k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1066:17): [True: 9.47k, False: 285]
  ------------------
 1067|  9.47k|			u8 ctag = buf[idx] & 0xF0;
 1068|  9.47k|			size_t ctag_len = buf[idx] & 0x0F;
 1069|  9.47k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1069:8): [True: 1.07k, False: 8.39k]
  |  Branch (1069:29): [True: 1.05k, False: 26]
  ------------------
 1070|  1.05k|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1070:7): [True: 564, False: 489]
  |  Branch (1070:28): [True: 36, False: 453]
  ------------------
 1071|    600|				if (outlen != NULL)
  ------------------
  |  Branch (1071:9): [True: 564, False: 36]
  ------------------
 1072|    564|					*outlen = ctag_len;
 1073|    600|				return buf + (idx + 1);
 1074|    600|			}
 1075|  8.87k|			idx += ctag_len;
 1076|  8.87k|		}
 1077|    885|	}
 1078|    285|	return NULL;
 1079|    885|}
sc_mutex_create:
 1084|  16.9k|{
 1085|  16.9k|	if (ctx == NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 16.9k]
  ------------------
 1086|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1087|  16.9k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1087:6): [True: 0, False: 16.9k]
  |  Branch (1087:33): [True: 0, False: 0]
  ------------------
 1088|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1089|  16.9k|	else
 1090|  16.9k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.9k|#define SC_SUCCESS				0
  ------------------
 1091|  16.9k|}
sc_mutex_lock:
 1094|   692k|{
 1095|   692k|	if (ctx == NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 692k]
  ------------------
 1096|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1097|   692k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1097:6): [True: 0, False: 692k]
  |  Branch (1097:33): [True: 0, False: 0]
  ------------------
 1098|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1099|   692k|	else
 1100|   692k|		return SC_SUCCESS;
  ------------------
  |  |   28|   692k|#define SC_SUCCESS				0
  ------------------
 1101|   692k|}
sc_mutex_unlock:
 1104|   692k|{
 1105|   692k|	if (ctx == NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 692k]
  ------------------
 1106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1107|   692k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1107:6): [True: 0, False: 692k]
  |  Branch (1107:33): [True: 0, False: 0]
  ------------------
 1108|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1109|   692k|	else
 1110|   692k|		return SC_SUCCESS;
  ------------------
  |  |   28|   692k|#define SC_SUCCESS				0
  ------------------
 1111|   692k|}

sc_pin_cmd:
  204|  1.70k|{
  205|  1.70k|	int r, debug;
  206|       |
  207|  1.70k|	if (card == NULL) {
  ------------------
  |  Branch (207:6): [True: 0, False: 1.70k]
  ------------------
  208|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  209|      0|	}
  210|  1.70k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.70k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.70k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.70k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|       |
  212|  1.70k|	debug = card->ctx->debug;
  213|  1.70k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  418|  3.40k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (213:6): [True: 251, False: 1.45k]
  ------------------
  214|    251|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (214:7): [True: 242, False: 9]
  ------------------
  215|    242|		card->ctx->debug = 0;
  216|    242|	}
  217|       |
  218|  1.70k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (218:6): [True: 1.70k, False: 0]
  ------------------
  219|  1.70k|		r = card->ops->pin_cmd(card, data);
  220|  1.70k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  221|       |		/* Card driver doesn't support new style pin_cmd, fall
  222|       |		 * back to old interface */
  223|       |
  224|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  225|      0|		switch (data->cmd) {
  ------------------
  |  Branch (225:11): [True: 0, False: 0]
  ------------------
  226|      0|		case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (226:3): [True: 0, False: 0]
  ------------------
  227|      0|			if (card->ops->verify != NULL)
  ------------------
  |  Branch (227:8): [True: 0, False: 0]
  ------------------
  228|      0|				r = card->ops->verify(card,
  229|      0|					data->pin_type,
  230|      0|					data->pin_reference,
  231|      0|					data->pin1.data,
  232|      0|					(size_t) data->pin1.len,
  233|      0|					&data->pin1.tries_left);
  234|      0|			break;
  235|      0|		case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (235:3): [True: 0, False: 0]
  ------------------
  236|      0|			if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (236:8): [True: 0, False: 0]
  ------------------
  237|      0|				r = card->ops->change_reference_data(card,
  238|      0|					data->pin_type,
  239|      0|					data->pin_reference,
  240|      0|					data->pin1.data,
  241|      0|					(size_t) data->pin1.len,
  242|      0|					data->pin2.data,
  243|      0|					(size_t) data->pin2.len,
  244|      0|					&data->pin1.tries_left);
  245|      0|			break;
  246|      0|		case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (246:3): [True: 0, False: 0]
  ------------------
  247|      0|			if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (247:8): [True: 0, False: 0]
  ------------------
  248|      0|				r = card->ops->reset_retry_counter(card,
  249|      0|					data->pin_type,
  250|      0|					data->pin_reference,
  251|      0|					data->pin1.data,
  252|      0|					(size_t) data->pin1.len,
  253|      0|					data->pin2.data,
  254|      0|					(size_t) data->pin2.len);
  255|      0|			break;
  256|      0|		}
  257|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (257:7): [True: 0, False: 0]
  ------------------
  258|      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__
  |  |  ------------------
  ------------------
  259|      0|					data->cmd);
  260|      0|	} else {
  261|      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__
  |  |  ------------------
  ------------------
  262|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  263|      0|	}
  264|  1.70k|	card->ctx->debug = debug;
  265|       |
  266|  1.70k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.70k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.70k|	int _ret = r; \
  |  |  155|  1.70k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.70k, False: 0]
  |  |  ------------------
  |  |  156|  1.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.40k, False: 293]
  |  |  ------------------
  |  |  157|  1.70k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.70k|	} else { \
  |  |  159|      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.70k|	return _ret; \
  |  |  163|  1.70k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  267|  1.70k|}
sc_build_pin:
  281|    422|{
  282|    422|	size_t i = 0, j, pin_len = pin->len;
  283|       |
  284|    422|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (284:6): [True: 422, False: 0]
  |  Branch (284:25): [True: 12, False: 410]
  ------------------
  285|     12|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     12|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  286|       |
  287|    410|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|    410|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (287:6): [True: 0, False: 410]
  ------------------
  288|      0|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (288:10): [True: 0, False: 0]
  |  Branch (288:25): [True: 0, False: 0]
  ------------------
  289|      0|			pin_len--;
  290|      0|		if (pin_len > 12)
  ------------------
  |  Branch (290:7): [True: 0, False: 0]
  ------------------
  291|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  292|      0|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (292:15): [True: 0, False: 0]
  ------------------
  293|      0|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (293:8): [True: 0, False: 0]
  |  Branch (293:30): [True: 0, False: 0]
  ------------------
  294|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  295|      0|		}
  296|      0|		buf[0] = 0x20 | (u8) pin_len;
  297|      0|		buf++;
  298|      0|		buflen--;
  299|      0|	}
  300|       |
  301|       |	/* PIN given by application, encode if required */
  302|    410|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  425|    410|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (302:6): [True: 410, False: 0]
  ------------------
  303|    410|		if (pin_len > buflen)
  ------------------
  |  Branch (303:7): [True: 0, False: 410]
  ------------------
  304|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  305|    410|		memcpy(buf, pin->data, pin_len);
  306|    410|		i = pin_len;
  307|    410|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|      0|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (307:13): [True: 0, False: 0]
  |  Branch (307:53): [True: 0, False: 0]
  ------------------
  308|      0|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (308:7): [True: 0, False: 0]
  ------------------
  309|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  310|      0|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (310:19): [True: 0, False: 0]
  ------------------
  311|      0|			if (!isdigit(pin->data[j])) {
  ------------------
  |  Branch (311:8): [True: 0, False: 0]
  ------------------
  312|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  313|      0|			}
  314|      0|			buf[i] <<= 4;
  315|      0|			buf[i] |= pin->data[j] & 0xf;
  316|      0|			if (j & 1)
  ------------------
  |  Branch (316:8): [True: 0, False: 0]
  ------------------
  317|      0|				i++;
  318|      0|		}
  319|      0|		if (j & 1) {
  ------------------
  |  Branch (319:7): [True: 0, False: 0]
  ------------------
  320|      0|			buf[i] <<= 4;
  321|      0|			buf[i] |= pin->pad_char & 0xf;
  322|      0|			i++;
  323|      0|		}
  324|      0|	}
  325|       |
  326|       |	/* Pad to maximum PIN length if requested */
  327|    410|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|     11|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (327:6): [True: 399, False: 11]
  |  Branch (327:13): [True: 0, False: 11]
  ------------------
  328|    399|		size_t pad_length = pin->pad_length;
  329|    399|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  427|    399|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (329:23): [True: 0, False: 399]
  ------------------
  330|       |
  331|    399|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  426|    399|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (331:7): [True: 0, False: 399]
  ------------------
  332|      0|			pad_length >>= 1;
  333|    399|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  427|    399|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (333:7): [True: 0, False: 399]
  ------------------
  334|      0|			pad_length = 8;
  335|       |
  336|    399|		if (pad_length > buflen)
  ------------------
  |  Branch (336:7): [True: 0, False: 399]
  ------------------
  337|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  338|       |
  339|    399|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (339:7): [True: 399, False: 0]
  |  Branch (339:21): [True: 372, False: 27]
  ------------------
  340|    372|			memset(buf + i, pad_char, pad_length - i);
  341|    372|			i = pad_length;
  342|    372|		}
  343|    399|	}
  344|       |
  345|    410|	return (int)i;
  346|    410|}

sc_simpletlv_read_tag:
   77|  18.3k|{
   78|  18.3k|	u8 tag;
   79|  18.3k|	size_t left = buflen, len;
   80|  18.3k|	const u8 *p = *buf;
   81|       |
   82|  18.3k|	*buf = NULL;
   83|       |
   84|  18.3k|	if (left < 2) {
  ------------------
  |  Branch (84:6): [True: 119, False: 18.2k]
  ------------------
   85|    119|		return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    119|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   86|    119|	}
   87|  18.2k|	tag = *p;
   88|  18.2k|	p++;
   89|  18.2k|	len = *p;
   90|  18.2k|	p++;
   91|  18.2k|	left -= 2;
   92|       |
   93|  18.2k|	if (len == 0xff) {
  ------------------
  |  Branch (93:6): [True: 461, False: 17.7k]
  ------------------
   94|       |		/* don't crash on bad data */
   95|    461|		if (left < 2) {
  ------------------
  |  Branch (95:7): [True: 15, False: 446]
  ------------------
   96|     15|			return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|     15|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   97|     15|		}
   98|       |		/* skip two bytes (the size) */
   99|    446|		len = lebytes2ushort(p);
  100|    446|		p += 2;
  101|    446|		left -= 2;
  102|    446|	}
  103|       |
  104|  18.2k|	*tag_out = tag;
  105|  18.2k|	*taglen = len;
  106|  18.2k|	*buf = p;
  107|       |
  108|  18.2k|	if (len > left)
  ------------------
  |  Branch (108:6): [True: 852, False: 17.3k]
  ------------------
  109|    852|		return SC_ERROR_TLV_END_OF_CONTENTS;
  ------------------
  |  |   99|    852|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  110|       |
  111|  17.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  17.3k|#define SC_SUCCESS				0
  ------------------
  112|  18.2k|}

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

lookup_enum_spec:
 1337|    116|{
 1338|    116|	CK_ULONG i;
 1339|       |
 1340|  41.7k|	for(i = 0; i < spec->size; i++)
  ------------------
  |  Branch (1340:13): [True: 41.7k, False: 26]
  ------------------
 1341|  41.7k|		if(spec->specs[i].type == value)
  ------------------
  |  Branch (1341:6): [True: 90, False: 41.6k]
  ------------------
 1342|     90|			return spec->specs[i].name;
 1343|     26|	return NULL;
 1344|    116|}
lookup_enum:
 1349|    116|{
 1350|    116|	CK_ULONG i;
 1351|       |
 1352|    580|	for(i = 0; ck_types[i].type < ( sizeof(ck_types) / sizeof(enum_spec) ) ; i++)
  ------------------
  |  Branch (1352:13): [True: 580, False: 0]
  ------------------
 1353|    580|		if(ck_types[i].type == type)
  ------------------
  |  Branch (1353:6): [True: 116, False: 464]
  ------------------
 1354|    116|			return lookup_enum_spec(&(ck_types[i]), value);
 1355|      0|	return NULL;
 1356|    116|}

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

scconf_new:
   37|  8.50k|{
   38|  8.50k|	scconf_context *config;
   39|       |
   40|  8.50k|	config = calloc(1, sizeof(scconf_context));
   41|  8.50k|	if (!config) {
  ------------------
  |  Branch (41:6): [True: 0, False: 8.50k]
  ------------------
   42|      0|		return NULL;
   43|      0|	}
   44|  8.50k|	config->filename = filename ? strdup(filename) : NULL;
  ------------------
  |  Branch (44:21): [True: 8.50k, False: 0]
  ------------------
   45|  8.50k|	config->root = calloc(1, sizeof(scconf_block));
   46|  8.50k|	if (!config->root) {
  ------------------
  |  Branch (46:6): [True: 0, False: 8.50k]
  ------------------
   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|  8.50k|	return config;
   54|  8.50k|}
scconf_free:
   57|  8.50k|{
   58|  8.50k|	if (config) {
  ------------------
  |  Branch (58:6): [True: 8.50k, False: 0]
  ------------------
   59|  8.50k|		scconf_block_destroy(config->root);
   60|  8.50k|		if (config->filename) {
  ------------------
  |  Branch (60:7): [True: 8.50k, False: 0]
  ------------------
   61|  8.50k|			free(config->filename);
   62|  8.50k|		}
   63|  8.50k|		free(config);
   64|  8.50k|	}
   65|  8.50k|}
scconf_find_blocks:
   87|   439k|{
   88|   439k|	scconf_block **blocks = NULL, **tmp;
   89|   439k|	int alloc_size, size;
   90|   439k|	scconf_item *item;
   91|       |
   92|   439k|	if (!block) {
  ------------------
  |  Branch (92:6): [True: 25.5k, False: 414k]
  ------------------
   93|  25.5k|		block = config->root;
   94|  25.5k|	}
   95|   439k|	if (!item_name) {
  ------------------
  |  Branch (95:6): [True: 0, False: 439k]
  ------------------
   96|      0|		return NULL;
   97|      0|	}
   98|   439k|	size = 0;
   99|   439k|	alloc_size = 10;
  100|   439k|	tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
  101|   439k|	if (!tmp) {
  ------------------
  |  Branch (101:6): [True: 0, False: 439k]
  ------------------
  102|      0|		free(blocks);
  103|      0|		return NULL;
  104|      0|	}
  105|   439k|	blocks = tmp;
  106|       |
  107|   879k|	for (item = block->items; item; item = item->next) {
  ------------------
  |  Branch (107:28): [True: 439k, False: 439k]
  ------------------
  108|   439k|		if (item->type == SCCONF_ITEM_TYPE_BLOCK &&
  ------------------
  |  |   43|   879k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (108:7): [True: 25.5k, False: 414k]
  ------------------
  109|  25.5k|		    strcasecmp(item_name, item->key) == 0) {
  ------------------
  |  Branch (109:7): [True: 25.5k, False: 0]
  ------------------
  110|  25.5k|			if (!item->value.block)
  ------------------
  |  Branch (110:8): [True: 0, False: 25.5k]
  ------------------
  111|      0|				continue;
  112|  25.5k|			if (key && strcasecmp(key, item->value.block->name->data)) {
  ------------------
  |  Branch (112:8): [True: 25.5k, False: 0]
  |  Branch (112:15): [True: 17.0k, False: 8.50k]
  ------------------
  113|  17.0k|				continue;
  114|  17.0k|			}
  115|  8.50k|			if (size + 1 >= alloc_size) {
  ------------------
  |  Branch (115:8): [True: 0, False: 8.50k]
  ------------------
  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|  8.50k|			blocks[size++] = item->value.block;
  125|  8.50k|		}
  126|   439k|	}
  127|   439k|	blocks[size] = NULL;
  128|   439k|	return blocks;
  129|   439k|}
scconf_find_list:
  132|  72.4k|{
  133|  72.4k|	scconf_item *item;
  134|       |
  135|  72.4k|	if (!block)
  ------------------
  |  Branch (135:6): [True: 12.9k, False: 59.5k]
  ------------------
  136|  12.9k|		return NULL;
  137|       |
  138|   110k|	for (item = block->items; item; item = item->next)
  ------------------
  |  Branch (138:28): [True: 59.5k, False: 51.0k]
  ------------------
  139|  59.5k|		if (item->type == SCCONF_ITEM_TYPE_VALUE && strcasecmp(option, item->key) == 0)
  ------------------
  |  |   44|   119k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (139:7): [True: 59.5k, False: 0]
  |  Branch (139:47): [True: 8.50k, False: 51.0k]
  ------------------
  140|  8.50k|			return item->value.list;
  141|  51.0k|	return NULL;
  142|  59.5k|}
scconf_get_str:
  145|  18.0k|{
  146|  18.0k|	const scconf_list *list;
  147|       |
  148|  18.0k|	list = scconf_find_list(block, option);
  149|  18.0k|	if (!list)
  ------------------
  |  Branch (149:6): [True: 18.0k, False: 0]
  ------------------
  150|  18.0k|		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|  8.50k|{
  161|  8.50k|	const scconf_list *list;
  162|  8.50k|	long res;
  163|       |
  164|  8.50k|	list = scconf_find_list(block, option);
  165|  8.50k|	if (!list) {
  ------------------
  |  Branch (165:6): [True: 8.50k, False: 0]
  ------------------
  166|  8.50k|		return def;
  167|  8.50k|	}
  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|  37.4k|{
  177|  37.4k|	const scconf_list *list;
  178|       |
  179|  37.4k|	list = scconf_find_list(block, option);
  180|  37.4k|	if (!list) {
  ------------------
  |  Branch (180:6): [True: 37.4k, False: 0]
  ------------------
  181|  37.4k|		return def;
  182|  37.4k|	}
  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|  37.4k|}
scconf_item_destroy:
  257|  17.0k|{
  258|  17.0k|	scconf_item *next;
  259|       |
  260|  34.0k|	while (item) {
  ------------------
  |  Branch (260:9): [True: 17.0k, False: 17.0k]
  ------------------
  261|  17.0k|		next = item->next;
  262|       |
  263|  17.0k|		switch (item->type) {
  ------------------
  |  Branch (263:11): [True: 17.0k, 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: 17.0k]
  ------------------
  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|  8.50k|		case SCCONF_ITEM_TYPE_BLOCK:
  ------------------
  |  |   43|  8.50k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (270:3): [True: 8.50k, False: 8.50k]
  ------------------
  271|  8.50k|			scconf_block_destroy(item->value.block);
  272|  8.50k|			break;
  273|  8.50k|		case SCCONF_ITEM_TYPE_VALUE:
  ------------------
  |  |   44|  8.50k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (273:3): [True: 8.50k, False: 8.50k]
  ------------------
  274|  8.50k|			scconf_list_destroy(item->value.list);
  275|  8.50k|			break;
  276|  17.0k|		}
  277|       |
  278|  17.0k|		if (item->key) {
  ------------------
  |  Branch (278:7): [True: 17.0k, False: 0]
  ------------------
  279|  17.0k|			free(item->key);
  280|  17.0k|		}
  281|       |		item->key = NULL;
  282|  17.0k|		free(item);
  283|  17.0k|		item = next;
  284|  17.0k|	}
  285|  17.0k|}
scconf_block_destroy:
  310|  17.0k|{
  311|  17.0k|	if (block) {
  ------------------
  |  Branch (311:6): [True: 17.0k, False: 0]
  ------------------
  312|  17.0k|		scconf_list_destroy(block->name);
  313|  17.0k|		scconf_item_destroy(block->items);
  314|  17.0k|		free(block);
  315|  17.0k|	}
  316|  17.0k|}
scconf_list_add:
  319|  25.5k|{
  320|  25.5k|	scconf_list *rec, **tmp;
  321|       |
  322|  25.5k|	rec = calloc(1, sizeof(scconf_list));
  323|  25.5k|	if (!rec) {
  ------------------
  |  Branch (323:6): [True: 0, False: 25.5k]
  ------------------
  324|      0|		return NULL;
  325|      0|	}
  326|  25.5k|	rec->data = value ? strdup(value) : NULL;
  ------------------
  |  Branch (326:14): [True: 25.5k, False: 0]
  ------------------
  327|       |
  328|  25.5k|	if (!*list) {
  ------------------
  |  Branch (328:6): [True: 17.0k, False: 8.50k]
  ------------------
  329|  17.0k|		*list = rec;
  330|  17.0k|	} else {
  331|  17.0k|		for (tmp = list; *tmp; tmp = &(*tmp)->next);
  ------------------
  |  Branch (331:20): [True: 8.50k, False: 8.50k]
  ------------------
  332|  8.50k|		*tmp = rec;
  333|  8.50k|	}
  334|  25.5k|	return rec;
  335|  25.5k|}
scconf_list_destroy:
  350|  51.0k|{
  351|  51.0k|	scconf_list *next;
  352|       |
  353|  76.5k|	while (list) {
  ------------------
  |  Branch (353:9): [True: 25.5k, False: 51.0k]
  ------------------
  354|  25.5k|		next = list->next;
  355|  25.5k|		if (list->data) {
  ------------------
  |  Branch (355:7): [True: 25.5k, False: 0]
  ------------------
  356|  25.5k|			free(list->data);
  357|  25.5k|		}
  358|  25.5k|		free(list);
  359|  25.5k|		list = next;
  360|  25.5k|	}
  361|  51.0k|}

scconf_lex_parse:
  181|  8.50k|{
  182|  8.50k|	FILE *fp;
  183|  8.50k|	BUFHAN bhan;
  184|  8.50k|	int ret;
  185|       |
  186|  8.50k|	fp = fopen(filename, "r");
  187|  8.50k|	if (!fp) {
  ------------------
  |  Branch (187:6): [True: 8.50k, False: 0]
  ------------------
  188|  8.50k|		parser->error = 1;
  189|  8.50k|		snprintf(parser->emesg, sizeof(parser->emesg),
  190|  8.50k|			 "File %s can't be opened\n", filename);
  191|  8.50k|		return 0;
  192|  8.50k|	}
  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|  8.50k|}
scconf_lex_parse_string:
  200|  8.50k|{
  201|  8.50k|	BUFHAN bhan;
  202|  8.50k|	int ret;
  203|       |
  204|       |	buf_init(&bhan, (FILE *) NULL, string);
  205|  8.50k|	ret = scconf_lex_engine(parser, &bhan);
  206|  8.50k|	return ret;
  207|  8.50k|}
sclex.c:buf_init:
   44|  8.50k|{
   45|  8.50k|	bp->fp = fp;
   46|  8.50k|	bp->saved_char = 0;
   47|  8.50k|	bp->buf = malloc(256);
   48|  8.50k|	if (bp->buf) {
  ------------------
  |  Branch (48:6): [True: 8.50k, False: 0]
  ------------------
   49|  8.50k|		bp->bufmax = 256;
   50|  8.50k|		bp->buf[0] = '\0';
   51|  8.50k|	} else
   52|      0|		bp->bufmax = 0;
   53|  8.50k|	bp->bufcur = 0;
   54|  8.50k|	bp->saved_string = saved_string;
   55|  8.50k|}
sclex.c:scconf_lex_engine:
  126|  8.50k|{
  127|  8.50k|	int this_char;
  128|       |
  129|   153k|	while (1) {
  ------------------
  |  Branch (129:9): [True: 153k, Folded]
  ------------------
  130|   153k|		switch (this_char = buf_nextch(bp)) {
  131|      0|		case '#':
  ------------------
  |  Branch (131:3): [True: 0, False: 153k]
  ------------------
  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: 153k]
  ------------------
  138|      0|			scconf_parse_token(parser, TOKEN_TYPE_NEWLINE, NULL);
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  139|      0|			continue;
  140|  59.5k|		case ' ':
  ------------------
  |  Branch (140:3): [True: 59.5k, False: 93.5k]
  ------------------
  141|  59.5k|		case '\t':
  ------------------
  |  Branch (141:3): [True: 0, False: 153k]
  ------------------
  142|  59.5k|		case '\r':
  ------------------
  |  Branch (142:3): [True: 0, False: 153k]
  ------------------
  143|       |			/* eat up whitespace */
  144|  59.5k|			continue;
  145|  8.50k|		case ',':
  ------------------
  |  Branch (145:3): [True: 8.50k, False: 144k]
  ------------------
  146|  17.0k|		case '{':
  ------------------
  |  Branch (146:3): [True: 8.50k, False: 144k]
  ------------------
  147|  17.0k|			if (parser->nested_blocks >= DEPTH_LIMIT) {
  ------------------
  |  |   36|  17.0k|#define DEPTH_LIMIT 16
  ------------------
  |  Branch (147:8): [True: 0, False: 17.0k]
  ------------------
  148|       |				/* reached the limit, this whole block */
  149|      0|				scconf_skip_block(parser);
  150|      0|				continue;
  151|      0|			}
  152|       |			/* fall through */
  153|  25.5k|		case '}':
  ------------------
  |  Branch (153:3): [True: 8.50k, False: 144k]
  ------------------
  154|  34.0k|		case '=':
  ------------------
  |  Branch (154:3): [True: 8.50k, False: 144k]
  ------------------
  155|  42.5k|		case ';':
  ------------------
  |  Branch (155:3): [True: 8.50k, False: 144k]
  ------------------
  156|  42.5k|			buf_addch(bp, (char) this_char);
  157|  42.5k|			scconf_parse_token(parser, TOKEN_TYPE_PUNCT, bp->buf);
  ------------------
  |  |   34|  42.5k|#define TOKEN_TYPE_PUNCT	3
  ------------------
  158|  42.5k|			buf_zero(bp);
  159|  42.5k|			continue;
  160|      0|		case '"':
  ------------------
  |  Branch (160:3): [True: 0, False: 153k]
  ------------------
  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|  8.50k|		case EOF:
  ------------------
  |  Branch (166:3): [True: 8.50k, False: 144k]
  ------------------
  167|  8.50k|			break;
  168|  42.5k|		default:
  ------------------
  |  Branch (168:3): [True: 42.5k, False: 110k]
  ------------------
  169|  42.5k|			buf_eat_till(bp, (char) this_char, ";, \t\r\n");
  170|  42.5k|			scconf_parse_token(parser, TOKEN_TYPE_STRING, bp->buf);
  ------------------
  |  |   33|  42.5k|#define TOKEN_TYPE_STRING	2
  ------------------
  171|  42.5k|			buf_zero(bp);
  172|  42.5k|			continue;
  173|   153k|		}
  174|  8.50k|		break;
  175|   153k|	}
  176|  8.50k|	buf_finished(bp);
  177|  8.50k|	return 1;
  178|  8.50k|}
sclex.c:buf_nextch:
   73|   433k|{
   74|   433k|	int saved;
   75|       |
   76|   433k|	if (bp->saved_char) {
  ------------------
  |  Branch (76:6): [True: 42.5k, False: 391k]
  ------------------
   77|  42.5k|		saved = bp->saved_char;
   78|  42.5k|		bp->saved_char = 0;
   79|  42.5k|		return saved;
   80|  42.5k|	}
   81|   391k|	if (bp->saved_string) {
  ------------------
  |  Branch (81:6): [True: 391k, False: 0]
  ------------------
   82|   391k|		if (*(bp->saved_string) == '\0')
  ------------------
  |  Branch (82:7): [True: 8.50k, False: 382k]
  ------------------
   83|  8.50k|			return EOF;
   84|   382k|		saved = (unsigned char) (*(bp->saved_string++));
   85|   382k|		return saved;
   86|   391k|	} else {
   87|      0|		saved = fgetc(bp->fp);
   88|      0|		return saved;
   89|      0|	}
   90|   391k|}
sclex.c:buf_eat_till:
  101|  42.5k|{
  102|  42.5k|	int i;
  103|       |
  104|  42.5k|	if (start) {
  ------------------
  |  Branch (104:6): [True: 42.5k, False: 0]
  ------------------
  105|  42.5k|		buf_addch(bp, start);
  106|  42.5k|	}
  107|   280k|	while (1) {
  ------------------
  |  Branch (107:9): [True: 280k, Folded]
  ------------------
  108|   280k|		i = buf_nextch(bp);
  109|   280k|		if (i == EOF)
  ------------------
  |  Branch (109:7): [True: 0, False: 280k]
  ------------------
  110|      0|			return;
  111|   280k|		if (strchr(end, i)) {
  ------------------
  |  Branch (111:7): [True: 42.5k, False: 238k]
  ------------------
  112|  42.5k|			bp->saved_char = i;
  113|  42.5k|			return;
  114|  42.5k|		}
  115|   238k|		buf_addch(bp, (char) i);
  116|   238k|	}
  117|  42.5k|}
sclex.c:buf_zero:
  120|  85.0k|{
  121|  85.0k|	bp->bufcur = 0;
  122|  85.0k|	bp->buf[0] = '\0';
  123|  85.0k|}
sclex.c:buf_addch:
   58|   323k|{
   59|   323k|	if (bp->bufcur + 1 >= bp->bufmax) {
  ------------------
  |  Branch (59:6): [True: 0, False: 323k]
  ------------------
   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|   323k|	if (bp->buf) {
  ------------------
  |  Branch (66:6): [True: 323k, False: 0]
  ------------------
   67|   323k|		bp->buf[bp->bufcur++] = ch;
   68|   323k|		bp->buf[bp->bufcur] = '\0';
   69|   323k|	}
   70|   323k|}
sclex.c:buf_finished:
   93|  8.50k|{
   94|  8.50k|	if (bp->buf) {
  ------------------
  |  Branch (94:6): [True: 8.50k, False: 0]
  ------------------
   95|  8.50k|		free(bp->buf);
   96|       |		bp->buf = NULL;
   97|  8.50k|	}
   98|  8.50k|}

fuzz_util_connect_card:
   52|  8.49k|{
   53|       |	return fuzz_connect_card(ctx, card, NULL, reader_data, reader_data_size);
   54|  8.49k|}
initialize_global:
   57|  8.80k|{
   58|       |	/* Global variables need to be reser between runs,
   59|       |	   fuzz target is called repetitively in one execution */
   60|  8.80k|	ctx = NULL;
   61|  8.80k|	card = NULL;
   62|  8.80k|	p15card = NULL;
   63|  8.80k|	opt_auth_id = NULL;
   64|  8.80k|	opt_reader = NULL;
   65|  8.80k|	opt_cert = NULL;
   66|  8.80k|	opt_data = NULL;
   67|  8.80k|	opt_pubkey = NULL;
   68|  8.80k|	opt_outfile = NULL;
   69|  8.80k|	opt_bind_to_aid = NULL;
   70|  8.80k|	opt_newpin = NULL;
   71|  8.80k|	opt_pin = NULL;
   72|  8.80k|	opt_puk = NULL;
   73|       |
   74|  8.80k|	optind = 0;
   75|  8.80k|	opterr = 0; /* do not print out error messages */
   76|  8.80k|	optopt = 0;
   77|       |
   78|  8.80k|	verbose = 0;
   79|  8.80k|	compact = 0;
   80|  8.80k|	opt_no_cache = 0;
   81|  8.80k|	opt_clear_cache = 0;
   82|  8.80k|	opt_wait = 0;
   83|  8.80k|	opt_raw = 0;
   84|  8.80k|	opt_use_pinpad = 0;
   85|  8.80k|}
LLVMFuzzerTestOneInput:
   88|  8.80k|{
   89|  8.80k|	char **argv = NULL;
   90|  8.80k|	int argc = 0;
   91|       |
   92|  8.80k|	if (size < 10)
  ------------------
  |  Branch (92:6): [True: 6, False: 8.80k]
  ------------------
   93|      6|		return 0;
   94|       |
   95|  8.80k|#ifdef FUZZING_ENABLED
   96|  8.80k|	fclose(stdout);
   97|  8.80k|#endif
   98|  8.80k|	initialize_global();
   99|       |
  100|  8.80k|	if (get_fuzzed_argv("./fuzz_pkcs15", data, size, &argv, &argc, &reader_data, &reader_data_size) != 0)
  ------------------
  |  Branch (100:6): [True: 9, False: 8.79k]
  ------------------
  101|      9|		return 0;
  102|  8.79k|	_main(argc, argv);
  103|  8.79k|	free_arguments(argc, argv);
  104|       |
  105|  8.79k|	return 0;
  106|  8.80k|}

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

get_word:
   26|   545k|{
   27|       |	/* Words are separated by one zero byte,
   28|       |	   return pointer to the next word if there is one */
   29|   545k|	const uint8_t *ptr = data;
   30|   545k|	if (!data || size == 0 || *data == 0)
  ------------------
  |  Branch (30:6): [True: 0, False: 545k]
  |  Branch (30:15): [True: 0, False: 545k]
  |  Branch (30:28): [True: 0, False: 545k]
  ------------------
   31|      0|		return NULL;
   32|       |	
   33|   545k|	ptr = memchr(data, 0, size - 1);
   34|   545k|	return ptr ? ++ptr : NULL;
  ------------------
  |  Branch (34:9): [True: 545k, False: 7]
  ------------------
   35|   545k|}
extract_word:
   38|   207k|{
   39|       |	/* Find word and return its copy (needs to be freed) */
   40|   207k|	char *result = NULL;
   41|   207k|	const uint8_t *ptr = NULL;
   42|       |
   43|   207k|	if (*size < 2)
  ------------------
  |  Branch (43:6): [True: 0, False: 207k]
  ------------------
   44|      0|		return NULL;
   45|       |
   46|   207k|	ptr = get_word(*data, *size);
   47|   207k|	if (!ptr)
  ------------------
  |  Branch (47:6): [True: 0, False: 207k]
  ------------------
   48|      0|		return NULL;
   49|   207k|	result = strdup((const char *)*data);
   50|   207k|	*size -=(ptr - *data);
   51|   207k|	*data = ptr;
   52|       |
   53|   207k|	return result;
   54|   207k|}
get_fuzzed_argv:
   58|  8.80k|{
   59|  8.80k|	const uint8_t *ptr = data, *help_ptr = data;
   60|  8.80k|	size_t ptr_size = size;
   61|  8.80k|	char **argv = NULL;
   62|  8.80k|	int argc = 1;
   63|       |
   64|       |	/* Count arguments until double zero bytes occurs*/
   65|   347k|	while(*ptr != 0) {
  ------------------
  |  Branch (65:8): [True: 338k, False: 8.79k]
  ------------------
   66|   338k|		ptr = get_word(help_ptr, ptr_size);
   67|   338k|		if (!ptr)
  ------------------
  |  Branch (67:7): [True: 7, False: 338k]
  ------------------
   68|      7|			return -1;
   69|   338k|		argc++;
   70|   338k|		ptr_size -= (ptr - help_ptr);
   71|   338k|		help_ptr = ptr;
   72|   338k|	}
   73|       |
   74|  8.79k|	if (argc > MAX_ARGC)
  ------------------
  |  |   23|  8.79k|#define MAX_ARGC 10000
  ------------------
  |  Branch (74:6): [True: 2, False: 8.79k]
  ------------------
   75|      2|		return -1;
   76|       |
   77|  8.79k|	argv = malloc((argc + 1) * sizeof(char*));
   78|  8.79k|	if (!argv)
  ------------------
  |  Branch (78:6): [True: 0, False: 8.79k]
  ------------------
   79|      0|		return -1;
   80|       |
   81|       |	/* Copy arguments into argv */
   82|  8.79k|	ptr = data;
   83|  8.79k|	ptr_size = size;
   84|  8.79k|	argv[0] = strdup(app_name);
   85|   215k|	for (int i = 1; i < argc; i++) {
  ------------------
  |  Branch (85:18): [True: 207k, False: 8.79k]
  ------------------
   86|   207k|		argv[i] = extract_word(&ptr, &ptr_size);
   87|   207k|	}
   88|  8.79k|	argv[argc] = NULL;
   89|       |
   90|  8.79k|	*argc_out = argc;
   91|  8.79k|	*argv_out = argv;
   92|  8.79k|	*reader_data = ptr + 1; /* there are two zero bytes at the end of argv */
   93|  8.79k|	*reader_data_size = ptr_size - 1;
   94|  8.79k|	return 0;
   95|  8.79k|}
free_arguments:
  166|  8.79k|{
  167|   224k|	for (int i = 0; i < argc; i++) {
  ------------------
  |  Branch (167:18): [True: 215k, False: 8.79k]
  ------------------
  168|   215k|		free(argv[i]);
  169|   215k|	}
  170|  8.79k|	free(argv);
  171|  8.79k|}

_main:
 2128|  8.79k|{
 2129|  8.79k|	int err = 0, r, c, long_optind = 0;
 2130|  8.79k|	int do_read_cert = 0;
 2131|  8.79k|	int do_list_certs = 0;
 2132|  8.79k|	int do_read_data_object = 0;
 2133|  8.79k|	int do_list_data_objects = 0;
 2134|  8.79k|	int do_list_pins = 0;
 2135|  8.79k|	int do_list_skeys = 0;
 2136|  8.79k|	int do_list_apps = 0;
 2137|  8.79k|	int do_dump = 0;
 2138|  8.79k|	int do_list_prkeys = 0;
 2139|  8.79k|	int do_list_pubkeys = 0;
 2140|  8.79k|	int do_read_pubkey = 0;
 2141|  8.79k|#if defined(ENABLE_OPENSSL) && (defined(_WIN32) || defined(HAVE_INTTYPES_H))
 2142|  8.79k|	int do_read_sshkey = 0;
 2143|  8.79k|#endif
 2144|  8.79k|	int do_verify_pin = 0;
 2145|  8.79k|	int do_change_pin = 0;
 2146|  8.79k|	int do_unblock_pin = 0;
 2147|  8.79k|	int do_test_update = 0;
 2148|  8.79k|	int do_test_session_pin = 0;
 2149|  8.79k|	int do_update = 0;
 2150|  8.79k|	int do_print_version = 0;
 2151|  8.79k|	int do_list_info = 0;
 2152|  8.79k|	int action_count = 0;
 2153|  8.79k|	sc_context_param_t ctx_param;
 2154|       |
 2155|  8.79k|	static_assert(sizeof(option_help) / sizeof(char *) == sizeof(options) / sizeof(struct option),
 2156|  8.79k|			"internal error");
 2157|       |
 2158|  1.35M|	while (1) {
  ------------------
  |  Branch (2158:9): [True: 1.35M, Folded]
  ------------------
 2159|  1.35M|		c = getopt_long(argc, argv, "r:cuko:sva:LR:CwDTU", options, &long_optind);
 2160|  1.35M|		if (c == -1)
  ------------------
  |  Branch (2160:7): [True: 8.76k, False: 1.34M]
  ------------------
 2161|  8.76k|			break;
 2162|  1.34M|		if (c == '?') {
  ------------------
  |  Branch (2162:7): [True: 26, False: 1.34M]
  ------------------
 2163|     26|			util_print_usage(app_name, options, option_help, NULL);
 2164|     26|			return 2;
 2165|     26|		}
 2166|  1.34M|		switch (c) {
  ------------------
  |  Branch (2166:11): [True: 1.34M, False: 1.06k]
  ------------------
 2167|    912|		case 'r':
  ------------------
  |  Branch (2167:3): [True: 912, False: 1.34M]
  ------------------
 2168|       |
 2169|       |#if OPENSC_MAJOR == 0 &&  OPENSC_VERSION_MINOR == 19
 2170|       |			fprintf(stderr, "\nWarning, option -r is reserved to specify card reader in future versions\n");
 2171|       |			fprintf (stderr, "Using -r option for read-certificate operation\n\n");
 2172|       |			opt_cert = optarg;
 2173|       |			do_read_cert = 1;
 2174|       |			action_count++;
 2175|       |			break;
 2176|       |#elif OPENSC_MAJOR == 0 &&  OPENSC_VERSION_MINOR == 20
 2177|       |
 2178|       |			memset(&ctx_param, 0, sizeof(ctx_param));
 2179|       |			ctx_param.ver      = 0;
 2180|       |			ctx_param.app_name = app_name;
 2181|       |			if (verbose)
 2182|       |				ctx_param.debug_file = stderr;
 2183|       |
 2184|       |			if (SC_SUCCESS == sc_context_create(&ctx, &ctx_param)) {
 2185|       |				/* attempt to connect reader, on error, -r is used for read-certificate operation */
 2186|       |				struct sc_reader *reader = NULL;
 2187|       |
 2188|       |				err = util_connect_reader(ctx, &reader, optarg, 0, 0);
 2189|       |				sc_release_context(ctx);
 2190|       |				ctx = NULL;
 2191|       |
 2192|       |				if (err != SC_SUCCESS ) {
 2193|       |#if 1
 2194|       |					fprintf (stderr,
 2195|       |						"Error, option -r is reserved to specify card reader, no reader \"%s\" found\n", optarg);
 2196|       |					exit (1);
 2197|       |#else
 2198|       |					fprintf (stderr,
 2199|       |						"\nWarning, option -r is reserved to specify card reader, no reader \"%s\" found\n", optarg);
 2200|       |					fprintf (stderr, "Using -r option for read-certificate operation\n\n");
 2201|       |					opt_cert = optarg;
 2202|       |					do_read_cert = 1;
 2203|       |					action_count++;
 2204|       |					break;
 2205|       |#endif
 2206|       |				}
 2207|       |			}
 2208|       |			opt_reader = optarg;
 2209|       |			break;
 2210|       |#elif (OPENSC_MAJOR > 0) || (OPENSC_MAJOR == 0 && OPENSC_VERSION_MINOR > 20)
 2211|       |
 2212|    912|			opt_reader = optarg;
 2213|    912|			break;
 2214|      0|#endif
 2215|       |
 2216|  1.26k|		case OPT_PRINT_VERSION:
  ------------------
  |  Branch (2216:3): [True: 1.26k, False: 1.34M]
  ------------------
 2217|  1.26k|			do_print_version = 1;
 2218|  1.26k|			action_count++;
 2219|  1.26k|			break;
 2220|    206|		case OPT_LIST_INFO:
  ------------------
  |  Branch (2220:3): [True: 206, False: 1.34M]
  ------------------
 2221|    206|			do_list_info = 1;
 2222|    206|			action_count++;
 2223|    206|			break;
 2224|    778|		case OPT_READ_CERT:
  ------------------
  |  Branch (2224:3): [True: 778, False: 1.34M]
  ------------------
 2225|    778|			opt_cert = optarg;
 2226|    778|			do_read_cert = 1;
 2227|    778|			action_count++;
 2228|    778|			break;
 2229|  4.59k|		case 'c':
  ------------------
  |  Branch (2229:3): [True: 4.59k, False: 1.34M]
  ------------------
 2230|  4.59k|			do_list_certs = 1;
 2231|  4.59k|			action_count++;
 2232|  4.59k|			break;
 2233|  2.35k|		case 'R':
  ------------------
  |  Branch (2233:3): [True: 2.35k, False: 1.34M]
  ------------------
 2234|  2.35k|			opt_data = optarg;
 2235|  2.35k|			do_read_data_object = 1;
 2236|  2.35k|			action_count++;
 2237|  2.35k|			break;
 2238|    239|		case OPT_RAW:
  ------------------
  |  Branch (2238:3): [True: 239, False: 1.34M]
  ------------------
 2239|    239|			opt_raw = 1;
 2240|    239|			break;
 2241|   342k|		case 'C':
  ------------------
  |  Branch (2241:3): [True: 342k, False: 1.00M]
  ------------------
 2242|   342k|			do_list_data_objects = 1;
 2243|   342k|			action_count++;
 2244|   342k|			break;
 2245|  1.20k|		case OPT_VERIFY_PIN:
  ------------------
  |  Branch (2245:3): [True: 1.20k, False: 1.34M]
  ------------------
 2246|  1.20k|			do_verify_pin = 1;
 2247|  1.20k|			action_count++;
 2248|  1.20k|			break;
 2249|    522|		case OPT_CHANGE_PIN:
  ------------------
  |  Branch (2249:3): [True: 522, False: 1.34M]
  ------------------
 2250|    522|			do_change_pin = 1;
 2251|    522|			action_count++;
 2252|    522|			break;
 2253|   800k|		case 'u':
  ------------------
  |  Branch (2253:3): [True: 800k, False: 546k]
  ------------------
 2254|   800k|			do_unblock_pin = 1;
 2255|   800k|			action_count++;
 2256|   800k|			break;
 2257|    384|		case OPT_LIST_PINS:
  ------------------
  |  Branch (2257:3): [True: 384, False: 1.34M]
  ------------------
 2258|    384|			do_list_pins = 1;
 2259|    384|			action_count++;
 2260|    384|			break;
 2261|    224|		case OPT_LIST_SKEYS:
  ------------------
  |  Branch (2261:3): [True: 224, False: 1.34M]
  ------------------
 2262|    224|			do_list_skeys = 1;
 2263|    224|			action_count++;
 2264|    224|			break;
 2265|  2.73k|		case 'D':
  ------------------
  |  Branch (2265:3): [True: 2.73k, False: 1.34M]
  ------------------
 2266|  2.73k|			do_dump = 1;
 2267|  2.73k|			action_count++;
 2268|  2.73k|			break;
 2269|  29.3k|		case 'k':
  ------------------
  |  Branch (2269:3): [True: 29.3k, False: 1.31M]
  ------------------
 2270|  29.3k|			do_list_prkeys = 1;
 2271|  29.3k|			action_count++;
 2272|  29.3k|			break;
 2273|    318|		case OPT_LIST_PUB:
  ------------------
  |  Branch (2273:3): [True: 318, False: 1.34M]
  ------------------
 2274|    318|			do_list_pubkeys = 1;
 2275|    318|			action_count++;
 2276|    318|			break;
 2277|  1.24k|		case OPT_READ_PUB:
  ------------------
  |  Branch (2277:3): [True: 1.24k, False: 1.34M]
  ------------------
 2278|  1.24k|			opt_pubkey = optarg;
 2279|  1.24k|			do_read_pubkey = 1;
 2280|  1.24k|			action_count++;
 2281|  1.24k|			break;
 2282|      0|#if defined(ENABLE_OPENSSL) && (defined(_WIN32) || defined(HAVE_INTTYPES_H))
 2283|    215|		case OPT_READ_SSH:
  ------------------
  |  Branch (2283:3): [True: 215, False: 1.34M]
  ------------------
 2284|    215|			opt_pubkey = optarg;
 2285|    215|			do_read_sshkey = 1;
 2286|    215|			action_count++;
 2287|    215|			break;
 2288|    199|		case OPT_RFC4716:
  ------------------
  |  Branch (2288:3): [True: 199, False: 1.34M]
  ------------------
 2289|    199|			opt_rfc4716 = 1;
 2290|    199|			break;
 2291|      0|#endif
 2292|  2.03k|		case 'T':
  ------------------
  |  Branch (2292:3): [True: 2.03k, False: 1.34M]
  ------------------
 2293|  2.03k|			do_test_update = 1;
 2294|  2.03k|			action_count++;
 2295|  2.03k|			break;
 2296|    563|		case OPT_TEST_SESSION_PIN:
  ------------------
  |  Branch (2296:3): [True: 563, False: 1.34M]
  ------------------
 2297|    563|			do_test_session_pin = 1;
 2298|    563|			action_count++;
 2299|    563|			break;
 2300|  7.31k|		case 'U':
  ------------------
  |  Branch (2300:3): [True: 7.31k, False: 1.33M]
  ------------------
 2301|  7.31k|			do_update = 1;
 2302|  7.31k|			action_count++;
 2303|  7.31k|			break;
 2304|    226|		case OPT_READER:
  ------------------
  |  Branch (2304:3): [True: 226, False: 1.34M]
  ------------------
 2305|    226|			opt_reader = optarg;
 2306|    226|			break;
 2307|  9.56k|		case OPT_PIN:
  ------------------
  |  Branch (2307:3): [True: 9.56k, False: 1.33M]
  ------------------
 2308|  9.56k|			util_get_pin(optarg, &opt_pin);
 2309|  9.56k|			break;
 2310|    837|		case OPT_NEWPIN:
  ------------------
  |  Branch (2310:3): [True: 837, False: 1.34M]
  ------------------
 2311|    837|			util_get_pin(optarg, &opt_newpin);
 2312|    837|			break;
 2313|    861|		case OPT_PUK:
  ------------------
  |  Branch (2313:3): [True: 861, False: 1.34M]
  ------------------
 2314|    861|			util_get_pin(optarg, &opt_puk);
 2315|    861|			break;
 2316|    920|		case 'o':
  ------------------
  |  Branch (2316:3): [True: 920, False: 1.34M]
  ------------------
 2317|    920|			opt_outfile = optarg;
 2318|    920|			break;
 2319|  15.4k|		case 's':
  ------------------
  |  Branch (2319:3): [True: 15.4k, False: 1.33M]
  ------------------
 2320|  15.4k|			compact++;
 2321|  15.4k|			break;
 2322|  96.5k|		case 'v':
  ------------------
  |  Branch (2322:3): [True: 96.5k, False: 1.25M]
  ------------------
 2323|  96.5k|			verbose++;
 2324|  96.5k|			break;
 2325|  6.04k|		case 'a':
  ------------------
  |  Branch (2325:3): [True: 6.04k, False: 1.34M]
  ------------------
 2326|  6.04k|			opt_auth_id = optarg;
 2327|  6.04k|			break;
 2328|  1.58k|		case OPT_BIND_TO_AID:
  ------------------
  |  Branch (2328:3): [True: 1.58k, False: 1.34M]
  ------------------
 2329|  1.58k|			opt_bind_to_aid = optarg;
 2330|  1.58k|			break;
 2331|    200|		case OPT_LIST_APPLICATIONS:
  ------------------
  |  Branch (2331:3): [True: 200, False: 1.34M]
  ------------------
 2332|    200|			do_list_apps = 1;
 2333|    200|			action_count++;
 2334|    200|			break;
 2335|  1.01k|		case OPT_NO_CACHE:
  ------------------
  |  Branch (2335:3): [True: 1.01k, False: 1.34M]
  ------------------
 2336|  1.01k|			opt_no_cache++;
 2337|  1.01k|			break;
 2338|    345|		case OPT_CLEAR_CACHE:
  ------------------
  |  Branch (2338:3): [True: 345, False: 1.34M]
  ------------------
 2339|    345|			opt_clear_cache = 1;
 2340|    345|			action_count++;
 2341|    345|			break;
 2342|  10.1k|		case 'w':
  ------------------
  |  Branch (2342:3): [True: 10.1k, False: 1.33M]
  ------------------
 2343|  10.1k|			opt_wait = 1;
 2344|  10.1k|			break;
 2345|  2.67k|		case OPT_USE_PINPAD_DEPRECATED:
  ------------------
  |  Branch (2345:3): [True: 2.67k, False: 1.34M]
  ------------------
 2346|  2.67k|			fprintf(stderr, "'--no-prompt' is deprecated , use '--use-pinpad' instead.\n");
  ------------------
  |  |   39|  2.67k|#define stderr stdout
  ------------------
 2347|       |			/* fallthrough */
 2348|  2.86k|		case OPT_USE_PINPAD:
  ------------------
  |  Branch (2348:3): [True: 199, False: 1.34M]
  ------------------
 2349|  2.86k|			opt_use_pinpad = 1;
 2350|  2.86k|			break;
 2351|  1.34M|		}
 2352|  1.34M|	}
 2353|  8.76k|	if (action_count == 0) {
  ------------------
  |  Branch (2353:6): [True: 267, False: 8.50k]
  ------------------
 2354|    267|		util_print_usage(app_name, options, option_help, NULL);
 2355|    267|		return 2;
 2356|    267|	}
 2357|       |
 2358|  8.50k|	if (do_print_version)   {
  ------------------
  |  Branch (2358:6): [True: 89, False: 8.41k]
  ------------------
 2359|     89|		printf("%s\n", OPENSC_SCM_REVISION);
  ------------------
  |  |  226|     89|#define OPENSC_SCM_REVISION "OpenSC-<version not available>, rev: ad73030, commit-time: 2026-09-02 20:33:10 +0200"
  ------------------
 2360|     89|		action_count--;
 2361|     89|	}
 2362|       |
 2363|  8.50k|	memset(&ctx_param, 0, sizeof(ctx_param));
 2364|  8.50k|	ctx_param.ver      = 0;
 2365|  8.50k|	ctx_param.app_name = app_name;
 2366|  8.50k|	ctx_param.debug    = verbose;
 2367|  8.50k|	if (verbose)
  ------------------
  |  Branch (2367:6): [True: 2.26k, False: 6.23k]
  ------------------
 2368|  2.26k|		ctx_param.debug_file = stderr;
  ------------------
  |  |   39|  2.26k|#define stderr stdout
  ------------------
 2369|       |
 2370|  8.50k|	r = sc_context_create(&ctx, &ctx_param);
 2371|  8.50k|	if (r) {
  ------------------
  |  Branch (2371:6): [True: 0, False: 8.50k]
  ------------------
 2372|      0|		fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 2373|      0|		return 1;
 2374|      0|	}
 2375|       |
 2376|  8.50k|	if (opt_clear_cache) {
  ------------------
  |  Branch (2376:6): [True: 20, False: 8.48k]
  ------------------
 2377|     20|		if ((err = clear_cache()))
  ------------------
  |  Branch (2377:7): [True: 9, False: 11]
  ------------------
 2378|      9|			goto end;
 2379|     11|		action_count--;
 2380|     11|	}
 2381|       |
 2382|  8.49k|	err = util_connect_card_ex(ctx, &card, opt_reader, opt_wait, 0);
  ------------------
  |  |   43|  8.49k|#define util_connect_card_ex(ctx, card, id, do_wait, do_lock) fuzz_util_connect_card(ctx, card)
  ------------------
 2383|  8.49k|	if (err)
  ------------------
  |  Branch (2383:6): [True: 2.44k, False: 6.04k]
  ------------------
 2384|  2.44k|		goto end;
 2385|       |
 2386|  6.04k|	if (verbose)
  ------------------
  |  Branch (2386:6): [True: 1.79k, False: 4.25k]
  ------------------
 2387|  1.79k|		fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
  ------------------
  |  |   39|  1.79k|#define stderr stdout
  ------------------
 2388|       |
 2389|  6.04k|	if (opt_bind_to_aid)   {
  ------------------
  |  Branch (2389:6): [True: 216, False: 5.83k]
  ------------------
 2390|    216|		struct sc_aid aid;
 2391|       |
 2392|    216|		aid.len = sizeof(aid.value);
 2393|    216|		if (sc_hex_to_bin(opt_bind_to_aid, aid.value, &aid.len))   {
  ------------------
  |  Branch (2393:7): [True: 91, False: 125]
  ------------------
 2394|     91|			fprintf(stderr, "Invalid AID value: '%s'\n", opt_bind_to_aid);
  ------------------
  |  |   39|     91|#define stderr stdout
  ------------------
 2395|     91|			err = 1;
 2396|     91|			goto end;
 2397|     91|		}
 2398|       |
 2399|    125|		r = sc_pkcs15_bind(card, &aid, &p15card);
 2400|    125|	}
 2401|  5.83k|	else   {
 2402|  5.83k|		r = sc_pkcs15_bind(card, NULL, &p15card);
 2403|  5.83k|	}
 2404|       |
 2405|  5.95k|	if (r) {
  ------------------
  |  Branch (2405:6): [True: 3.42k, False: 2.53k]
  ------------------
 2406|  3.42k|		fprintf(stderr, "PKCS#15 binding failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|  3.42k|#define stderr stdout
  ------------------
 2407|  3.42k|		err = 1;
 2408|  3.42k|		goto end;
 2409|  3.42k|	}
 2410|  2.53k|	if (opt_no_cache)
  ------------------
  |  Branch (2410:6): [True: 26, False: 2.50k]
  ------------------
 2411|     26|		p15card->opts.use_file_cache = 0;
 2412|  2.53k|	if (verbose)
  ------------------
  |  Branch (2412:6): [True: 752, False: 1.78k]
  ------------------
 2413|    752|		fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label);
  ------------------
  |  |   39|    752|#define stderr stdout
  ------------------
 2414|       |
 2415|  2.53k|	if (do_list_info) {
  ------------------
  |  Branch (2415:6): [True: 4, False: 2.52k]
  ------------------
 2416|      4|		if (!do_dump)
  ------------------
  |  Branch (2416:7): [True: 1, False: 3]
  ------------------
 2417|      1|			list_info();
 2418|      4|		action_count--;
 2419|      4|	}
 2420|       |
 2421|  2.53k|	if (do_verify_pin)
  ------------------
  |  Branch (2421:6): [True: 29, False: 2.50k]
  ------------------
 2422|     29|		if ((err = verify_pin()))
  ------------------
  |  Branch (2422:7): [True: 15, False: 14]
  ------------------
 2423|     15|			goto end;
 2424|       |
 2425|  2.51k|	if (do_list_certs) {
  ------------------
  |  Branch (2425:6): [True: 372, False: 2.14k]
  ------------------
 2426|    372|		if ((err = list_certificates()))
  ------------------
  |  Branch (2426:7): [True: 0, False: 372]
  ------------------
 2427|      0|			goto end;
 2428|    372|		action_count--;
 2429|    372|	}
 2430|  2.51k|	if (do_read_cert) {
  ------------------
  |  Branch (2430:6): [True: 8, False: 2.51k]
  ------------------
 2431|      8|		if ((err = read_certificate()))
  ------------------
  |  Branch (2431:7): [True: 8, False: 0]
  ------------------
 2432|      8|			goto end;
 2433|      0|		action_count--;
 2434|      0|	}
 2435|  2.51k|	if (do_list_data_objects) {
  ------------------
  |  Branch (2435:6): [True: 732, False: 1.77k]
  ------------------
 2436|    732|		if ((err = list_data_objects()))
  ------------------
  |  Branch (2436:7): [True: 142, False: 590]
  ------------------
 2437|    142|			goto end;
 2438|    590|		action_count--;
 2439|    590|	}
 2440|  2.36k|	if (do_read_data_object) {
  ------------------
  |  Branch (2440:6): [True: 492, False: 1.87k]
  ------------------
 2441|    492|		if ((err = read_data_object()))
  ------------------
  |  Branch (2441:7): [True: 434, False: 58]
  ------------------
 2442|    434|			goto end;
 2443|     58|		action_count--;
 2444|     58|	}
 2445|  1.93k|	if (do_list_prkeys) {
  ------------------
  |  Branch (2445:6): [True: 1.09k, False: 842]
  ------------------
 2446|  1.09k|		if ((err = list_private_keys()))
  ------------------
  |  Branch (2446:7): [True: 0, False: 1.09k]
  ------------------
 2447|      0|			goto end;
 2448|  1.09k|		action_count--;
 2449|  1.09k|	}
 2450|  1.93k|	if (do_list_pubkeys) {
  ------------------
  |  Branch (2450:6): [True: 17, False: 1.91k]
  ------------------
 2451|     17|		if ((err = list_public_keys()))
  ------------------
  |  Branch (2451:7): [True: 0, False: 17]
  ------------------
 2452|      0|			goto end;
 2453|     17|		action_count--;
 2454|     17|	}
 2455|  1.93k|	if (do_read_pubkey) {
  ------------------
  |  Branch (2455:6): [True: 24, False: 1.91k]
  ------------------
 2456|     24|		if ((err = read_public_key()))
  ------------------
  |  Branch (2456:7): [True: 24, False: 0]
  ------------------
 2457|     24|			goto end;
 2458|      0|		action_count--;
 2459|      0|	}
 2460|  1.91k|#if defined(ENABLE_OPENSSL) && (defined(_WIN32) || defined(HAVE_INTTYPES_H))
 2461|  1.91k|	if (do_read_sshkey) {
  ------------------
  |  Branch (2461:6): [True: 6, False: 1.90k]
  ------------------
 2462|      6|		if ((err = read_ssh_key()))
  ------------------
  |  Branch (2462:7): [True: 6, False: 0]
  ------------------
 2463|      6|			goto end;
 2464|      0|		action_count--;
 2465|      0|	}
 2466|  1.90k|#endif
 2467|  1.90k|	if (do_list_pins) {
  ------------------
  |  Branch (2467:6): [True: 65, False: 1.83k]
  ------------------
 2468|     65|		if ((err = list_pins()))
  ------------------
  |  Branch (2468:7): [True: 0, False: 65]
  ------------------
 2469|      0|			goto end;
 2470|     65|		action_count--;
 2471|     65|	}
 2472|  1.90k|	if (do_list_skeys) {
  ------------------
  |  Branch (2472:6): [True: 8, False: 1.89k]
  ------------------
 2473|      8|		if ((err = list_skeys()))
  ------------------
  |  Branch (2473:7): [True: 0, False: 8]
  ------------------
 2474|      0|			goto end;
 2475|      8|		action_count--;
 2476|      8|	}
 2477|  1.90k|	if (do_list_apps) {
  ------------------
  |  Branch (2477:6): [True: 5, False: 1.89k]
  ------------------
 2478|      5|		if ((err = list_apps(stdout)))
  ------------------
  |  Branch (2478:7): [True: 0, False: 5]
  ------------------
 2479|      0|			goto end;
 2480|      5|		action_count--;
 2481|      5|	}
 2482|  1.90k|	if (do_dump) {
  ------------------
  |  Branch (2482:6): [True: 610, False: 1.29k]
  ------------------
 2483|    610|		if ((err = dump()))
  ------------------
  |  Branch (2483:7): [True: 0, False: 610]
  ------------------
 2484|      0|			goto end;
 2485|    610|		action_count--;
 2486|    610|	}
 2487|  1.90k|	if (do_change_pin) {
  ------------------
  |  Branch (2487:6): [True: 282, False: 1.62k]
  ------------------
 2488|    282|		if ((err = change_pin()))
  ------------------
  |  Branch (2488:7): [True: 273, False: 9]
  ------------------
 2489|    273|			goto end;
 2490|      9|		action_count--;
 2491|      9|	}
 2492|  1.63k|	if (do_unblock_pin) {
  ------------------
  |  Branch (2492:6): [True: 341, False: 1.29k]
  ------------------
 2493|    341|		if ((err = unblock_pin()))
  ------------------
  |  Branch (2493:7): [True: 339, False: 2]
  ------------------
 2494|    339|			goto end;
 2495|      2|		action_count--;
 2496|      2|	}
 2497|  1.29k|	if (do_test_update || do_update) {
  ------------------
  |  Branch (2497:6): [True: 132, False: 1.16k]
  |  Branch (2497:24): [True: 62, False: 1.09k]
  ------------------
 2498|    194|		err = test_update(card);
 2499|    194|		action_count--;
 2500|    194|		if (err == 2) { /* problem */
  ------------------
  |  Branch (2500:7): [True: 63, False: 131]
  ------------------
 2501|     63|			err = 1;
 2502|     63|			goto end;
 2503|     63|		}
 2504|    131|		if (do_update && err == 1) { /* card vulnerable */
  ------------------
  |  Branch (2504:7): [True: 78, False: 53]
  |  Branch (2504:20): [True: 0, False: 78]
  ------------------
 2505|      0|			if ((err = update(card)))
  ------------------
  |  Branch (2505:8): [True: 0, False: 0]
  ------------------
 2506|      0|				goto end;
 2507|      0|		}
 2508|    131|	}
 2509|  1.22k|	if (do_test_session_pin) {
  ------------------
  |  Branch (2509:6): [True: 164, False: 1.06k]
  ------------------
 2510|    164|		if ((err = test_session_pin()))
  ------------------
  |  Branch (2510:7): [True: 164, False: 0]
  ------------------
 2511|    164|			goto end;
 2512|      0|		action_count--;
 2513|      0|	}
 2514|  8.50k|end:
 2515|  8.50k|	sc_pkcs15_unbind(p15card);
 2516|  8.50k|	sc_disconnect_card(card);
 2517|  8.50k|	sc_release_context(ctx);
 2518|  8.50k|	return err;
 2519|  1.22k|}
fuzz_pkcs15_tool.c:clear_cache:
 1315|     20|{
 1316|     20|	char dirname[PATH_MAX];
 1317|     20|	int r = 0;
 1318|       |
 1319|       |	/* remove the user's cache directory */
 1320|     20|	if ((r = sc_get_cache_dir(ctx, dirname, sizeof(dirname))) < 0)
  ------------------
  |  Branch (1320:6): [True: 0, False: 20]
  ------------------
 1321|      0|		return r;
 1322|     20|	r = nftw(dirname, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
 1323|     20|	return r;
 1324|     20|}
fuzz_pkcs15_tool.c:unlink_cb:
 1308|    548|{
 1309|    548|	int r = remove(fpath);
 1310|    548|	if (r)
  ------------------
  |  Branch (1310:6): [True: 1, False: 547]
  ------------------
 1311|      1|		perror(fpath);
 1312|    548|	return r;
 1313|    548|}
fuzz_pkcs15_tool.c:list_info:
 1639|    611|{
 1640|    611|	const char *flags[] = {
 1641|    611|		"Read-only",
 1642|    611|		"Login required",
 1643|    611|		"PRN generation",
 1644|    611|		"EID compliant"
 1645|    611|	};
 1646|    611|	char *last_update = sc_pkcs15_get_lastupdate(p15card);
 1647|    611|	int i, count = 0;
 1648|    611|	int idx;
 1649|       |
 1650|    611|	printf("PKCS#15 Card [%s]:\n", p15card->tokeninfo->label);
 1651|    611|	printf("\tVersion        : %d\n", p15card->tokeninfo->version);
 1652|    611|	printf("\tSerial number  : %s\n", p15card->tokeninfo->serial_number);
 1653|    611|	printf("\tManufacturer ID: %s\n", p15card->tokeninfo->manufacturer_id);
 1654|    611|	if (last_update)
  ------------------
  |  Branch (1654:6): [True: 1, False: 610]
  ------------------
 1655|      1|		printf("\tLast update    : %s\n", last_update);
 1656|    611|	if (p15card->tokeninfo->preferred_language)
  ------------------
  |  Branch (1656:6): [True: 1, False: 610]
  ------------------
 1657|      1|		printf("\tLanguage       : %s\n", p15card->tokeninfo->preferred_language);
 1658|    611|	if (p15card->tokeninfo->profile_indication.name)
  ------------------
  |  Branch (1658:6): [True: 104, False: 507]
  ------------------
 1659|    104|		printf("\tProfile        : %s\n", p15card->tokeninfo->profile_indication.name);
 1660|    611|	printf("\tFlags          : ");
 1661|  3.05k|	for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (1661:14): [True: 2.44k, False: 611]
  ------------------
 1662|  2.44k|		if ((p15card->tokeninfo->flags >> i) & 1) {
  ------------------
  |  Branch (1662:7): [True: 121, False: 2.32k]
  ------------------
 1663|    121|			if (count)
  ------------------
  |  Branch (1663:8): [True: 61, False: 60]
  ------------------
 1664|     61|				printf(", ");
 1665|    121|			printf("%s", flags[i]);
 1666|    121|			count++;
 1667|    121|		}
 1668|  2.44k|	}
 1669|    611|	printf("\n");
 1670|    727|	for (i = 0; i < SC_MAX_SUPPORTED_ALGORITHMS; i++) {
  ------------------
  |  |   61|    727|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (1670:14): [True: 727, False: 0]
  ------------------
 1671|    727|		struct sc_supported_algo_info * sa = &p15card->tokeninfo->supported_algos[i];
 1672|       |
 1673|    727|		if (sa->reference == 0 && sa->mechanism == 0
  ------------------
  |  Branch (1673:7): [True: 622, False: 105]
  |  Branch (1673:29): [True: 613, False: 9]
  ------------------
 1674|    613|				&& sa->operations == 0 && sa->algo_ref == 0)
  ------------------
  |  Branch (1674:8): [True: 611, False: 2]
  |  Branch (1674:31): [True: 611, False: 0]
  ------------------
 1675|    611|					break;
 1676|    116|		printf("\t\t sc_supported_algo_info[%d]:\n", i);
 1677|    116|		printf("\t\t\t reference  : %u (0x%02x)\n", sa->reference, sa->reference);
 1678|    116|		printf("\t\t\t mechanism  : [0x%02x] %s\n", sa->mechanism, lookup_enum(MEC_T, sa->mechanism));
 1679|    116|		if (sc_valid_oid(&sa->parameters)) {
  ------------------
  |  Branch (1679:7): [True: 0, False: 116]
  ------------------
 1680|      0|			printf("\t\t\t parameters:  %i", sa->parameters.value[0]);
 1681|      0|			for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->parameters.value[idx] != -1 ; idx++)
  ------------------
  |  |   46|      0|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (1681:18): [True: 0, False: 0]
  |  Branch (1681:51): [True: 0, False: 0]
  ------------------
 1682|      0|				printf(".%i", sa->parameters.value[idx]);
 1683|      0|			printf("\n");
 1684|      0|		}
 1685|    116|		printf("\t\t\t operations : [0x%2.2x]",sa->operations);
 1686|    116|		print_supported_algo_info_operations(sa->operations);
 1687|    116|		printf("\n");
 1688|    116|		if (sc_valid_oid((const struct sc_object_id*)&sa->algo_id)) {
  ------------------
  |  Branch (1688:7): [True: 56, False: 60]
  ------------------
 1689|     56|			printf("\t\t\t algo_id    : %i", sa->algo_id.value[0]);
 1690|    460|			for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && sa->algo_id.value[idx] != -1 ; idx++)
  ------------------
  |  |   46|    920|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (1690:18): [True: 460, False: 0]
  |  Branch (1690:51): [True: 404, False: 56]
  ------------------
 1691|    404|				printf(".%i", sa->algo_id.value[idx]);
 1692|     56|			printf("\n");
 1693|     56|		}
 1694|    116|		printf("\t\t\t algo_ref   : [0x%02x]\n",sa->algo_ref);
 1695|    116|	}
 1696|       |
 1697|    611|	printf((compact) ? "\n" : "\n\n");
  ------------------
  |  Branch (1697:9): [True: 137, False: 474]
  ------------------
 1698|    611|}
fuzz_pkcs15_tool.c:print_supported_algo_info_operations:
 1626|    116|{
 1627|    116|	size_t i;
 1628|    116|	const char *operations[] = {
 1629|    116|		"compute_checksum", "compute_signature", "verify_checksum", "verify_signature",
 1630|    116|		"encipher", "decipher", "hash", "generate/derive_key"
 1631|    116|	};
 1632|    116|	const size_t operations_count = NELEMENTS(operations);
  ------------------
  |  |  114|    116|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
 1633|  1.04k|	for (i = 0; i < operations_count; i++)
  ------------------
  |  Branch (1633:14): [True: 928, False: 116]
  ------------------
 1634|    928|		if (operation & (1 << i))
  ------------------
  |  Branch (1634:7): [True: 258, False: 670]
  ------------------
 1635|    258|			printf(", %s", operations[i]);
 1636|    116|}
fuzz_pkcs15_tool.c:verify_pin:
 1329|     29|{
 1330|     29|	struct sc_pkcs15_object	*pin_obj = NULL;
 1331|     29|	unsigned char		*pin;
 1332|     29|	int r;
 1333|       |
 1334|     29|	if (!opt_auth_id)   {
  ------------------
  |  Branch (1334:6): [True: 21, False: 8]
  ------------------
 1335|     21|		struct sc_pkcs15_object *objs[32];
 1336|     21|		int ii;
 1337|       |
 1338|     21|		r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|     21|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
 1339|     21|		if (r < 0) {
  ------------------
  |  Branch (1339:7): [True: 0, False: 21]
  ------------------
 1340|      0|			fprintf(stderr, "PIN code enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1341|      0|			return -1;
 1342|      0|		}
 1343|       |
 1344|     21|		for (ii=0;ii<r;ii++)   {
  ------------------
  |  Branch (1344:13): [True: 18, False: 3]
  ------------------
 1345|     18|			struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
 1346|       |
 1347|     18|			if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|     18|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1347:8): [True: 0, False: 18]
  ------------------
 1348|      0|				continue;
 1349|     18|			if (pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN)
  ------------------
  |  |   61|     18|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (1349:8): [True: 0, False: 18]
  ------------------
 1350|      0|				continue;
 1351|     18|			if (pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN)
  ------------------
  |  |   60|     18|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  |  Branch (1351:8): [True: 0, False: 18]
  ------------------
 1352|      0|				continue;
 1353|       |
 1354|     18|			pin_obj = objs[ii];
 1355|     18|			break;
 1356|     18|		}
 1357|     21|	}
 1358|      8|	else   {
 1359|      8|		pin_obj = get_pin_info();
 1360|      8|	}
 1361|       |
 1362|     29|	if (!pin_obj)   {
  ------------------
  |  Branch (1362:6): [True: 10, False: 19]
  ------------------
 1363|     10|		fprintf(stderr, "PIN object '%s' not found\n", opt_auth_id);
  ------------------
  |  |   39|     10|#define stderr stdout
  ------------------
 1364|     10|		return -1;
 1365|     10|	}
 1366|       |
 1367|     19|	if (opt_pin != NULL)
  ------------------
  |  Branch (1367:6): [True: 17, False: 2]
  ------------------
 1368|     17|		pin = (unsigned char *) opt_pin;
 1369|      2|	else
 1370|      2|		pin = get_pin("Please enter PIN", pin_obj);
 1371|       |
 1372|       |
 1373|     19|	r = sc_pkcs15_verify_pin(p15card, pin_obj, pin, pin ? strlen((char *) pin) : 0);
  ------------------
  |  Branch (1373:50): [True: 17, False: 2]
  ------------------
 1374|     19|	if (opt_pin == NULL)
  ------------------
  |  Branch (1374:6): [True: 2, False: 17]
  ------------------
 1375|      2|		free(pin);
 1376|     19|	if (r < 0)   {
  ------------------
  |  Branch (1376:6): [True: 5, False: 14]
  ------------------
 1377|      5|		fprintf(stderr, "Operation failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      5|#define stderr stdout
  ------------------
 1378|      5|		return -1;
 1379|      5|	}
 1380|       |
 1381|     14|	return 0;
 1382|     19|}
fuzz_pkcs15_tool.c:get_pin_info:
 1194|    692|{
 1195|    692|	sc_pkcs15_object_t *objs[32], *obj;
 1196|    692|	int r;
 1197|       |
 1198|    692|	if (opt_auth_id == NULL) {
  ------------------
  |  Branch (1198:6): [True: 478, False: 214]
  ------------------
 1199|    478|		r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|    478|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
 1200|    478|		if (r < 0) {
  ------------------
  |  Branch (1200:7): [True: 0, False: 478]
  ------------------
 1201|      0|			fprintf(stderr, "PIN code enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1202|      0|			return NULL;
 1203|      0|		}
 1204|    478|		if (r == 0) {
  ------------------
  |  Branch (1204:7): [True: 21, False: 457]
  ------------------
 1205|     21|			fprintf(stderr, "No PIN codes found.\n");
  ------------------
  |  |   39|     21|#define stderr stdout
  ------------------
 1206|     21|			return NULL;
 1207|     21|		}
 1208|    457|		obj = objs[0];
 1209|    457|	} else {
 1210|    214|		struct sc_pkcs15_id auth_id;
 1211|       |
 1212|    214|		sc_pkcs15_hex_string_to_id(opt_auth_id, &auth_id);
 1213|    214|		r = sc_pkcs15_find_pin_by_auth_id(p15card, &auth_id, &obj);
 1214|    214|		if (r) {
  ------------------
  |  Branch (1214:7): [True: 211, False: 3]
  ------------------
 1215|    211|			fprintf(stderr, "Unable to find PIN code: %s\n", sc_strerror(r));
  ------------------
  |  |   39|    211|#define stderr stdout
  ------------------
 1216|    211|			return NULL;
 1217|    211|		}
 1218|    214|	}
 1219|       |
 1220|    460|	return obj;
 1221|    692|}
fuzz_pkcs15_tool.c:get_pin:
 1224|    288|{
 1225|    288|	sc_pkcs15_auth_info_t *pinfo = (sc_pkcs15_auth_info_t *) pin_obj->data;
 1226|    288|	char *pincode = NULL;
 1227|    288|	size_t len = 0;
 1228|    288|	int r;
 1229|       |
 1230|    288|	if (opt_use_pinpad) {
  ------------------
  |  Branch (1230:6): [True: 15, False: 273]
  ------------------
 1231|       |		// defer entry of the PIN to the readers pinpad.
 1232|     15|		if (verbose)
  ------------------
  |  Branch (1232:7): [True: 14, False: 1]
  ------------------
 1233|     14|			printf("%s [%.*s]: entry deferred to the reader keypad\n", prompt, (int) sizeof pin_obj->label, pin_obj->label);
 1234|     15|		return NULL;
 1235|     15|	}
 1236|       |
 1237|    273|	printf("%s [%.*s]: ", prompt, (int) sizeof pin_obj->label, pin_obj->label);
 1238|    273|	if (pinfo->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    273|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1238:6): [True: 0, False: 273]
  ------------------
 1239|      0|		return NULL;
 1240|       |
 1241|    273|	while (1) {
  ------------------
  |  Branch (1241:9): [True: 273, Folded]
  ------------------
 1242|    273|		r = util_getpass(&pincode, &len, stdin);
 1243|    273|		if (r < 0)
  ------------------
  |  Branch (1243:7): [True: 273, False: 0]
  ------------------
 1244|    273|			return NULL;
 1245|      0|		if (!pincode || strlen(pincode) == 0) {
  ------------------
  |  Branch (1245:7): [True: 0, False: 0]
  |  Branch (1245:19): [True: 0, False: 0]
  ------------------
 1246|      0|			free(pincode);
 1247|      0|			return NULL;
 1248|      0|		}
 1249|      0|		if (strlen(pincode) < pinfo->attrs.pin.min_length) {
  ------------------
  |  Branch (1249:7): [True: 0, False: 0]
  ------------------
 1250|      0|			printf("PIN code too short, try again.\n");
 1251|      0|			continue;
 1252|      0|		}
 1253|      0|		if (strlen(pincode) > pinfo->attrs.pin.max_length) {
  ------------------
  |  Branch (1253:7): [True: 0, False: 0]
  ------------------
 1254|      0|			printf("PIN code too long, try again.\n");
 1255|      0|			continue;
 1256|      0|		}
 1257|      0|		return (u8 *) pincode;
 1258|      0|	}
 1259|    273|}
fuzz_pkcs15_tool.c:list_certificates:
  301|    982|{
  302|    982|	int r, i;
  303|    982|	struct sc_pkcs15_object *objs[32];
  304|       |
  305|    982|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_CERT_X509, objs, 32);
  ------------------
  |  |  439|    982|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  306|    982|	if (r < 0) {
  ------------------
  |  Branch (306:6): [True: 0, False: 982]
  ------------------
  307|      0|		fprintf(stderr, "Certificate enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  308|      0|		return 1;
  309|      0|	}
  310|    982|	if (compact)
  ------------------
  |  Branch (310:6): [True: 264, False: 718]
  ------------------
  311|    264|		printf("Card has %d Certificate(s).\n", r);
  312|    718|	else if (verbose)
  ------------------
  |  Branch (312:11): [True: 466, False: 252]
  ------------------
  313|    466|		printf("Card has %d Certificate(s).\n\n", r);
  314|  1.50k|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (314:14): [True: 525, False: 982]
  ------------------
  315|    525|		print_cert_info(objs[i]);
  316|    525|		printf("\n");
  317|    525|	}
  318|       |
  319|    982|	return 0;
  320|    982|}
fuzz_pkcs15_tool.c:print_cert_info:
  268|    525|{
  269|    525|	struct sc_pkcs15_cert_info *cert_info = (struct sc_pkcs15_cert_info *) obj->data;
  270|    525|	struct sc_pkcs15_cert *cert_parsed = NULL;
  271|    525|	int rv;
  272|    525|	int private_obj;
  273|       |
  274|    525|	if (compact) {
  ------------------
  |  Branch (274:6): [True: 70, False: 455]
  ------------------
  275|     70|		printf("\tPath:%s  ID:%s", sc_print_path(&cert_info->path),
  276|     70|			sc_pkcs15_print_id(&cert_info->id));
  277|     70|		if (cert_info->authority)
  ------------------
  |  Branch (277:7): [True: 20, False: 50]
  ------------------
  278|     20|			printf("  Authority");
  279|     70|		return;
  280|     70|	}
  281|       |
  282|    455|	printf("X.509 Certificate [%.*s]\n", (int) sizeof obj->label, obj->label);
  283|    455|	print_common_flags(obj);
  284|    455|	printf("\tAuthority      : %s\n", cert_info->authority ? "yes" : "no");
  ------------------
  |  Branch (284:36): [True: 120, False: 335]
  ------------------
  285|    455|	printf("\tPath           : %s\n", sc_print_path(&cert_info->path));
  286|    455|	printf("\tID             : %s\n", sc_pkcs15_print_id(&cert_info->id));
  287|       |
  288|    455|	print_access_rules(obj->access_rules, SC_PKCS15_MAX_ACCESS_RULES);
  ------------------
  |  |   42|    455|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  289|       |
  290|    455|	private_obj = obj->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    455|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  291|    455|	rv = sc_pkcs15_read_certificate(p15card, cert_info, private_obj, &cert_parsed);
  292|    455|	if (rv >= 0 && cert_parsed)   {
  ------------------
  |  Branch (292:6): [True: 109, False: 346]
  |  Branch (292:17): [True: 109, False: 0]
  ------------------
  293|    109|		printf("\tEncoded serial : %02X %02X ", *(cert_parsed->serial), *(cert_parsed->serial + 1));
  294|       |		util_hex_dump(stdout, cert_parsed->serial + 2, cert_parsed->serial_len - 2, "");
  295|    109|		printf("\n");
  296|    109|		sc_pkcs15_free_certificate(cert_parsed);
  297|    109|	}
  298|    455|}
fuzz_pkcs15_tool.c:print_common_flags:
  255|  1.68k|{
  256|  1.68k|	const char *common_flags[] = {"private", "modifiable"};
  257|  1.68k|	unsigned int i;
  258|  1.68k|	printf("\tObject Flags   : [0x%02X]", obj->flags);
  259|  5.04k|	for (i = 0; i < NELEMENTS(common_flags); i++) {
  ------------------
  |  |  114|  5.04k|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
  |  Branch (259:14): [True: 3.36k, False: 1.68k]
  ------------------
  260|  3.36k|		if (obj->flags & (1 << i)) {
  ------------------
  |  Branch (260:7): [True: 996, False: 2.36k]
  ------------------
  261|    996|			printf(", %s", common_flags[i]);
  262|    996|		}
  263|  3.36k|	}
  264|  1.68k|	printf("\n");
  265|  1.68k|}
fuzz_pkcs15_tool.c:print_access_rules:
  228|    853|{
  229|    853|	int i, j;
  230|       |
  231|    853|	if (!rules->access_mode)
  ------------------
  |  Branch (231:6): [True: 853, False: 0]
  ------------------
  232|    853|		return;
  233|       |
  234|      0|	printf("\tAccess Rules   :");
  235|      0|	for (i = 0; i < num; i++)   {
  ------------------
  |  Branch (235:14): [True: 0, False: 0]
  ------------------
  236|      0|		int next_coma = 0;
  237|       |
  238|      0|		if (!(rules + i)->access_mode)
  ------------------
  |  Branch (238:7): [True: 0, False: 0]
  ------------------
  239|      0|			break;
  240|      0|		printf(" ");
  241|       |
  242|      0|		for (j = 0; _access_rules_text[j].label;j++)   {
  ------------------
  |  Branch (242:15): [True: 0, False: 0]
  ------------------
  243|      0|			if ((rules + i)->access_mode & (_access_rules_text[j].flag))   {
  ------------------
  |  Branch (243:8): [True: 0, False: 0]
  ------------------
  244|      0|				printf("%s%s", next_coma ? "," : "", _access_rules_text[j].label);
  ------------------
  |  Branch (244:20): [True: 0, False: 0]
  ------------------
  245|      0|				next_coma = 1;
  246|      0|			}
  247|      0|		}
  248|       |
  249|      0|		printf(":%s;", (rules + i)->auth_id.len ? sc_pkcs15_print_id(&(rules + i)->auth_id) : "<always>");
  ------------------
  |  Branch (249:18): [True: 0, False: 0]
  ------------------
  250|      0|	}
  251|      0|	printf("\n");
  252|      0|}
fuzz_pkcs15_tool.c:read_certificate:
  419|      8|{
  420|      8|	int r, i, count;
  421|      8|	struct sc_pkcs15_id id;
  422|      8|	struct sc_pkcs15_object *objs[32];
  423|       |
  424|      8|	id.len = SC_PKCS15_MAX_ID_SIZE;
  ------------------
  |  |   36|      8|#define SC_PKCS15_MAX_ID_SIZE		255
  ------------------
  425|      8|	sc_pkcs15_hex_string_to_id(opt_cert, &id);
  426|       |
  427|      8|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_CERT_X509, objs, 32);
  ------------------
  |  |  439|      8|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  428|      8|	if (r < 0) {
  ------------------
  |  Branch (428:6): [True: 0, False: 8]
  ------------------
  429|      0|		fprintf(stderr, "Certificate enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  430|      0|		return 1;
  431|      0|	}
  432|      8|	count = r;
  433|     15|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (433:14): [True: 9, False: 6]
  ------------------
  434|      9|		struct sc_pkcs15_cert_info *cinfo = (struct sc_pkcs15_cert_info *) objs[i]->data;
  435|      9|		struct sc_pkcs15_cert *cert;
  436|      9|		int private_obj;
  437|       |
  438|      9|		if (sc_pkcs15_compare_id(&id, &cinfo->id) != 1)
  ------------------
  |  Branch (438:7): [True: 7, False: 2]
  ------------------
  439|      7|			continue;
  440|       |
  441|      2|		if (verbose)
  ------------------
  |  Branch (441:7): [True: 1, False: 1]
  ------------------
  442|      1|			printf("Reading certificate with ID '%s'\n", opt_cert);
  443|      2|		private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      2|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  444|      2|		r = sc_pkcs15_read_certificate(p15card, cinfo, private_obj, &cert);
  445|      2|		if (r) {
  ------------------
  |  Branch (445:7): [True: 2, False: 0]
  ------------------
  446|      2|			fprintf(stderr, "Certificate read failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      2|#define stderr stdout
  ------------------
  447|      2|			return 1;
  448|      2|		}
  449|      0|		r = print_pem_object("CERTIFICATE", cert->data.value, cert->data.len);
  450|      0|		sc_pkcs15_free_certificate(cert);
  451|      0|		return r;
  452|      2|	}
  453|      6|	fprintf(stderr, "Certificate with ID '%s' not found.\n", opt_cert);
  ------------------
  |  |   39|      6|#define stderr stdout
  ------------------
  454|      6|	return 2;
  455|      8|}
fuzz_pkcs15_tool.c:list_data_objects:
  509|  1.34k|{
  510|  1.34k|	int r, i, count;
  511|  1.34k|	struct sc_pkcs15_object *objs[32];
  512|       |
  513|  1.34k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT, objs, 32);
  ------------------
  |  |  442|  1.34k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  514|  1.34k|	if (r < 0) {
  ------------------
  |  Branch (514:6): [True: 0, False: 1.34k]
  ------------------
  515|      0|		fprintf(stderr, "Data object enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  516|      0|		return 1;
  517|      0|	}
  518|  1.34k|	count = r;
  519|  1.34k|	if (compact)
  ------------------
  |  Branch (519:6): [True: 584, False: 758]
  ------------------
  520|    584|		printf("Card has %d Data object(s).\n", count);
  521|    758|	else if (verbose)
  ------------------
  |  Branch (521:11): [True: 484, False: 274]
  ------------------
  522|    484|		printf("Card has %d Data object(s).\n\n", count);
  523|  11.3k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (523:14): [True: 10.1k, False: 1.17k]
  ------------------
  524|  10.1k|		int idx;
  525|  10.1k|		struct sc_pkcs15_data_info *cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  526|       |
  527|  10.1k|		if (compact) {
  ------------------
  |  Branch (527:7): [True: 2.52k, False: 7.62k]
  ------------------
  528|  2.52k|			printf("\tPath:%-12s", sc_print_path(&cinfo->path));
  529|  2.52k|			if (sc_valid_oid(&cinfo->app_oid)) {
  ------------------
  |  Branch (529:8): [True: 2.35k, False: 176]
  ------------------
  530|  2.35k|				printf("  %i", cinfo->app_oid.value[0]);
  531|  23.5k|				for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && cinfo->app_oid.value[idx] != -1 ; idx++)
  ------------------
  |  |   46|  47.0k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (531:19): [True: 23.5k, False: 0]
  |  Branch (531:52): [True: 21.1k, False: 2.35k]
  ------------------
  532|  21.1k|					printf(".%i", cinfo->app_oid.value[idx]);
  533|  2.35k|			}
  534|  2.52k|			if (objs[i]->auth_id.len == 0) {
  ------------------
  |  Branch (534:8): [True: 2.12k, False: 405]
  ------------------
  535|  2.12k|				struct sc_pkcs15_data *data_object;
  536|  2.12k|				int private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  2.12k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  537|  2.12k|				r = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &data_object);
  538|  2.12k|				if (r) {
  ------------------
  |  Branch (538:9): [True: 1.83k, False: 294]
  ------------------
  539|  1.83k|					fprintf(stderr, "Data object read failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|  1.83k|#define stderr stdout
  ------------------
  540|  1.83k|					if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  1.83k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (540:10): [True: 1.71k, False: 117]
  ------------------
  541|  1.71k|						continue; /* DEE emulation may say there is a file */
  542|    117|					return 1;
  543|  1.83k|				}
  544|    294|				sc_pkcs15_free_data_object(data_object);
  545|    294|				printf("  Size:%5zu", cinfo->data.len);
  546|    405|			} else {
  547|    405|				printf("  AuthID:%-3s", sc_pkcs15_print_id(&objs[i]->auth_id));
  548|    405|			}
  549|    699|			printf("  %-20s", cinfo->app_label);
  550|    699|			printf("\n");
  551|    699|			continue;
  552|  2.52k|		}
  553|       |
  554|  7.62k|		if (objs[i]->label[0] != '\0')
  ------------------
  |  Branch (554:7): [True: 7.62k, False: 0]
  ------------------
  555|  7.62k|			printf("Data object '%.*s'\n",(int) sizeof objs[i]->label, objs[i]->label);
  556|      0|		else
  557|      0|			printf("Data object <%i>\n", i);
  558|  7.62k|		printf("\tapplicationName: %s\n", cinfo->app_label);
  559|  7.62k|		if (sc_valid_oid(&cinfo->app_oid)) {
  ------------------
  |  Branch (559:7): [True: 7.48k, False: 137]
  ------------------
  560|  7.48k|			printf("\tapplicationOID:  %i", cinfo->app_oid.value[0]);
  561|  74.8k|			for (idx = 1; idx < SC_MAX_OBJECT_ID_OCTETS && cinfo->app_oid.value[idx] != -1 ; idx++)
  ------------------
  |  |   46|   149k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (561:18): [True: 74.8k, False: 0]
  |  Branch (561:51): [True: 67.3k, False: 7.48k]
  ------------------
  562|  67.3k|				printf(".%i", cinfo->app_oid.value[idx]);
  563|  7.48k|			printf("\n");
  564|  7.48k|		}
  565|  7.62k|		printf("\tPath:            %s\n", sc_print_path(&cinfo->path));
  566|  7.62k|		if (objs[i]->auth_id.len == 0) {
  ------------------
  |  Branch (566:7): [True: 6.35k, False: 1.26k]
  ------------------
  567|  6.35k|			struct sc_pkcs15_data *data_object;
  568|  6.35k|			int private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  6.35k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  569|  6.35k|			r = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &data_object);
  570|  6.35k|			if (r) {
  ------------------
  |  Branch (570:8): [True: 5.43k, False: 921]
  ------------------
  571|  5.43k|				fprintf(stderr, "Data object read failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|  5.43k|#define stderr stdout
  ------------------
  572|  5.43k|				if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  5.43k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (572:9): [True: 5.38k, False: 50]
  ------------------
  573|  5.38k|					 continue; /* DEE emulation may say there is a file */
  574|     50|				return 1;
  575|  5.43k|			}
  576|    921|			list_data_object("\tData", data_object->data, data_object->data_len);
  577|    921|			sc_pkcs15_free_data_object(data_object);
  578|    921|		}
  579|  1.26k|		else {
  580|  1.26k|			printf("\tAuth ID:         %s\n", sc_pkcs15_print_id(&objs[i]->auth_id));
  581|  1.26k|		}
  582|       |
  583|  2.18k|		printf("\n");
  584|  2.18k|	}
  585|  1.17k|	return 0;
  586|  1.34k|}
fuzz_pkcs15_tool.c:list_data_object:
  372|    921|{
  373|    921|	char title[0x100];
  374|    921|	size_t i;
  375|       |
  376|    921|	snprintf(title, sizeof(title), "%s (%lu bytes): ", kind, (unsigned long) data_len);
  377|    921|	printf("%s", title);
  378|    921|	memset(title, ' ', strlen(title));
  379|   944k|	for (i = 0; i < data_len; i++)   {
  ------------------
  |  Branch (379:14): [True: 943k, False: 921]
  ------------------
  380|   943k|		if (i && !(i%48))
  ------------------
  |  Branch (380:7): [True: 942k, False: 886]
  |  Branch (380:12): [True: 19.2k, False: 923k]
  ------------------
  381|  19.2k|			printf("\n%s", title);
  382|   943k|		printf("%02X", data[i]);
  383|   943k|	}
  384|    921|	printf("\n");
  385|    921|}
fuzz_pkcs15_tool.c:read_data_object:
  458|    492|{
  459|    492|	int r, i, count;
  460|    492|	struct sc_pkcs15_object *objs[32];
  461|    492|	struct sc_object_id oid;
  462|       |
  463|    492|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT, objs, 32);
  ------------------
  |  |  442|    492|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  464|    492|	if (r < 0) {
  ------------------
  |  Branch (464:6): [True: 0, False: 492]
  ------------------
  465|      0|		fprintf(stderr, "Data object enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  466|      0|		return 1;
  467|      0|	}
  468|    492|	count = r;
  469|       |
  470|  4.56k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (470:14): [True: 4.13k, False: 430]
  ------------------
  471|  4.13k|		struct sc_pkcs15_data_info *cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  472|  4.13k|		struct sc_pkcs15_data *data_object = NULL;
  473|  4.13k|		int private_obj;
  474|       |
  475|  4.13k|		if (!sc_format_oid(&oid, opt_data))   {
  ------------------
  |  Branch (475:7): [True: 213, False: 3.92k]
  ------------------
  476|    213|			if (!sc_compare_oid(&oid, &cinfo->app_oid))
  ------------------
  |  Branch (476:8): [True: 213, False: 0]
  ------------------
  477|    213|				continue;
  478|    213|		}
  479|  3.92k|		else   {
  480|  3.92k|			if (strcmp(opt_data, cinfo->app_label) && strncmp(opt_data, objs[i]->label, sizeof objs[i]->label))
  ------------------
  |  Branch (480:8): [True: 3.85k, False: 64]
  |  Branch (480:46): [True: 3.85k, False: 0]
  ------------------
  481|  3.85k|				continue;
  482|  3.92k|		}
  483|       |
  484|     64|		if (verbose)
  ------------------
  |  Branch (484:7): [True: 30, False: 34]
  ------------------
  485|     30|			printf("Reading data object with label '%s'\n", opt_data);
  486|     64|		r = authenticate(objs[i]);
  487|     64|		if (r >= 0) {
  ------------------
  |  Branch (487:7): [True: 62, False: 2]
  ------------------
  488|     62|			private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     62|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  489|     62|			r = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &data_object);
  490|     62|			if (r) {
  ------------------
  |  Branch (490:8): [True: 3, False: 59]
  ------------------
  491|      3|				fprintf(stderr, "Data object read failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      3|#define stderr stdout
  ------------------
  492|      3|				if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|      3|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (492:9): [True: 2, False: 1]
  ------------------
  493|      2|					continue; /* DEE emulation may say there is a file */
  494|      1|				return 1;
  495|      3|			}
  496|     59|			r = print_data_object("Data Object", data_object->data, data_object->data_len);
  497|     59|			sc_pkcs15_free_data_object(data_object);
  498|     59|			return r;
  499|     62|		} else {
  500|      2|			fprintf(stderr, "Authentication error: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      2|#define stderr stdout
  ------------------
  501|      2|			return 1;
  502|      2|		}
  503|     64|	}
  504|    430|	fprintf(stderr, "Data object with label '%s' not found.\n", opt_data);
  ------------------
  |  |   39|    430|#define stderr stdout
  ------------------
  505|    430|	return 2;
  506|    492|}
fuzz_pkcs15_tool.c:authenticate:
 1472|     64|{
 1473|     64|	sc_pkcs15_object_t	*pin_obj;
 1474|     64|	u8			*pin = NULL;
 1475|     64|	int			r;
 1476|       |
 1477|     64|	if (obj->auth_id.len == 0)
  ------------------
  |  Branch (1477:6): [True: 61, False: 3]
  ------------------
 1478|     61|		return 0;
 1479|      3|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
 1480|      3|	if (r)
  ------------------
  |  Branch (1480:6): [True: 0, False: 3]
  ------------------
 1481|      0|		return r;
 1482|       |
 1483|      3|	if (opt_pin != NULL)
  ------------------
  |  Branch (1483:6): [True: 2, False: 1]
  ------------------
 1484|      2|		pin = (u8 *) opt_pin;
 1485|      1|	else
 1486|      1|		pin = get_pin("Please enter PIN", pin_obj);
 1487|       |
 1488|      3|	r = sc_pkcs15_verify_pin(p15card, pin_obj, pin, pin? strlen((char *) pin) : 0);
  ------------------
  |  Branch (1488:50): [True: 2, False: 1]
  ------------------
 1489|       |
 1490|      3|	if (opt_pin == NULL)
  ------------------
  |  Branch (1490:6): [True: 1, False: 2]
  ------------------
 1491|      1|		free(pin);
 1492|       |
 1493|      3|	return r;
 1494|      3|}
fuzz_pkcs15_tool.c:print_data_object:
  389|     59|{
  390|     59|	size_t i;
  391|       |
  392|     59|	if (opt_outfile != NULL) {
  ------------------
  |  Branch (392:6): [True: 17, False: 42]
  ------------------
  393|     17|		FILE *outf;
  394|     17|		outf = fopen(opt_outfile, "wb");
  395|     17|		if (outf == NULL) {
  ------------------
  |  Branch (395:7): [True: 1, False: 16]
  ------------------
  396|      1|			fprintf(stderr, "Error opening file '%s': %s\n",
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
  397|      1|				opt_outfile, strerror(errno));
  398|      1|			return 2;
  399|      1|			}
  400|  34.8k|		for (i=0; i < data_len; i++)
  ------------------
  |  Branch (400:13): [True: 34.8k, False: 16]
  ------------------
  401|  34.8k|			fprintf(outf, "%c", data[i]);
  402|     16|		fclose(outf);
  403|     42|	} else {
  404|     42|		if (opt_raw) {
  ------------------
  |  Branch (404:7): [True: 18, False: 24]
  ------------------
  405|  51.4k|			for (i=0; i < data_len; i++)
  ------------------
  |  Branch (405:14): [True: 51.4k, False: 18]
  ------------------
  406|  51.4k|				printf("%c", data[i]);
  407|     24|		} else {
  408|     24|			printf("%s (%lu bytes): <",
  409|     24|				kind, (unsigned long) data_len);
  410|   102k|			for (i=0; i < data_len; i++)
  ------------------
  |  Branch (410:14): [True: 102k, False: 24]
  ------------------
  411|   102k|				printf(" %02X", data[i]);
  412|     24|			printf(" >\n");
  413|     24|		}
  414|     42|	}
  415|     58|	return 0;
  416|     59|}
fuzz_pkcs15_tool.c:list_private_keys:
  689|  1.70k|{
  690|  1.70k|	int r, i;
  691|  1.70k|	struct sc_pkcs15_object *objs[32];
  692|       |
  693|  1.70k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PRKEY, objs, 32);
  ------------------
  |  |  418|  1.70k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  694|  1.70k|	if (r < 0) {
  ------------------
  |  Branch (694:6): [True: 0, False: 1.70k]
  ------------------
  695|      0|		fprintf(stderr, "Private key enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  696|      0|		return 1;
  697|      0|	}
  698|  1.70k|	if (compact)
  ------------------
  |  Branch (698:6): [True: 570, False: 1.13k]
  ------------------
  699|    570|		printf("Card has %d Private key(s).\n", r);
  700|  1.13k|	else if (verbose)
  ------------------
  |  Branch (700:11): [True: 754, False: 378]
  ------------------
  701|    754|		printf("Card has %d Private key(s).\n\n", r);
  702|  2.04k|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (702:14): [True: 344, False: 1.70k]
  ------------------
  703|    344|		print_prkey_info(objs[i]);
  704|    344|		printf("\n");
  705|    344|	}
  706|  1.70k|	return 0;
  707|  1.70k|}
fuzz_pkcs15_tool.c:print_prkey_info:
  614|    344|{
  615|    344|	struct sc_pkcs15_prkey_info *prkey = (struct sc_pkcs15_prkey_info *) obj->data;
  616|    344|	unsigned char guid[40];
  617|    344|	size_t guid_len;
  618|    344|	int i;
  619|    344|	int last_algo_refs = 0;
  620|       |
  621|    344|	if (compact) {
  ------------------
  |  Branch (621:6): [True: 50, False: 294]
  ------------------
  622|     50|		printf("\t%-3s", key_types[7 & obj->type]);
  623|       |
  624|     50|		if (prkey->modulus_length)
  ------------------
  |  Branch (624:7): [True: 33, False: 17]
  ------------------
  625|     33|			printf("[%lu]", (unsigned long)prkey->modulus_length);
  626|     17|		else {
  627|     17|			if (prkey->field_length)
  ------------------
  |  Branch (627:8): [True: 17, False: 0]
  ------------------
  628|     17|				printf("[%lu]", (unsigned long)prkey->field_length);
  629|     17|		}
  630|     50|		printf("  ID:%s", sc_pkcs15_print_id(&prkey->id));
  631|     50|		printf("  Ref:0x%02X", prkey->key_reference);
  632|     50|		if (obj->auth_id.len != 0)
  ------------------
  |  Branch (632:7): [True: 40, False: 10]
  ------------------
  633|     40|			printf("  AuthID:%s", sc_pkcs15_print_id(&obj->auth_id));
  634|     50|		printf("\n\t     %-18.*s [0x%02X", (int)sizeof obj->label, obj->label, prkey->usage);
  635|     50|		print_key_usages(prkey->usage);
  636|     50|		printf("]");
  637|     50|		return;
  638|     50|	}
  639|       |
  640|    294|	printf("Private %s Key [%.*s]\n", key_types[7 & obj->type], (int) sizeof obj->label, obj->label);
  641|    294|	print_common_flags(obj);
  642|    294|	printf("\tUsage          : [0x%02X]", prkey->usage);
  643|    294|	print_key_usages(prkey->usage);
  644|    294|	printf("\n");
  645|    294|	printf("\tAccess Flags   : [0x%02X]", prkey->access_flags);
  646|    294|	print_key_access_flags(prkey->access_flags);
  647|    294|	printf("\n");
  648|    294|	printf("\tAlgo_refs      : ");
  649|       |	/* zero may be valid and don't know how many were read  print at least 1*/
  650|  4.99k|	for (i = 0; i< SC_MAX_SUPPORTED_ALGORITHMS; i++) {
  ------------------
  |  |   61|  4.99k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (650:14): [True: 4.70k, False: 294]
  ------------------
  651|  4.70k|		if (prkey->algo_refs[i] != 0)
  ------------------
  |  Branch (651:7): [True: 0, False: 4.70k]
  ------------------
  652|      0|			last_algo_refs = i;
  653|  4.70k|	}
  654|    588|	for (i = 0; i< last_algo_refs + 1; i++) {
  ------------------
  |  Branch (654:14): [True: 294, False: 294]
  ------------------
  655|    294|		printf("%s%u", (i == 0) ? "" : ", ", prkey->algo_refs[i]);
  ------------------
  |  Branch (655:18): [True: 294, False: 0]
  ------------------
  656|    294|	}
  657|    294|	printf("\n");
  658|       |
  659|    294|	print_access_rules(obj->access_rules, SC_PKCS15_MAX_ACCESS_RULES);
  ------------------
  |  |   42|    294|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  660|       |
  661|    294|	if (prkey->modulus_length)
  ------------------
  |  Branch (661:6): [True: 208, False: 86]
  ------------------
  662|    208|		printf("\tModLength      : %lu\n", (unsigned long)prkey->modulus_length);
  663|     86|	else
  664|     86|		printf("\tFieldLength    : %lu\n", (unsigned long)prkey->field_length);
  665|    294|	printf("\tKey ref        : %d (0x%02X)\n", prkey->key_reference, prkey->key_reference);
  666|    294|	printf("\tNative         : %s\n", prkey->native ? "yes" : "no");
  ------------------
  |  Branch (666:36): [True: 294, False: 0]
  ------------------
  667|    294|	if (prkey->path.len || prkey->path.aid.len)
  ------------------
  |  Branch (667:6): [True: 0, False: 294]
  |  Branch (667:25): [True: 0, False: 294]
  ------------------
  668|      0|		printf("\tPath           : %s\n", sc_print_path(&prkey->path));
  669|    294|	if (obj->auth_id.len != 0)
  ------------------
  |  Branch (669:6): [True: 252, False: 42]
  ------------------
  670|    252|		printf("\tAuth ID        : %s\n", sc_pkcs15_print_id(&obj->auth_id));
  671|    294|	printf("\tID             : %s\n", sc_pkcs15_print_id(&prkey->id));
  672|       |
  673|    294|	guid_len = sizeof(guid);
  674|    294|	if (!sc_pkcs15_get_object_guid(p15card, obj, 1, guid, &guid_len))   {
  ------------------
  |  Branch (674:6): [True: 131, False: 163]
  ------------------
  675|    131|		printf("\tMD:guid        : ");
  676|    131|		if (strlen((char *)guid) == guid_len)   {
  ------------------
  |  Branch (676:7): [True: 82, False: 49]
  ------------------
  677|     82|			printf("%s\n", (char *)guid);
  678|     82|		}
  679|     49|		else  {
  680|     49|			printf("0x'");
  681|       |			util_hex_dump(stdout, guid, guid_len, "");
  682|     49|			printf("'\n");
  683|     49|		}
  684|    131|	}
  685|    294|}
fuzz_pkcs15_tool.c:print_key_usages:
  589|    465|{
  590|    465|	size_t i;
  591|    465|	const char *usages[] = {
  592|    465|		"encrypt", "decrypt", "sign", "signRecover", "wrap", "unwrap",
  593|    465|		"verify", "verifyRecover", "derive", "nonRepudiation"
  594|    465|	};
  595|    465|	const size_t usage_count = NELEMENTS(usages);
  ------------------
  |  |  114|    465|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
  596|  5.11k|	for (i = 0; i < usage_count; i++)
  ------------------
  |  Branch (596:14): [True: 4.65k, False: 465]
  ------------------
  597|  4.65k|		if (usage & (1 << i))
  ------------------
  |  Branch (597:7): [True: 778, False: 3.87k]
  ------------------
  598|    778|			printf(", %s", usages[i]);
  599|    465|}
fuzz_pkcs15_tool.c:print_key_access_flags:
  602|    398|{
  603|    398|	size_t i;
  604|    398|	const char *key_access_flags[] = {
  605|    398|		"sensitive", "extract", "alwaysSensitive","neverExtract", "local"
  606|    398|	};
  607|    398|	const size_t af_count = NELEMENTS(key_access_flags);
  ------------------
  |  |  114|    398|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
  608|  2.38k|	for (i = 0; i < af_count; i++)
  ------------------
  |  Branch (608:14): [True: 1.99k, False: 398]
  ------------------
  609|  1.99k|		if (flags & (1 << i))
  ------------------
  |  Branch (609:7): [True: 1.28k, False: 710]
  ------------------
  610|  1.28k|			printf(", %s", key_access_flags[i]);
  611|    398|}
fuzz_pkcs15_tool.c:list_public_keys:
  770|    627|{
  771|    627|	int r, i;
  772|    627|	struct sc_pkcs15_object *objs[32];
  773|       |
  774|    627|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_PUBKEY, objs, 32);
  ------------------
  |  |  425|    627|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  775|    627|	if (r < 0) {
  ------------------
  |  Branch (775:6): [True: 0, False: 627]
  ------------------
  776|      0|		fprintf(stderr, "Public key enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  777|      0|		return 1;
  778|      0|	}
  779|    627|	if (compact)
  ------------------
  |  Branch (779:6): [True: 141, False: 486]
  ------------------
  780|    141|		printf("Card has %d Public key(s).\n", r);
  781|    486|	else if (verbose)
  ------------------
  |  Branch (781:11): [True: 329, False: 157]
  ------------------
  782|    329|		printf("Card has %d Public key(s).\n\n", r);
  783|    748|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (783:14): [True: 121, False: 627]
  ------------------
  784|    121|		print_pubkey_info(objs[i]);
  785|    121|		printf("\n");
  786|    121|	}
  787|    627|	return 0;
  788|    627|}
fuzz_pkcs15_tool.c:print_pubkey_info:
  710|    121|{
  711|    121|	const struct sc_pkcs15_pubkey_info *pubkey = (const struct sc_pkcs15_pubkey_info *) obj->data;
  712|    121|	int have_path = (pubkey->path.len != 0) || (pubkey->path.aid.len != 0);
  ------------------
  |  Branch (712:18): [True: 26, False: 95]
  |  Branch (712:45): [True: 0, False: 95]
  ------------------
  713|       |
  714|    121|	if (compact) {
  ------------------
  |  Branch (714:6): [True: 17, False: 104]
  ------------------
  715|     17|		printf("\t%-3s", key_types[7 & obj->type]);
  716|       |
  717|     17|		if (pubkey->modulus_length)
  ------------------
  |  Branch (717:7): [True: 1, False: 16]
  ------------------
  718|      1|			printf("[%lu]", (unsigned long)pubkey->modulus_length);
  719|     16|		else
  720|     16|			printf("[FieldLength:%lu]", (unsigned long)pubkey->field_length);
  721|     17|		printf("  %s", sc_pkcs15_print_id(&pubkey->id));
  722|     17|		printf("  Ref:0x%02X", pubkey->key_reference);
  723|     17|		if (obj->auth_id.len != 0)
  ------------------
  |  Branch (723:7): [True: 2, False: 15]
  ------------------
  724|      2|			printf("  AuthID:%s", sc_pkcs15_print_id(&obj->auth_id));
  725|     17|		printf("  %-18.*s [0x%02X", (int)sizeof obj->label, obj->label, pubkey->usage);
  726|     17|		print_key_usages(pubkey->usage);
  727|     17|		printf("]");
  728|     17|		return;
  729|     17|	}
  730|       |
  731|    104|	printf("Public %s Key [%.*s]\n", key_types[7 & obj->type], (int) sizeof obj->label, obj->label);
  732|    104|	print_common_flags(obj);
  733|    104|	printf("\tUsage          : [0x%02X]", pubkey->usage);
  734|    104|	print_key_usages(pubkey->usage);
  735|    104|	printf("\n");
  736|       |
  737|    104|	printf("\tAccess Flags   : [0x%02X]", pubkey->access_flags);
  738|    104|	print_key_access_flags(pubkey->access_flags);
  739|    104|	printf("\n");
  740|       |
  741|    104|	print_access_rules(obj->access_rules, SC_PKCS15_MAX_ACCESS_RULES);
  ------------------
  |  |   42|    104|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  742|       |
  743|    104|	if (pubkey->modulus_length)   {
  ------------------
  |  Branch (743:6): [True: 24, False: 80]
  ------------------
  744|     24|		printf("\tModLength      : %lu\n", (unsigned long)pubkey->modulus_length);
  745|     24|	}
  746|     80|	else if (pubkey->field_length)   {
  ------------------
  |  Branch (746:11): [True: 58, False: 22]
  ------------------
  747|     58|		printf("\tFieldLength    : %lu\n", (unsigned long)pubkey->field_length);
  748|     58|	}
  749|     22|	else if ((obj->type == SC_PKCS15_TYPE_PUBKEY_EC || obj->type == SC_PKCS15_TYPE_PUBKEY_EDDSA)
  ------------------
  |  |  428|     44|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
              	else if ((obj->type == SC_PKCS15_TYPE_PUBKEY_EC || obj->type == SC_PKCS15_TYPE_PUBKEY_EDDSA)
  ------------------
  |  |  429|     22|#define SC_PKCS15_TYPE_PUBKEY_EDDSA		0x205
  ------------------
  |  Branch (749:12): [True: 0, False: 22]
  |  Branch (749:53): [True: 0, False: 22]
  ------------------
  750|      0|			&& have_path)   {
  ------------------
  |  Branch (750:7): [True: 0, False: 0]
  ------------------
  751|      0|		sc_pkcs15_pubkey_t *pkey = NULL;
  752|      0|		if (!sc_pkcs15_read_pubkey(p15card, obj, &pkey))   {
  ------------------
  |  Branch (752:7): [True: 0, False: 0]
  ------------------
  753|      0|			printf("\tFieldLength    : %lu\n", (unsigned long)pkey->u.ec.params.field_length);
  754|      0|			sc_pkcs15_free_pubkey(pkey);
  755|      0|		}
  756|      0|	}
  757|       |
  758|    104|	printf("\tKey ref        : %d (0x%02X)\n", pubkey->key_reference,  pubkey->key_reference);
  759|    104|	printf("\tNative         : %s\n", pubkey->native ? "yes" : "no");
  ------------------
  |  Branch (759:36): [True: 104, False: 0]
  ------------------
  760|    104|	if (have_path)
  ------------------
  |  Branch (760:6): [True: 22, False: 82]
  ------------------
  761|     22|		printf("\tPath           : %s\n", sc_print_path(&pubkey->path));
  762|    104|	if (obj->auth_id.len != 0)
  ------------------
  |  Branch (762:6): [True: 11, False: 93]
  ------------------
  763|     11|		printf("\tAuth ID        : %s\n", sc_pkcs15_print_id(&obj->auth_id));
  764|    104|	printf("\tID             : %s\n", sc_pkcs15_print_id(&pubkey->id));
  765|    104|	if (!have_path || obj->content.len)
  ------------------
  |  Branch (765:6): [True: 82, False: 22]
  |  Branch (765:20): [True: 0, False: 22]
  ------------------
  766|     82|		printf("\tDirectValue    : <%s>\n", obj->content.len ? "present" : "absent");
  ------------------
  |  Branch (766:39): [True: 0, False: 82]
  ------------------
  767|    104|}
fuzz_pkcs15_tool.c:read_public_key:
  791|     24|{
  792|     24|	int r;
  793|     24|	struct sc_pkcs15_id id;
  794|     24|	struct sc_pkcs15_object *obj;
  795|     24|	sc_pkcs15_pubkey_t *pubkey = NULL;
  796|     24|	sc_pkcs15_cert_t *cert = NULL;
  797|     24|	sc_pkcs15_der_t pem_key;
  798|       |
  799|     24|	pem_key.value = NULL;
  800|     24|	pem_key.len = 0;
  801|       |
  802|     24|	id.len = SC_PKCS15_MAX_ID_SIZE;
  ------------------
  |  |   36|     24|#define SC_PKCS15_MAX_ID_SIZE		255
  ------------------
  803|     24|	sc_pkcs15_hex_string_to_id(opt_pubkey, &id);
  804|       |
  805|     24|	r = sc_pkcs15_find_pubkey_by_id(p15card, &id, &obj);
  806|     24|	if (r >= 0) {
  ------------------
  |  Branch (806:6): [True: 0, False: 24]
  ------------------
  807|      0|		if (verbose)
  ------------------
  |  Branch (807:7): [True: 0, False: 0]
  ------------------
  808|      0|			printf("Reading public key with ID '%s'\n", opt_pubkey);
  809|      0|		r = sc_pkcs15_read_pubkey(p15card, obj, &pubkey);
  810|     24|	} else if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|     24|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (810:13): [True: 24, False: 0]
  ------------------
  811|       |		/* No pubkey - try if there's a certificate */
  812|     24|		int private_obj;
  813|     24|		r = sc_pkcs15_find_cert_by_id(p15card, &id, &obj);
  814|     24|		if (r >= 0) {
  ------------------
  |  Branch (814:7): [True: 2, False: 22]
  ------------------
  815|      2|			if (verbose)
  ------------------
  |  Branch (815:8): [True: 1, False: 1]
  ------------------
  816|      1|				printf("Reading certificate with ID '%s'\n", opt_pubkey);
  817|      2|			private_obj = obj->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      2|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  818|      2|			r = sc_pkcs15_read_certificate(p15card, (sc_pkcs15_cert_info_t *) obj->data, private_obj, &cert);
  819|      2|		}
  820|     24|		if (r >= 0)
  ------------------
  |  Branch (820:7): [True: 0, False: 24]
  ------------------
  821|      0|			pubkey = cert->key;
  822|     24|	}
  823|       |
  824|     24|	if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|     24|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (824:6): [True: 22, False: 2]
  ------------------
  825|     22|		fprintf(stderr, "Public key with ID '%s' not found.\n", opt_pubkey);
  ------------------
  |  |   39|     22|#define stderr stdout
  ------------------
  826|     22|		r = 2;
  827|     22|		goto out;
  828|     22|	}
  829|      2|	if (r < 0) {
  ------------------
  |  Branch (829:6): [True: 2, False: 0]
  ------------------
  830|      2|		fprintf(stderr, "Public key enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      2|#define stderr stdout
  ------------------
  831|      2|		r = 1;
  832|      2|		goto out;
  833|      2|	}
  834|      0|	if (!pubkey) {
  ------------------
  |  Branch (834:6): [True: 0, False: 0]
  ------------------
  835|      0|		fprintf(stderr, "Public key not available\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  836|      0|		r = 1;
  837|      0|		goto out;
  838|      0|	}
  839|       |
  840|      0|	r = sc_pkcs15_encode_pubkey_as_spki(ctx, pubkey, &pem_key.value, &pem_key.len);
  841|      0|	if (r < 0) {
  ------------------
  |  Branch (841:6): [True: 0, False: 0]
  ------------------
  842|      0|		fprintf(stderr, "Error encoding PEM key: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  843|      0|		r = 1;
  844|      0|	} else {
  845|      0|		r = print_pem_object("PUBLIC KEY", pem_key.value, pem_key.len);
  846|      0|		free(pem_key.value);
  847|      0|	}
  848|       |
  849|     24|out:
  850|     24|	if (cert)
  ------------------
  |  Branch (850:6): [True: 0, False: 24]
  ------------------
  851|      0|		sc_pkcs15_free_certificate(cert);
  852|     24|	else
  853|     24|		sc_pkcs15_free_pubkey(pubkey);
  854|       |
  855|     24|	return r;
  856|      0|}
fuzz_pkcs15_tool.c:read_ssh_key:
  956|      6|{
  957|      6|	int r;
  958|      6|	struct sc_pkcs15_id id;
  959|      6|	struct sc_pkcs15_object *obj = NULL;
  960|      6|	sc_pkcs15_pubkey_t *pubkey = NULL;
  961|      6|	sc_pkcs15_cert_t *cert = NULL;
  962|      6|	FILE *outf = NULL;
  963|       |
  964|      6|	if (opt_outfile != NULL) {
  ------------------
  |  Branch (964:6): [True: 3, False: 3]
  ------------------
  965|      3|		outf = fopen(opt_outfile, "w");
  966|      3|		if (outf == NULL) {
  ------------------
  |  Branch (966:7): [True: 1, False: 2]
  ------------------
  967|      1|			fprintf(stderr, "Error opening file '%s': %s\n", opt_outfile, strerror(errno));
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
  968|      1|			goto fail2;
  969|      1|		}
  970|      3|	}
  971|      3|	else   {
  972|      3|		outf = stdout;
  973|      3|	}
  974|       |
  975|      5|	id.len = SC_PKCS15_MAX_ID_SIZE;
  ------------------
  |  |   36|      5|#define SC_PKCS15_MAX_ID_SIZE		255
  ------------------
  976|      5|	sc_pkcs15_hex_string_to_id(opt_pubkey, &id);
  977|       |
  978|      5|	r = sc_pkcs15_find_pubkey_by_id(p15card, &id, &obj);
  979|      5|	if (r >= 0) {
  ------------------
  |  Branch (979:6): [True: 0, False: 5]
  ------------------
  980|      0|		if (verbose)
  ------------------
  |  Branch (980:7): [True: 0, False: 0]
  ------------------
  981|      0|			fprintf(stderr,"Reading ssh key with ID '%s'\n", opt_pubkey);
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  982|      0|		r = authenticate(obj);
  983|      0|		if (r >= 0)
  ------------------
  |  Branch (983:7): [True: 0, False: 0]
  ------------------
  984|      0|			r = sc_pkcs15_read_pubkey(p15card, obj, &pubkey);
  985|      0|	}
  986|      5|	else if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|      5|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (986:11): [True: 5, False: 0]
  ------------------
  987|       |		/* No pubkey - try if there's a certificate */
  988|      5|		int private_obj;
  989|      5|		r = sc_pkcs15_find_cert_by_id(p15card, &id, &obj);
  990|      5|		if (r >= 0) {
  ------------------
  |  Branch (990:7): [True: 3, False: 2]
  ------------------
  991|      3|			if (verbose)
  ------------------
  |  Branch (991:8): [True: 1, False: 2]
  ------------------
  992|      1|				fprintf(stderr,"Reading certificate with ID '%s'\n", opt_pubkey);
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
  993|      3|			private_obj = obj->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      3|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  994|      3|			r = sc_pkcs15_read_certificate(p15card, (sc_pkcs15_cert_info_t *) obj->data, private_obj, &cert);
  995|      3|		}
  996|      5|		if (r >= 0)
  ------------------
  |  Branch (996:7): [True: 0, False: 5]
  ------------------
  997|      0|			pubkey = cert->key;
  998|      5|	}
  999|       |
 1000|      5|	if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|      5|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1000:6): [True: 2, False: 3]
  ------------------
 1001|      2|		if (opt_outfile != NULL)
  ------------------
  |  Branch (1001:7): [True: 1, False: 1]
  ------------------
 1002|      1|			fclose(outf);
 1003|      2|		fprintf(stderr, "Public key with ID '%s' not found.\n", opt_pubkey);
  ------------------
  |  |   39|      2|#define stderr stdout
  ------------------
 1004|      2|		return 2;
 1005|      2|	}
 1006|      3|	if (r < 0) {
  ------------------
  |  Branch (1006:6): [True: 3, False: 0]
  ------------------
 1007|      3|		if (opt_outfile != NULL)
  ------------------
  |  Branch (1007:7): [True: 1, False: 2]
  ------------------
 1008|      1|			fclose(outf);
 1009|      3|		fprintf(stderr, "Public key enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      3|#define stderr stdout
  ------------------
 1010|      3|		return 1;
 1011|      3|	}
 1012|       |
 1013|      0|	if (pubkey->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1013:6): [True: 0, False: 0]
  ------------------
 1014|       |		// SSH supports only ed25519 key now
 1015|       |
 1016|      0|		const char alg[] = "ssh-ed25519";
 1017|       |		/* Large enough to fit the following:
 1018|       |		 * 2 x 4B item length headers
 1019|       |		 * max 11B algorithm name, 32B key data */
 1020|      0|		unsigned char buf[64];
 1021|      0|		size_t n, len;
 1022|       |
 1023|      0|		n = pubkey->u.ec.ecpointQ.len;
 1024|      0|		if (n != 32) {
  ------------------
  |  Branch (1024:7): [True: 0, False: 0]
  ------------------
 1025|      0|			fprintf(stderr, "Wrong public key length\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1026|      0|			goto fail2;
 1027|      0|		}
 1028|       |
 1029|      0|		len = strlen(alg);
 1030|      0|		buf[0] = 0;
 1031|      0|		buf[1] = 0;
 1032|      0|		buf[2] = 0;
 1033|      0|		buf[3] = len;
 1034|      0|		memcpy(buf+4, alg, len);
 1035|      0|		len += 4;
 1036|       |
 1037|      0|		buf[len++] = 0;
 1038|      0|		buf[len++] = 0;
 1039|      0|		buf[len++] = 0;
 1040|      0|		buf[len++] = n & 0xff;
 1041|      0|		memcpy(buf + len, pubkey->u.ec.ecpointQ.value, n);
 1042|      0|		len += n;
 1043|       |
 1044|      0|		print_ssh_key(outf, alg, obj, buf, len);
 1045|      0|	}
 1046|      0|	if (pubkey->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1046:6): [True: 0, False: 0]
  ------------------
 1047|       |		// support only for NIST
 1048|       |		// 'ssh-keygen -t ecdsa' allow only field lengths 256/384/521
 1049|       |
 1050|      0|		static struct supported_ec_curves {
 1051|      0|			char *curve_name;
 1052|      0|			struct sc_object_id curve_oid;
 1053|      0|			size_t size;
 1054|      0|		} ec_curves[] = {
 1055|      0|			{"secp256r1", {{1, 2, 840, 10045, 3, 1, 7, -1}},256},
 1056|      0|			{"secp384r1", {{1, 3, 132, 0, 34, -1}},         384},
 1057|      0|			{"secp521r1", {{1, 3, 132, 0, 35, -1}},         521},
 1058|      0|		        {NULL, {{-1}}, 0},
 1059|      0|		};
 1060|      0|		char alg[20];
 1061|       |		/* Large enough to fit the following:
 1062|       |		 * 3 x 4B item length headers
 1063|       |		 * max 20B algorithm name, 9B curve name, max 256B key data */
 1064|      0|		unsigned char buf[300];
 1065|      0|		unsigned int i, tmp;
 1066|      0|		size_t n;
 1067|      0|		int len;
 1068|       |
 1069|      0|		for (n = 0,i = 0; ec_curves[i].curve_name != NULL; i++) {
  ------------------
  |  Branch (1069:21): [True: 0, False: 0]
  ------------------
 1070|      0|			if(sc_compare_oid (&ec_curves[i].curve_oid,&pubkey->u.ec.params.id))
  ------------------
  |  Branch (1070:7): [True: 0, False: 0]
  ------------------
 1071|      0|				n = ec_curves[i].size;
 1072|      0|		}
 1073|      0|		if (!n) {
  ------------------
  |  Branch (1073:7): [True: 0, False: 0]
  ------------------
 1074|      0|			fprintf(stderr, "Unsupported curve\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1075|      0|			goto fail2;
 1076|      0|		}
 1077|      0|		if (n != pubkey->u.ec.params.field_length) {
  ------------------
  |  Branch (1077:7): [True: 0, False: 0]
  ------------------
 1078|      0|			fprintf(stderr, "Wrong field length\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1079|      0|			goto fail2;
 1080|      0|		}
 1081|       |
 1082|      0|		len = snprintf(alg, sizeof alg, "ecdsa-sha2-nistp%zu", n);
 1083|      0|		if (len < 0) {
  ------------------
  |  Branch (1083:7): [True: 0, False: 0]
  ------------------
 1084|      0|			fprintf(stderr, "failed to write algorithm\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1085|      0|			goto fail2;
 1086|      0|		}
 1087|      0|		buf[0] = 0;
 1088|      0|		buf[1] = 0;
 1089|      0|		buf[2] = 0;
 1090|      0|		buf[3] = len;
 1091|      0|		memcpy(buf+4, alg, len);
 1092|      0|		len += 4;
 1093|       |
 1094|      0|		buf[len++] = 0;
 1095|      0|		buf[len++] = 0;
 1096|      0|		buf[len++] = 0;
 1097|      0|		tmp = snprintf((char *) buf+len+1, 9, "nistp%zu", n);
 1098|      0|		buf[len++] = tmp;
 1099|      0|		len += tmp;
 1100|       |
 1101|      0|		n = pubkey->u.ec.ecpointQ.len;
 1102|      0|		if(n > 255) {
  ------------------
  |  Branch (1102:6): [True: 0, False: 0]
  ------------------
 1103|      0|			fprintf(stderr, "Wrong public key length\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1104|      0|			goto fail2;
 1105|      0|		}
 1106|      0|		buf[len++] = 0;
 1107|      0|		buf[len++] = 0;
 1108|      0|		buf[len++] = 0;
 1109|      0|		buf[len++] = n & 0xff;
 1110|      0|		memcpy(buf+len,pubkey->u.ec.ecpointQ.value,n);
 1111|      0|		len += n;
 1112|       |
 1113|      0|		print_ssh_key(outf, alg, obj, buf, len);
 1114|      0|	}
 1115|       |
 1116|      0|	if (pubkey->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1116:6): [True: 0, False: 0]
  ------------------
 1117|      0|		unsigned char buf[2048];
 1118|      0|		size_t len, n;
 1119|       |
 1120|      0|		if (!pubkey->u.rsa.modulus.data || !pubkey->u.rsa.modulus.len ||
  ------------------
  |  Branch (1120:7): [True: 0, False: 0]
  |  Branch (1120:38): [True: 0, False: 0]
  ------------------
 1121|      0|				!pubkey->u.rsa.exponent.data || !pubkey->u.rsa.exponent.len)  {
  ------------------
  |  Branch (1121:5): [True: 0, False: 0]
  |  Branch (1121:37): [True: 0, False: 0]
  ------------------
 1122|      0|			fprintf(stderr, "Failed to decode public RSA key.\n");
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1123|      0|			goto fail2;
 1124|      0|		}
 1125|       |
 1126|      0|		buf[0]=0;
 1127|      0|		buf[1]=0;
 1128|      0|		buf[2]=0;
 1129|      0|		buf[3]=7;
 1130|       |
 1131|      0|		len = sprintf((char *) buf+4,"ssh-rsa");
 1132|      0|		len+=4;
 1133|       |
 1134|      0|		if (sizeof(buf)-len < 5+pubkey->u.rsa.exponent.len)
  ------------------
  |  Branch (1134:7): [True: 0, False: 0]
  ------------------
 1135|      0|			goto fail;
 1136|       |
 1137|      0|		n = pubkey->u.rsa.exponent.len;
 1138|      0|		if (pubkey->u.rsa.exponent.data[0] & 0x80)
  ------------------
  |  Branch (1138:7): [True: 0, False: 0]
  ------------------
 1139|      0|			n++;
 1140|       |
 1141|      0|		buf[len++]=(n >>24) & 0xff;
 1142|      0|		buf[len++]=(n >>16) & 0xff;
 1143|      0|		buf[len++]=(n >>8) & 0xff;
 1144|      0|		buf[len++]=(n) & 0xff;
 1145|      0|		if (pubkey->u.rsa.exponent.data[0] & 0x80)
  ------------------
  |  Branch (1145:7): [True: 0, False: 0]
  ------------------
 1146|      0|			buf[len++]= 0;
 1147|       |
 1148|      0|		memcpy(buf+len,pubkey->u.rsa.exponent.data, pubkey->u.rsa.exponent.len);
 1149|      0|		len += pubkey->u.rsa.exponent.len;
 1150|       |
 1151|      0|		if (sizeof(buf)-len < 5+pubkey->u.rsa.modulus.len)
  ------------------
  |  Branch (1151:7): [True: 0, False: 0]
  ------------------
 1152|      0|			goto fail;
 1153|       |
 1154|      0|		n = pubkey->u.rsa.modulus.len;
 1155|      0|		if (pubkey->u.rsa.modulus.data[0] & 0x80)
  ------------------
  |  Branch (1155:7): [True: 0, False: 0]
  ------------------
 1156|      0|			n++;
 1157|      0|		buf[len++]=(n >>24) & 0xff;
 1158|      0|		buf[len++]=(n >>16) & 0xff;
 1159|      0|		buf[len++]=(n >>8) & 0xff;
 1160|      0|		buf[len++]=(n) & 0xff;
 1161|       |
 1162|      0|		if (pubkey->u.rsa.modulus.data[0] & 0x80)
  ------------------
  |  Branch (1162:7): [True: 0, False: 0]
  ------------------
 1163|      0|			buf[len++]= 0;
 1164|       |
 1165|      0|		memcpy(buf+len,pubkey->u.rsa.modulus.data, pubkey->u.rsa.modulus.len);
 1166|      0|		len += pubkey->u.rsa.modulus.len;
 1167|       |
 1168|      0|		print_ssh_key(outf, "ssh-rsa", obj, buf, len);
 1169|      0|	}
 1170|       |
 1171|      0|	if (opt_outfile != NULL)
  ------------------
  |  Branch (1171:6): [True: 0, False: 0]
  ------------------
 1172|      0|		fclose(outf);
 1173|      0|	if (cert)
  ------------------
  |  Branch (1173:6): [True: 0, False: 0]
  ------------------
 1174|      0|		sc_pkcs15_free_certificate(cert);
 1175|      0|	else
 1176|      0|		sc_pkcs15_free_pubkey(pubkey);
 1177|      0|	return 0;
 1178|      0|fail:
 1179|      0|	printf("can't convert key: buffer too small\n");
 1180|      1|fail2:
 1181|      1|	if (opt_outfile != NULL && outf != NULL)
  ------------------
  |  Branch (1181:6): [True: 1, False: 0]
  |  Branch (1181:29): [True: 0, False: 1]
  ------------------
 1182|      0|		fclose(outf);
 1183|      1|	if (cert)
  ------------------
  |  Branch (1183:6): [True: 0, False: 1]
  ------------------
 1184|      0|		sc_pkcs15_free_certificate(cert);
 1185|      1|	else
 1186|      1|		sc_pkcs15_free_pubkey(pubkey);
 1187|      1|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      1|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1188|      0|}
fuzz_pkcs15_tool.c:list_pins:
 1575|    675|{
 1576|    675|	int r, i;
 1577|    675|	struct sc_pkcs15_object *objs[32];
 1578|       |
 1579|    675|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH, objs, 32);
  ------------------
  |  |  444|    675|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1580|    675|	if (r < 0) {
  ------------------
  |  Branch (1580:6): [True: 0, False: 675]
  ------------------
 1581|      0|		fprintf(stderr, "AUTH objects enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1582|      0|		return 1;
 1583|      0|	}
 1584|    675|	if (compact)
  ------------------
  |  Branch (1584:6): [True: 150, False: 525]
  ------------------
 1585|    150|		printf("Card has %d Authentication object(s).\n", r);
 1586|    525|	else if (verbose)
  ------------------
  |  Branch (1586:11): [True: 346, False: 179]
  ------------------
 1587|    346|		printf("Card has %d Authentication object(s).\n\n", r);
 1588|       |
 1589|  1.71k|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (1589:14): [True: 1.03k, False: 675]
  ------------------
 1590|  1.03k|		sc_pkcs15_get_pin_info(p15card, objs[i]);
 1591|  1.03k|		print_pin_info(objs[i]);
 1592|  1.03k|		printf("\n");
 1593|  1.03k|	}
 1594|    675|	return 0;
 1595|    675|}
fuzz_pkcs15_tool.c:print_pin_info:
 1497|  1.03k|{
 1498|  1.03k|	const char *pin_flags[] = {
 1499|  1.03k|		"case-sensitive", "local", "change-disabled",
 1500|  1.03k|		"unblock-disabled", "initialized", "needs-padding",
 1501|  1.03k|		"unblockingPin", "soPin", "disable_allowed",
 1502|  1.03k|		"integrity-protected", "confidentiality-protected",
 1503|  1.03k|		"exchangeRefData"
 1504|  1.03k|	};
 1505|  1.03k|	const char *pin_types[] = {"bcd", "ascii-numeric", "UTF-8", "halfnibble bcd", "iso 9664-1"};
 1506|  1.03k|	const struct sc_pkcs15_auth_info *auth_info = (const struct sc_pkcs15_auth_info *) obj->data;
 1507|  1.03k|	const size_t pf_count = NELEMENTS(pin_flags);
  ------------------
  |  |  114|  1.03k|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
 1508|  1.03k|	size_t i;
 1509|       |
 1510|  1.03k|	if (obj->type != SC_PKCS15_TYPE_AUTH_PIN && obj->type != SC_PKCS15_TYPE_AUTH_AUTHKEY)
  ------------------
  |  |  445|  2.07k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
              	if (obj->type != SC_PKCS15_TYPE_AUTH_PIN && obj->type != SC_PKCS15_TYPE_AUTH_AUTHKEY)
  ------------------
  |  |  447|      0|#define SC_PKCS15_TYPE_AUTH_AUTHKEY		0x603
  ------------------
  |  Branch (1510:6): [True: 0, False: 1.03k]
  |  Branch (1510:46): [True: 0, False: 0]
  ------------------
 1511|      0|		return;
 1512|       |
 1513|  1.03k|	if (compact) {
  ------------------
  |  Branch (1513:6): [True: 209, False: 827]
  ------------------
 1514|    209|		printf("\t%-3s  ID:%s", obj->type == SC_PKCS15_TYPE_AUTH_PIN ? "PIN" : "Key",
  ------------------
  |  |  445|    209|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  |  Branch (1514:27): [True: 209, False: 0]
  ------------------
 1515|    209|			sc_pkcs15_print_id(&auth_info->auth_id));
 1516|    209|		if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN) {
  ------------------
  |  |   94|    209|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1516:7): [True: 209, False: 0]
  ------------------
 1517|    209|			const struct sc_pkcs15_pin_attributes *pin_attrs = &(auth_info->attrs.pin);
 1518|    209|			printf("  Ref:0x%02X", pin_attrs->reference);
 1519|    209|		}
 1520|      0|		else {
 1521|      0|			const struct sc_pkcs15_authkey_attributes *attrs = &auth_info->attrs.authkey;
 1522|      0|			printf("  Derived:%i", attrs->derived);
 1523|      0|			printf("  SecretKeyID:%s", sc_pkcs15_print_id(&attrs->skey_id));
 1524|      0|		}
 1525|    209|		if (obj->auth_id.len)
  ------------------
  |  Branch (1525:7): [True: 93, False: 116]
  ------------------
 1526|     93|			printf("  AuthID:%s", sc_pkcs15_print_id(&obj->auth_id));
 1527|    209|		if (auth_info->path.len || auth_info->path.aid.len)
  ------------------
  |  Branch (1527:7): [True: 0, False: 209]
  |  Branch (1527:30): [True: 9, False: 200]
  ------------------
 1528|      9|			printf("  Path:%s", sc_print_path(&auth_info->path));
 1529|    209|		if (auth_info->tries_left >= 0)
  ------------------
  |  Branch (1529:7): [True: 22, False: 187]
  ------------------
 1530|     22|			printf("  Tries:%d", auth_info->tries_left);
 1531|    209|		printf("  %.*s", (int) sizeof obj->label, obj->label);
 1532|    209|		return;
 1533|    209|	}
 1534|       |
 1535|    827|	printf("%s [%.*s]\n", obj->type == SC_PKCS15_TYPE_AUTH_PIN ? "PIN" : "AuthKey",
  ------------------
  |  |  445|    827|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  |  Branch (1535:24): [True: 827, False: 0]
  ------------------
 1536|    827|		(int) sizeof obj->label, obj->label);
 1537|       |
 1538|    827|	print_common_flags(obj);
 1539|    827|	if (obj->auth_id.len)
  ------------------
  |  Branch (1539:6): [True: 365, False: 462]
  ------------------
 1540|    365|		printf("\tAuth ID        : %s\n", sc_pkcs15_print_id(&obj->auth_id));
 1541|       |
 1542|    827|	printf("\tID             : %s\n", sc_pkcs15_print_id(&auth_info->auth_id));
 1543|    827|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    827|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1543:6): [True: 827, False: 0]
  ------------------
 1544|    827|		const struct sc_pkcs15_pin_attributes *pin_attrs = &(auth_info->attrs.pin);
 1545|       |
 1546|    827|		printf("\tFlags          : [0x%02X]", pin_attrs->flags);
 1547|  10.7k|		for (i = 0; i < pf_count; i++)
  ------------------
  |  Branch (1547:15): [True: 9.92k, False: 827]
  ------------------
 1548|  9.92k|			if (pin_attrs->flags & (1 << i))
  ------------------
  |  Branch (1548:8): [True: 2.47k, False: 7.45k]
  ------------------
 1549|  2.47k|				printf(", %s", pin_flags[i]);
 1550|    827|		printf("\n");
 1551|       |
 1552|    827|		printf("\tLength         : min_len:%lu, max_len:%lu, stored_len:%lu\n",
 1553|    827|			(unsigned long)pin_attrs->min_length, (unsigned long)pin_attrs->max_length,
 1554|    827|			(unsigned long)pin_attrs->stored_length);
 1555|    827|		printf("\tPad char       : 0x%02X\n", pin_attrs->pad_char);
 1556|    827|		printf("\tReference      : %d (0x%02X)\n", pin_attrs->reference, pin_attrs->reference);
 1557|    827|		if (pin_attrs->type < NELEMENTS(pin_types))
  ------------------
  |  |  114|    827|#define NELEMENTS(x)	(sizeof(x)/sizeof((x)[0]))
  ------------------
  |  Branch (1557:7): [True: 827, False: 0]
  ------------------
 1558|    827|			printf("\tType           : %s\n", pin_types[pin_attrs->type]);
 1559|      0|		else
 1560|      0|			printf("\tType           : [encoding %d]\n", pin_attrs->type);
 1561|    827|	}
 1562|      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 (1562:11): [True: 0, False: 0]
  ------------------
 1563|      0|		const struct sc_pkcs15_authkey_attributes *attrs = &auth_info->attrs.authkey;
 1564|      0|		printf("\tDerived        : %i\n", attrs->derived);
 1565|      0|		printf("\tSecretKeyID    : %s\n", sc_pkcs15_print_id(&attrs->skey_id));
 1566|      0|	}
 1567|       |
 1568|    827|	if (auth_info->path.len || auth_info->path.aid.len)
  ------------------
  |  Branch (1568:6): [True: 0, False: 827]
  |  Branch (1568:29): [True: 24, False: 803]
  ------------------
 1569|     24|		printf("\tPath           : %s\n", sc_print_path(&auth_info->path));
 1570|    827|	if (auth_info->tries_left >= 0)
  ------------------
  |  Branch (1570:6): [True: 128, False: 699]
  ------------------
 1571|    128|		printf("\tTries left     : %d\n", auth_info->tries_left);
 1572|    827|}
fuzz_pkcs15_tool.c:list_skeys:
  893|    618|{
  894|    618|	int r, i;
  895|    618|	struct sc_pkcs15_object *objs[32];
  896|       |
  897|    618|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_SKEY, objs, 32);
  ------------------
  |  |  432|    618|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  898|    618|	if (r < 0) {
  ------------------
  |  Branch (898:6): [True: 0, False: 618]
  ------------------
  899|      0|		fprintf(stderr, "Secret key enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
  900|      0|		return 1;
  901|      0|	}
  902|    618|	if (verbose)
  ------------------
  |  Branch (902:6): [True: 424, False: 194]
  ------------------
  903|    424|		printf("Card has %d Secret key(s).\n\n", r);
  904|    618|	for (i = 0; i < r; i++) {
  ------------------
  |  Branch (904:14): [True: 0, False: 618]
  ------------------
  905|      0|		print_skey_info(objs[i]);
  906|      0|		printf("\n");
  907|      0|	}
  908|       |
  909|    618|	return 0;
  910|    618|}
fuzz_pkcs15_tool.c:list_apps:
 1598|      5|{
 1599|      5|	unsigned j;
 1600|      5|	int i;
 1601|       |
 1602|      8|	for (i=0; i<p15card->card->app_count; i++)   {
  ------------------
  |  Branch (1602:12): [True: 3, False: 5]
  ------------------
 1603|      3|		struct sc_app_info *info = p15card->card->app[i];
 1604|       |
 1605|      3|		fprintf(fout, "Application '%s':\n", info->label);
 1606|      3|		fprintf(fout, "\tAID: ");
 1607|     37|		for(j=0;j<info->aid.len;j++)
  ------------------
  |  Branch (1607:11): [True: 34, False: 3]
  ------------------
 1608|     34|			fprintf(fout, "%02X", info->aid.value[j]);
 1609|      3|		fprintf(fout, "\n");
 1610|       |
 1611|      3|		if (info->ddo.value && info->ddo.len)   {
  ------------------
  |  Branch (1611:7): [True: 0, False: 3]
  |  Branch (1611:26): [True: 0, False: 0]
  ------------------
 1612|      0|			fprintf(fout, "\tDDO: ");
 1613|      0|			for(j=0;j<info->ddo.len;j++)
  ------------------
  |  Branch (1613:12): [True: 0, False: 0]
  ------------------
 1614|      0|				fprintf(fout, "%02X", info->ddo.value[j]);
 1615|      0|			fprintf(fout, "\n");
 1616|      0|		}
 1617|       |
 1618|      3|		fprintf(fout, "\n");
 1619|      3|	}
 1620|      5|	return 0;
 1621|      5|}
fuzz_pkcs15_tool.c:dump:
 1701|    610|{
 1702|    610|	list_info();
 1703|    610|	list_pins();
 1704|    610|	list_private_keys();
 1705|    610|	list_public_keys();
 1706|    610|	list_skeys();
 1707|    610|	list_certificates();
 1708|    610|	list_data_objects();
 1709|       |
 1710|    610|	return 0;
 1711|    610|}
fuzz_pkcs15_tool.c:change_pin:
 1814|    282|{
 1815|    282|	sc_pkcs15_object_t *pin_obj;
 1816|    282|	sc_pkcs15_auth_info_t *pinfo = NULL;
 1817|    282|	u8 *pincode, *newpin;
 1818|    282|	int r, pinpad_present = 0;
 1819|       |
 1820|    282|	pinpad_present = p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    564|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1820:19): [True: 0, False: 282]
  ------------------
 1821|    282|	   	|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH;
  ------------------
  |  |  560|    564|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (1821:9): [True: 0, False: 282]
  ------------------
 1822|       |
 1823|    282|	if (!(pin_obj = get_pin_info()))
  ------------------
  |  Branch (1823:6): [True: 2, False: 280]
  ------------------
 1824|      2|		return 2;
 1825|       |
 1826|    280|	pinfo = (sc_pkcs15_auth_info_t *) pin_obj->data;
 1827|    280|	if (pinfo->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    280|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1827:6): [True: 0, False: 280]
  ------------------
 1828|      0|		return 1;
 1829|       |
 1830|    280|	if (pinfo->tries_left != -1) {
  ------------------
  |  Branch (1830:6): [True: 3, False: 277]
  ------------------
 1831|      3|		if (pinfo->tries_left != pinfo->max_tries) {
  ------------------
  |  Branch (1831:7): [True: 2, False: 1]
  ------------------
 1832|      2|			if (pinfo->tries_left == 0) {
  ------------------
  |  Branch (1832:8): [True: 1, False: 1]
  ------------------
 1833|      1|				fprintf(stderr, "PIN code blocked!\n");
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
 1834|      1|				return 2;
 1835|      1|			} else {
 1836|      1|				fprintf(stderr, "%d PIN tries left.\n", pinfo->tries_left);
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
 1837|      1|			}
 1838|      2|		}
 1839|      3|	}
 1840|       |
 1841|    279|	pincode = (u8 *) opt_pin;
 1842|    279|	if (pincode == NULL) {
  ------------------
  |  Branch (1842:6): [True: 45, False: 234]
  ------------------
 1843|     45|		pincode = get_pin("Enter old PIN", pin_obj);
 1844|     45|		if (!pinpad_present && pincode == NULL)
  ------------------
  |  Branch (1844:7): [True: 45, False: 0]
  |  Branch (1844:26): [True: 45, False: 0]
  ------------------
 1845|     45|			return 2;
 1846|     45|	}
 1847|       |
 1848|    234|	if (pincode && strlen((char *) pincode) == 0) {
  ------------------
  |  Branch (1848:6): [True: 234, False: 0]
  |  Branch (1848:17): [True: 1, False: 233]
  ------------------
 1849|      1|		fprintf(stderr, "No PIN code supplied.\n");
  ------------------
  |  |   39|      1|#define stderr stdout
  ------------------
 1850|      1|		if (opt_pin == NULL)
  ------------------
  |  Branch (1850:7): [True: 0, False: 1]
  ------------------
 1851|      0|			free(pincode);
 1852|      1|		return 2;
 1853|      1|	}
 1854|       |
 1855|    233|	if (pincode == NULL && verbose)
  ------------------
  |  Branch (1855:6): [True: 0, False: 233]
  |  Branch (1855:25): [True: 0, False: 0]
  ------------------
 1856|      0|		printf("Old PIN value will be prompted with pinpad.\n");
 1857|       |
 1858|    233|	newpin = (u8 *) opt_newpin;
 1859|    233|	while (newpin == NULL) {
  ------------------
  |  Branch (1859:9): [True: 28, False: 205]
  ------------------
 1860|     28|		u8 *newpin2;
 1861|       |
 1862|     28|		newpin = get_pin("Enter new PIN", pin_obj);
 1863|     28|		if (pinpad_present && newpin == NULL)   {
  ------------------
  |  Branch (1863:7): [True: 0, False: 28]
  |  Branch (1863:25): [True: 0, False: 0]
  ------------------
 1864|      0|			if (verbose)
  ------------------
  |  Branch (1864:8): [True: 0, False: 0]
  ------------------
 1865|      0|				printf("New PIN value will be prompted with pinpad.\n");
 1866|      0|			break;
 1867|      0|		}
 1868|     28|		if (newpin == NULL || strlen((char *) newpin) == 0)   {
  ------------------
  |  Branch (1868:7): [True: 28, False: 0]
  |  Branch (1868:25): [True: 0, False: 0]
  ------------------
 1869|     28|			fprintf(stderr, "No new PIN value supplied.\n");
  ------------------
  |  |   39|     28|#define stderr stdout
  ------------------
 1870|     28|			free(newpin);
 1871|     28|			if (opt_pin == NULL)
  ------------------
  |  Branch (1871:8): [True: 0, False: 28]
  ------------------
 1872|      0|				free(pincode);
 1873|     28|			return 2;
 1874|     28|		}
 1875|       |
 1876|      0|		newpin2 = get_pin("Enter new PIN again", pin_obj);
 1877|      0|		if (newpin2 && strlen((char *) newpin2) &&
  ------------------
  |  Branch (1877:7): [True: 0, False: 0]
  |  Branch (1877:18): [True: 0, False: 0]
  ------------------
 1878|      0|				strcmp((char *) newpin, (char *) newpin2) == 0) {
  ------------------
  |  Branch (1878:5): [True: 0, False: 0]
  ------------------
 1879|      0|			free(newpin2);
 1880|      0|			break;
 1881|      0|		}
 1882|      0|		printf("PIN codes do not match, try again.\n");
 1883|      0|		free(newpin);
 1884|      0|		free(newpin2);
 1885|      0|		newpin=NULL;
 1886|      0|	}
 1887|       |
 1888|    205|	r = sc_pkcs15_change_pin(p15card, pin_obj,
 1889|    205|			pincode, pincode ? strlen((char *) pincode) : 0,
  ------------------
  |  Branch (1889:13): [True: 205, False: 0]
  ------------------
 1890|    205|			newpin, newpin ? strlen((char *) newpin) : 0);
  ------------------
  |  Branch (1890:12): [True: 205, False: 0]
  ------------------
 1891|    205|	if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|    205|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1891:6): [True: 0, False: 205]
  ------------------
 1892|      0|		fprintf(stderr, "PIN code incorrect; tries left: %d\n", pinfo->tries_left);
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1893|      0|		return 3;
 1894|    205|	} else if (r) {
  ------------------
  |  Branch (1894:13): [True: 196, False: 9]
  ------------------
 1895|    196|		fprintf(stderr, "PIN code change failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|    196|#define stderr stdout
  ------------------
 1896|    196|		return 2;
 1897|    196|	}
 1898|      9|	if (verbose)
  ------------------
  |  Branch (1898:6): [True: 1, False: 8]
  ------------------
 1899|      1|		printf("PIN code changed successfully.\n");
 1900|       |
 1901|      9|	if (opt_pin == NULL)
  ------------------
  |  Branch (1901:6): [True: 0, False: 9]
  ------------------
 1902|      0|		free(pincode);
 1903|      9|	if (opt_newpin == NULL)
  ------------------
  |  Branch (1903:6): [True: 0, False: 9]
  ------------------
 1904|      0|		free(newpin);
 1905|       |
 1906|      9|	return 0;
 1907|    205|}
fuzz_pkcs15_tool.c:unblock_pin:
 1714|    341|{
 1715|    341|	struct sc_pkcs15_auth_info *pinfo = NULL;
 1716|    341|	sc_pkcs15_object_t *pin_obj;
 1717|    341|	u8 *pin, *puk;
 1718|    341|	int r, pinpad_present = 0;
 1719|       |
 1720|    341|	pinpad_present = p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    682|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1720:19): [True: 0, False: 341]
  ------------------
 1721|    341|	   	|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH;
  ------------------
  |  |  560|    682|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (1721:9): [True: 0, False: 341]
  ------------------
 1722|       |
 1723|    341|	if (!(pin_obj = get_pin_info()))
  ------------------
  |  Branch (1723:6): [True: 162, False: 179]
  ------------------
 1724|    162|		return 2;
 1725|    179|	pinfo = (sc_pkcs15_auth_info_t *) pin_obj->data;
 1726|       |
 1727|    179|	if (pinfo->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    179|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1727:6): [True: 0, False: 179]
  ------------------
 1728|      0|		return 1;
 1729|       |
 1730|    179|	puk = (u8 *) opt_puk;
 1731|    179|	if (puk == NULL) {
  ------------------
  |  Branch (1731:6): [True: 165, False: 14]
  ------------------
 1732|    165|		sc_pkcs15_object_t *puk_obj = NULL;
 1733|       |
 1734|    165|		if (pin_obj->auth_id.len)   {
  ------------------
  |  Branch (1734:7): [True: 83, False: 82]
  ------------------
 1735|     83|			r = sc_pkcs15_find_pin_by_auth_id(p15card, &pin_obj->auth_id, &puk_obj);
 1736|     83|			if (r < 0)   {
  ------------------
  |  Branch (1736:8): [True: 0, False: 83]
  ------------------
 1737|      0|				fprintf(stderr, "Failed to find PUK object for PIN: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1738|      0|				return 2;
 1739|      0|			}
 1740|     83|		}
 1741|       |
 1742|    165|		if (puk_obj)   {
  ------------------
  |  Branch (1742:7): [True: 83, False: 82]
  ------------------
 1743|     83|			struct sc_pkcs15_auth_info *puk_info = (sc_pkcs15_auth_info_t *) puk_obj->data;
 1744|       |
 1745|     83|			if (puk_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)    {
  ------------------
  |  |   94|     83|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1745:8): [True: 83, False: 0]
  ------------------
 1746|       |				/* TODO: Print PUK's label */
 1747|     83|				puk = get_pin("Enter PUK", puk_obj);
 1748|     83|				if (!pinpad_present && puk == NULL)
  ------------------
  |  Branch (1748:9): [True: 83, False: 0]
  |  Branch (1748:28): [True: 83, False: 0]
  ------------------
 1749|     83|					return 2;
 1750|     83|			}
 1751|     83|		}
 1752|     82|		else   {
 1753|     82|			puk = get_pin("Enter PUK", pin_obj);
 1754|     82|			if (!pinpad_present && puk == NULL)
  ------------------
  |  Branch (1754:8): [True: 82, False: 0]
  |  Branch (1754:27): [True: 82, False: 0]
  ------------------
 1755|     82|				return 2;
 1756|     82|		}
 1757|    165|	}
 1758|       |
 1759|     14|	if (puk == NULL && verbose)
  ------------------
  |  Branch (1759:6): [True: 0, False: 14]
  |  Branch (1759:21): [True: 0, False: 0]
  ------------------
 1760|      0|		printf("PUK value will be prompted with pinpad.\n");
 1761|       |
 1762|       |	/* FIXME should OPENSSL_cleanse on pin/puk data */
 1763|     14|	pin = opt_pin ? (u8 *) opt_pin : (u8 *) opt_newpin;
  ------------------
  |  Branch (1763:8): [True: 11, False: 3]
  ------------------
 1764|     14|	while (pin == NULL) {
  ------------------
  |  Branch (1764:9): [True: 1, False: 13]
  ------------------
 1765|      1|		u8 *pin2;
 1766|       |
 1767|      1|		pin = get_pin("Enter new PIN", pin_obj);
 1768|      1|		if (pinpad_present && pin == NULL)   {
  ------------------
  |  Branch (1768:7): [True: 0, False: 1]
  |  Branch (1768:25): [True: 0, False: 0]
  ------------------
 1769|      0|			if (verbose)
  ------------------
  |  Branch (1769:8): [True: 0, False: 0]
  ------------------
 1770|      0|				printf("New PIN value will be prompted with pinpad.\n");
 1771|      0|			break;
 1772|      0|		}
 1773|      1|		if (pin == NULL || strlen((char *) pin) == 0) {
  ------------------
  |  Branch (1773:7): [True: 1, False: 0]
  |  Branch (1773:22): [True: 0, False: 0]
  ------------------
 1774|      1|			free(pin);
 1775|      1|			return 2;
 1776|      1|		}
 1777|       |
 1778|      0|		pin2 = get_pin("Enter new PIN again", pin_obj);
 1779|      0|		if (pin2 == NULL || strlen((char *) pin2) == 0) {
  ------------------
  |  Branch (1779:7): [True: 0, False: 0]
  |  Branch (1779:23): [True: 0, False: 0]
  ------------------
 1780|      0|			free(pin);
 1781|      0|			free(pin2);
 1782|      0|			return 2;
 1783|      0|		}
 1784|      0|		if (strcmp((char *) pin, (char *) pin2) != 0) {
  ------------------
  |  Branch (1784:7): [True: 0, False: 0]
  ------------------
 1785|      0|			printf("PIN codes do not match, try again.\n");
 1786|      0|			free(pin);
 1787|      0|			pin = NULL;
 1788|      0|		}
 1789|      0|		free(pin2);
 1790|      0|	}
 1791|       |
 1792|     13|	r = sc_pkcs15_unblock_pin(p15card, pin_obj,
 1793|     13|			puk, puk ? strlen((char *) puk) : 0,
  ------------------
  |  Branch (1793:9): [True: 13, False: 0]
  ------------------
 1794|     13|			pin, pin ? strlen((char *) pin) : 0);
  ------------------
  |  Branch (1794:9): [True: 13, False: 0]
  ------------------
 1795|       |
 1796|     13|	if (NULL == opt_puk)
  ------------------
  |  Branch (1796:6): [True: 0, False: 13]
  ------------------
 1797|      0|		free(puk);
 1798|     13|	if (NULL == opt_pin && NULL == opt_newpin)
  ------------------
  |  Branch (1798:6): [True: 2, False: 11]
  |  Branch (1798:25): [True: 0, False: 2]
  ------------------
 1799|      0|		free(pin);
 1800|       |
 1801|     13|	if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     13|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1801:6): [True: 0, False: 13]
  ------------------
 1802|      0|		fprintf(stderr, "PUK code incorrect; tries left: %d\n", pinfo->tries_left);
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1803|      0|		return 3;
 1804|     13|	} else if (r) {
  ------------------
  |  Branch (1804:13): [True: 11, False: 2]
  ------------------
 1805|     11|		fprintf(stderr, "PIN unblocking failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|     11|#define stderr stdout
  ------------------
 1806|     11|		return 2;
 1807|     11|	}
 1808|      2|	if (verbose)
  ------------------
  |  Branch (1808:6): [True: 1, False: 1]
  ------------------
 1809|      1|		printf("PIN successfully unblocked.\n");
 1810|      2|	return 0;
 1811|     13|}
fuzz_pkcs15_tool.c:test_update:
 1910|    194|{
 1911|    194|	sc_apdu_t apdu;
 1912|    194|	static u8 cmd1[2] = { 0x50, 0x15};
 1913|    194|	u8 rbuf[258];
 1914|    194|	int rc;
 1915|    194|	int r;
 1916|    194|	static u8 fci_bad[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 1917|    194|	static u8 fci_good[] = { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00 };
 1918|       |
 1919|    194|	r = sc_lock(card);
 1920|    194|	if (r < 0)
  ------------------
  |  Branch (1920:6): [True: 0, False: 194]
  ------------------
 1921|      0|		return r;
 1922|       |
 1923|    194|	if (strcmp("cardos",in_card->driver->short_name) != 0) {
  ------------------
  |  Branch (1923:6): [True: 131, False: 63]
  ------------------
 1924|    131|		printf("not using the cardos driver, card is fine.\n");
 1925|    131|		rc = 0;
 1926|    131|		goto end;
 1927|    131|	}
 1928|       |
 1929|       |	/* first select file on 5015 and get fci */
 1930|     63|	sc_format_apdu(in_card, &apdu, SC_APDU_CASE_4_SHORT, 0xa4, 0x08, 0x00);
  ------------------
  |  |  294|     63|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1931|     63|	apdu.lc = sizeof(cmd1);
 1932|     63|	apdu.datalen = sizeof(cmd1);
 1933|     63|	apdu.data = cmd1;
 1934|     63|	apdu.le = 256;
 1935|     63|	apdu.resp = rbuf;
 1936|     63|	apdu.resplen = sizeof(rbuf);
 1937|       |
 1938|     63|	r = sc_transmit_apdu(card, &apdu);
 1939|     63|	if (r < 0) {
  ------------------
  |  Branch (1939:6): [True: 1, False: 62]
  ------------------
 1940|      1|		printf("selecting folder failed: %s\n", sc_strerror(r));
 1941|      1|		rc = 2;
 1942|      1|		goto end;
 1943|      1|	}
 1944|       |
 1945|     62|	if (apdu.sw1 != 0x90) {
  ------------------
  |  Branch (1945:6): [True: 23, False: 39]
  ------------------
 1946|     23|		printf("apdu command select file failed: card returned %02X %02X\n",
 1947|     23|			apdu.sw1, apdu.sw2);
 1948|     23|		rc = 2;
 1949|     23|		goto end;
 1950|       |
 1951|     23|	}
 1952|       |
 1953|     39|	if (apdu.resplen < 6) {
  ------------------
  |  Branch (1953:6): [True: 4, False: 35]
  ------------------
 1954|      4|		printf("select file did not return enough data (length %d)\n",
 1955|      4|			(int) apdu.resplen);
 1956|      4|		goto bad_fci;
 1957|      4|	}
 1958|       |
 1959|     35|	if (rbuf[0] != 0x6f) {
  ------------------
  |  Branch (1959:6): [True: 16, False: 19]
  ------------------
 1960|     16|		printf("select file did not return the information we need\n");
 1961|     16|		goto bad_fci;
 1962|     16|	}
 1963|       |
 1964|     19|	if (rbuf[1] != apdu.resplen -2) {
  ------------------
  |  Branch (1964:6): [True: 4, False: 15]
  ------------------
 1965|      4|		printf("select file returned inconsistent information\n");
 1966|      4|		goto bad_fci;
 1967|      4|	}
 1968|       |
 1969|     15|	{
 1970|     15|		size_t i=0;
 1971|    124|		while(i < rbuf[1]) {
  ------------------
  |  Branch (1971:9): [True: 124, False: 0]
  ------------------
 1972|    124|			if (rbuf[2+i] == 0x86) { /* found our buffer */
  ------------------
  |  Branch (1972:8): [True: 4, False: 120]
  ------------------
 1973|      4|				break;
 1974|      4|			}
 1975|       |			/* other tag */
 1976|    120|			i += 2 + rbuf[2+i+1]; /* length of this tag*/
 1977|    120|			if (2+i+1 >= apdu.resplen) {
  ------------------
  |  Branch (1977:8): [True: 11, False: 109]
  ------------------
 1978|     11|				break;
 1979|     11|			}
 1980|    120|		}
 1981|     15|		if (2+i+1 >= apdu.resplen || rbuf[2+i+1] < 9 || 2+i+2+9 > apdu.resplen) {
  ------------------
  |  Branch (1981:7): [True: 11, False: 4]
  |  Branch (1981:32): [True: 2, False: 2]
  |  Branch (1981:51): [True: 0, False: 2]
  ------------------
 1982|     13|			printf("select file returned short fci\n");
 1983|     13|			goto bad_fci;
 1984|     13|		}
 1985|       |
 1986|      2|		if (memcmp(&rbuf[2+i+2],fci_good,sizeof(fci_good)) == 0) {
  ------------------
  |  Branch (1986:7): [True: 0, False: 2]
  ------------------
 1987|      0|			printf("fci is up-to-date, card is fine\n");
 1988|      0|			rc = 0;
 1989|      0|			goto end;
 1990|      0|		}
 1991|       |
 1992|      2|		if (memcmp(&rbuf[2+i+2],fci_bad,sizeof(fci_bad)) == 0) {
  ------------------
  |  Branch (1992:7): [True: 0, False: 2]
  ------------------
 1993|      0|			printf("fci is out-of-date, card is vulnerable\n");
 1994|      0|			rc = 1;
 1995|      0|			goto end;
 1996|      0|		}
 1997|       |
 1998|      2|		printf("select file returned fci with unknown data\n");
 1999|      2|		goto bad_fci;
 2000|      2|	}
 2001|    155|end:
 2002|    155|	sc_unlock(card);
 2003|       |	/* 0 = card ok, 1 = card vulnerable, 2 = problem! */
 2004|    155|	return rc;
 2005|       |
 2006|     39|bad_fci:
 2007|     39|	sc_unlock(card);
 2008|       |	util_hex_dump(stdout,rbuf,apdu.resplen," ");
 2009|     39|	printf("\n");
 2010|     39|	return 2;
 2011|      2|}
fuzz_pkcs15_tool.c:test_session_pin:
 1385|    164|{
 1386|    164|	struct sc_pkcs15_object	*pin_obj = NULL;
 1387|    164|	struct sc_pkcs15_auth_info *auth_info = NULL;
 1388|    164|	unsigned int  auth_method;
 1389|    164|	unsigned char		*pin;
 1390|    164|	int r;
 1391|    164|	unsigned char sessionpin[SC_MAX_PIN_SIZE] = {0};
 1392|    164|	size_t sessionpinlen = sizeof sessionpin;
 1393|       |
 1394|    164|	if (!opt_auth_id)   {
  ------------------
  |  Branch (1394:6): [True: 103, False: 61]
  ------------------
 1395|    103|		struct sc_pkcs15_object *objs[32];
 1396|    103|		int ii;
 1397|       |
 1398|    103|		r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|    103|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
 1399|    103|		if (r < 0) {
  ------------------
  |  Branch (1399:7): [True: 0, False: 103]
  ------------------
 1400|      0|			fprintf(stderr, "PIN code enumeration failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1401|      0|			return -1;
 1402|      0|		}
 1403|       |
 1404|    103|		for (ii=0;ii<r;ii++)   {
  ------------------
  |  Branch (1404:13): [True: 97, False: 6]
  ------------------
 1405|     97|			struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
 1406|       |
 1407|     97|			if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|     97|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (1407:8): [True: 0, False: 97]
  ------------------
 1408|      0|				continue;
 1409|     97|			if (pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN)
  ------------------
  |  |   61|     97|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (1409:8): [True: 0, False: 97]
  ------------------
 1410|      0|				continue;
 1411|     97|			if (pin_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN)
  ------------------
  |  |   60|     97|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  |  Branch (1411:8): [True: 0, False: 97]
  ------------------
 1412|      0|				continue;
 1413|       |
 1414|     97|			pin_obj = objs[ii];
 1415|     97|			break;
 1416|     97|		}
 1417|    103|	}
 1418|     61|	else   {
 1419|     61|		pin_obj = get_pin_info();
 1420|     61|	}
 1421|       |
 1422|    164|	if (!(card->caps & SC_CARD_CAP_SESSION_PIN)) {
  ------------------
  |  |  563|    164|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (1422:6): [True: 164, False: 0]
  ------------------
 1423|    164|		fprintf(stderr, "Card does not support session PIN. Will try anyway.\n");
  ------------------
  |  |   39|    164|#define stderr stdout
  ------------------
 1424|    164|	}
 1425|       |
 1426|    164|	if (!pin_obj)   {
  ------------------
  |  Branch (1426:6): [True: 67, False: 97]
  ------------------
 1427|     67|		fprintf(stderr, "PIN object '%s' not found\n", opt_auth_id);
  ------------------
  |  |   39|     67|#define stderr stdout
  ------------------
 1428|     67|		return -1;
 1429|     67|	}
 1430|       |
 1431|     97|	if (opt_pin != NULL)
  ------------------
  |  Branch (1431:6): [True: 51, False: 46]
  ------------------
 1432|     51|		pin = (unsigned char *) opt_pin;
 1433|     46|	else
 1434|     46|		pin = get_pin("Please enter PIN", pin_obj);
 1435|       |
 1436|     97|	r = sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pin, pin ? strlen((char *) pin) : 0,
  ------------------
  |  Branch (1436:67): [True: 51, False: 46]
  ------------------
 1437|     97|			sessionpin, &sessionpinlen);
 1438|     97|	if (opt_pin == NULL)
  ------------------
  |  Branch (1438:6): [True: 46, False: 51]
  ------------------
 1439|     46|		free(pin);
 1440|     97|	if (r < 0)   {
  ------------------
  |  Branch (1440:6): [True: 86, False: 11]
  ------------------
 1441|     86|		fprintf(stderr, "Operation failed: %s\n", sc_strerror(r));
  ------------------
  |  |   39|     86|#define stderr stdout
  ------------------
 1442|     86|		return -1;
 1443|     86|	}
 1444|       |
 1445|     11|	if (!sessionpinlen)   {
  ------------------
  |  Branch (1445:6): [True: 11, False: 0]
  ------------------
 1446|     11|		fprintf(stderr, "Could not generate session PIN\n");
  ------------------
  |  |   39|     11|#define stderr stdout
  ------------------
 1447|     11|		return -1;
 1448|     11|	}
 1449|       |
 1450|      0|	printf("Generated session PIN (in hexadecimal form): ");
 1451|      0|	util_hex_dump(stdout, sessionpin, sessionpinlen, "");
 1452|      0|	puts("");
 1453|       |
 1454|      0|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
 1455|       |	/* save the pin type */
 1456|      0|	auth_method = auth_info->auth_method;
 1457|      0|	auth_info->auth_method = SC_AC_SESSION;
  ------------------
  |  |  159|      0|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
 1458|      0|	r = sc_pkcs15_verify_pin(p15card, pin_obj, sessionpin, sessionpinlen);
 1459|       |	/* restore the pin type */
 1460|      0|	auth_info->auth_method = auth_method;
 1461|      0|	if (r < 0)   {
  ------------------
  |  Branch (1461:6): [True: 0, False: 0]
  ------------------
 1462|      0|		fprintf(stderr, "Could not verify session PIN: %s\n", sc_strerror(r));
  ------------------
  |  |   39|      0|#define stderr stdout
  ------------------
 1463|      0|		return -1;
 1464|      0|	}
 1465|       |
 1466|      0|	puts("Verified session PIN");
 1467|       |
 1468|      0|	return 0;
 1469|      0|}

util_hex_dump:
  218|    197|{
  219|    197|	size_t i;
  220|       |
  221|  6.38k|	for (i = 0; i < len; i++) {
  ------------------
  |  Branch (221:14): [True: 6.18k, False: 197]
  ------------------
  222|  6.18k|		if (sep != NULL && i)
  ------------------
  |  Branch (222:7): [True: 6.18k, False: 0]
  |  Branch (222:22): [True: 5.99k, False: 197]
  ------------------
  223|  5.99k|			fprintf(f, "%s", sep);
  224|  6.18k|		fprintf(f, "%02X", in[i]);
  225|  6.18k|	}
  226|    197|}
util_print_usage:
  260|    293|{
  261|    293|	int i;
  262|    293|	int header_shown = 0;
  263|       |
  264|    293|	if (args)
  ------------------
  |  Branch (264:6): [True: 0, False: 293]
  ------------------
  265|      0|		printf("Usage: %s [OPTIONS] %s\n", app_name, args);
  266|    293|	else
  267|    293|		printf("Usage: %s [OPTIONS]\n", app_name);
  268|       |
  269|  10.8k|	for (i = 0; options[i].name; i++) {
  ------------------
  |  Branch (269:14): [True: 10.5k, False: 293]
  ------------------
  270|  10.5k|		char buf[40];
  271|  10.5k|		const char *arg_str;
  272|       |
  273|       |		/* Skip "hidden" options */
  274|  10.5k|		if (option_help[i] == NULL)
  ------------------
  |  Branch (274:7): [True: 293, False: 10.2k]
  ------------------
  275|    293|			continue;
  276|       |
  277|  10.2k|		if (!header_shown++)
  ------------------
  |  Branch (277:7): [True: 293, False: 9.96k]
  ------------------
  278|    293|			printf("Options:\n");
  279|       |
  280|  10.2k|		switch (options[i].has_arg) {
  281|  3.22k|		case 1:
  ------------------
  |  Branch (281:3): [True: 3.22k, False: 7.03k]
  ------------------
  282|  3.22k|			arg_str = " <arg>";
  283|  3.22k|			break;
  284|      0|		case 2:
  ------------------
  |  Branch (284:3): [True: 0, False: 10.2k]
  ------------------
  285|      0|			arg_str = " [arg]";
  286|      0|			break;
  287|  7.03k|		default:
  ------------------
  |  Branch (287:3): [True: 7.03k, False: 3.22k]
  ------------------
  288|  7.03k|			arg_str = "";
  289|  7.03k|			break;
  290|  10.2k|		}
  291|  10.2k|		if (isascii(options[i].val) &&
  ------------------
  |  Branch (291:7): [True: 3.80k, False: 6.44k]
  ------------------
  292|  10.2k|		    isprint(options[i].val) && !isspace(options[i].val))
  ------------------
  |  Branch (292:7): [True: 3.80k, False: 0]
  |  Branch (292:34): [True: 3.80k, False: 0]
  ------------------
  293|  3.80k|			sprintf(buf, "-%c, --%s%s", options[i].val, options[i].name, arg_str);
  294|  6.44k|		else
  295|  6.44k|			sprintf(buf, "    --%s%s", options[i].name, arg_str);
  296|       |
  297|       |		/* print the line - wrap if necessary */
  298|  10.2k|		if (strlen(buf) > 28) {
  ------------------
  |  Branch (298:7): [True: 0, False: 10.2k]
  ------------------
  299|      0|			printf("  %s\n", buf);
  300|      0|			buf[0] = '\0';
  301|      0|		}
  302|  10.2k|		printf("  %-28s  %s\n", buf, option_help[i]);
  303|  10.2k|	}
  304|    293|}
util_getpass:
  438|    273|{
  439|    273|#define MAX_PASS_SIZE	128
  440|    273|	char *buf;
  441|    273|	size_t i;
  442|    273|	int ch = 0;
  443|    273|#ifndef _WIN32
  444|    273|	struct termios old, new;
  445|       |
  446|    273|	fflush(stdout);
  447|    273|	if (tcgetattr (fileno (stdout), &old) != 0)
  ------------------
  |  Branch (447:6): [True: 273, False: 0]
  ------------------
  448|    273|		return -1;
  449|      0|	new = old;
  450|      0|	new.c_lflag &= ~ECHO;
  451|      0|	if (tcsetattr (fileno (stdout), TCSAFLUSH, &new) != 0)
  ------------------
  |  Branch (451:6): [True: 0, False: 0]
  ------------------
  452|      0|		return -1;
  453|      0|#endif
  454|       |
  455|      0|	buf = calloc(1, MAX_PASS_SIZE);
  ------------------
  |  |  439|      0|#define MAX_PASS_SIZE	128
  ------------------
  456|      0|	if (!buf)
  ------------------
  |  Branch (456:6): [True: 0, False: 0]
  ------------------
  457|      0|		return -1;
  458|       |
  459|      0|	for (i = 0; i < MAX_PASS_SIZE - 1; i++) {
  ------------------
  |  |  439|      0|#define MAX_PASS_SIZE	128
  ------------------
  |  Branch (459:14): [True: 0, False: 0]
  ------------------
  460|      0|#ifndef _WIN32
  461|      0|		ch = getchar();
  462|       |#else
  463|       |		ch = _getch();
  464|       |#endif
  465|      0|		if (ch == 0 || ch == 3)
  ------------------
  |  Branch (465:7): [True: 0, False: 0]
  |  Branch (465:18): [True: 0, False: 0]
  ------------------
  466|      0|			break;
  467|      0|		if (ch == '\n' || ch == '\r')
  ------------------
  |  Branch (467:7): [True: 0, False: 0]
  |  Branch (467:21): [True: 0, False: 0]
  ------------------
  468|      0|			break;
  469|       |
  470|      0|		buf[i] = (char) ch;
  471|      0|	}
  472|      0|#ifndef _WIN32
  473|      0|	tcsetattr (fileno (stdout), TCSAFLUSH, &old);
  474|      0|	fputs("\n", stdout);
  475|      0|#endif
  476|      0|	if (ch == 0 || ch == 3) {
  ------------------
  |  Branch (476:6): [True: 0, False: 0]
  |  Branch (476:17): [True: 0, False: 0]
  ------------------
  477|      0|		free(buf);
  478|      0|		return -1;
  479|      0|	}
  480|       |
  481|      0|	if (*lineptr && (!len || *len < i+1)) {
  ------------------
  |  Branch (481:6): [True: 0, False: 0]
  |  Branch (481:19): [True: 0, False: 0]
  |  Branch (481:27): [True: 0, False: 0]
  ------------------
  482|      0|		free(*lineptr);
  483|      0|		*lineptr = NULL;
  484|      0|	}
  485|       |
  486|      0|	if (*lineptr) {
  ------------------
  |  Branch (486:6): [True: 0, False: 0]
  ------------------
  487|      0|		memcpy(*lineptr,buf,i+1);
  488|      0|		memset(buf, 0, MAX_PASS_SIZE);
  ------------------
  |  |  439|      0|#define MAX_PASS_SIZE	128
  ------------------
  489|      0|		free(buf);
  490|      0|	} else {
  491|      0|		*lineptr = buf;
  492|      0|		if (len)
  ------------------
  |  Branch (492:7): [True: 0, False: 0]
  ------------------
  493|      0|			*len = MAX_PASS_SIZE;
  ------------------
  |  |  439|      0|#define MAX_PASS_SIZE	128
  ------------------
  494|      0|	}
  495|      0|	return (int)i;
  496|      0|}
util_get_pin:
  500|  11.2k|{
  501|  11.2k|	size_t inputlen;
  502|  11.2k|	size_t pinlen = 0;
  503|       |
  504|  11.2k|	if (!input || !pin) {
  ------------------
  |  Branch (504:6): [True: 0, False: 11.2k]
  |  Branch (504:16): [True: 0, False: 11.2k]
  ------------------
  505|      0|		return 0;
  506|      0|	}
  507|  11.2k|	inputlen = strlen(input);
  508|       |
  509|  11.2k|	if (inputlen > 4 && strncasecmp(input, "env:", 4) == 0) {
  ------------------
  |  Branch (509:6): [True: 9.32k, False: 1.93k]
  |  Branch (509:22): [True: 4.73k, False: 4.59k]
  ------------------
  510|       |		// Get a PIN from a environment variable
  511|  4.73k|		*pin = getenv(input + 4);
  512|  4.73k|		pinlen = *pin ? strlen(*pin) : 0;
  ------------------
  |  Branch (512:12): [True: 727, False: 4.01k]
  ------------------
  513|  6.52k|	} else if (inputlen > 5 && strncasecmp(input, "file:", 5) == 0) {
  ------------------
  |  Branch (513:13): [True: 3.46k, False: 3.06k]
  |  Branch (513:29): [True: 194, False: 3.27k]
  ------------------
  514|    194|		fprintf(stderr, "Reading PIN from file not supported!\n");
  515|  6.33k|	} else {
  516|       |		//Just use the input
  517|  6.33k|		*pin = input;
  518|  6.33k|		pinlen = inputlen;
  519|  6.33k|	}
  520|  11.2k|	return pinlen;
  521|  11.2k|}

sc_notify_id:
  528|    193|		struct sc_pkcs15_card *p15card, enum ui_str id) {}

