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

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

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

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

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

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

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

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

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

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

sc_get_asepcos_driver:
 1086|  16.9k|{
 1087|  16.9k|	return sc_get_driver();
 1088|  16.9k|}
card-asepcos.c:sc_get_driver:
 1064|  16.9k|{
 1065|  16.9k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1065:6): [True: 1, False: 16.9k]
  ------------------
 1066|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1067|  16.9k|	asepcos_ops = *iso_ops;
 1068|  16.9k|	asepcos_ops.match_card        = asepcos_match_card;
 1069|  16.9k|	asepcos_ops.init              = asepcos_init;
 1070|  16.9k|	asepcos_ops.select_file       = asepcos_select_file;
 1071|  16.9k|	asepcos_ops.set_security_env  = asepcos_set_security_env;
 1072|  16.9k|	asepcos_ops.decipher          = asepcos_decipher;
 1073|  16.9k|	asepcos_ops.compute_signature = asepcos_compute_signature;
 1074|  16.9k|	asepcos_ops.create_file       = asepcos_create_file;
 1075|  16.9k|	asepcos_ops.delete_file       = asepcos_delete_file;
 1076|  16.9k|	asepcos_ops.list_files        = asepcos_list_files;
 1077|  16.9k|	asepcos_ops.card_ctl          = asepcos_card_ctl;
 1078|  16.9k|	asepcos_ops.pin_cmd           = asepcos_pin_cmd;
 1079|  16.9k|	asepcos_ops.logout            = asepcos_logout;
 1080|  16.9k|	asepcos_ops.card_reader_lock_obtained = asepcos_card_reader_lock_obtained;
 1081|       |
 1082|  16.9k|	return &asepcos_drv;
 1083|  16.9k|}
card-asepcos.c:asepcos_match_card:
   47|  16.9k|{
   48|  16.9k|	int i = _sc_match_atr(card, asepcos_atrs, &card->type);
   49|  16.9k|	if (i < 0)
  ------------------
  |  Branch (49:6): [True: 16.7k, False: 164]
  ------------------
   50|  16.7k|		return 0;
   51|    164|	return 1;
   52|  16.9k|}
card-asepcos.c:asepcos_init:
   76|    164|{
   77|    164|	unsigned long	flags;
   78|       |
   79|    164|	card->name = "Athena ASEPCOS";
   80|    164|	card->cla  = 0x00;
   81|       |
   82|       |	/* in case of a Java card try to select the ASEPCOS applet */
   83|    164|	if (card->type == SC_CARD_TYPE_ASEPCOS_JAVA) {
  ------------------
  |  Branch (83:6): [True: 0, False: 164]
  ------------------
   84|      0|		int r = asepcos_select_asepcos_applet(card);
   85|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (85:7): [True: 0, False: 0]
  ------------------
   86|      0|			return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
   87|      0|	}
   88|       |
   89|       |	/* Set up algorithm info. */
   90|    164|	flags =	SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    164|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   91|    164|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|    164|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   92|    164|		| SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|    164|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
   93|    164|		;
   94|    164|	_sc_card_add_rsa_alg(card,  512, flags, 0);
   95|    164|	_sc_card_add_rsa_alg(card,  768, flags, 0);
   96|    164|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
   97|    164|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
   98|    164|	_sc_card_add_rsa_alg(card, 1792, flags, 0);
   99|    164|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  100|       |
  101|    164|	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  547|    164|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    164|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  102|       |
  103|    164|	return SC_SUCCESS;
  ------------------
  |  |   28|    164|#define SC_SUCCESS				0
  ------------------
  104|    164|}
card-asepcos.c:asepcos_select_file:
  274|    839|{
  275|    839|	int       r;
  276|    839|	sc_path_t npath = *in_path;
  277|       |
  278|    839|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    839|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    839|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    839|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    839|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 839]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    839|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|    839|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (280:6): [True: 511, False: 328]
  ------------------
  281|       |		/* check the current DF to avoid unnecessary re-selection of
  282|       |		 * the MF (as this might invalidate a security status) */
  283|    511|		sc_path_t tpath;
  284|    511|		memset(&tpath, 0, sizeof tpath);
  285|       |
  286|    511|		r = asepcos_get_current_df_path(card, &tpath);
  287|       |		/* workaround: as opensc can't handle paths with file id
  288|       |		 * and application names in it let's ignore the current
  289|       |		 * DF if the returned path contains a unsupported tag.
  290|       |		 */
  291|    511|		if (r != SC_ERROR_INVALID_ASN1_OBJECT && r != SC_SUCCESS)
  ------------------
  |  |   82|  1.02k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
              		if (r != SC_ERROR_INVALID_ASN1_OBJECT && r != SC_SUCCESS)
  ------------------
  |  |   28|    416|#define SC_SUCCESS				0
  ------------------
  |  Branch (291:7): [True: 416, False: 95]
  |  Branch (291:44): [True: 328, False: 88]
  ------------------
  292|    328|			return r;
  293|    183|		if (r == SC_SUCCESS && sc_compare_path_prefix(&tpath, &npath) != 0) {
  ------------------
  |  |   28|    366|#define SC_SUCCESS				0
  ------------------
  |  Branch (293:7): [True: 88, False: 95]
  |  Branch (293:26): [True: 73, False: 15]
  ------------------
  294|       |			/* remove the currently selected DF from the path */
  295|     73|			if (tpath.len == npath.len) {
  ------------------
  |  Branch (295:8): [True: 0, False: 73]
  ------------------
  296|       |				/* we are already in the requested DF */
  297|      0|				if (file == NULL)
  ------------------
  |  Branch (297:9): [True: 0, False: 0]
  ------------------
  298|       |					/* no file information requested =>
  299|       |					 * nothing to do */
  300|      0|					return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  301|     73|			} else {
  302|       |				/* shorten path */
  303|     73|				r = sc_path_set(&npath, 0, &in_path->value[tpath.len],
  304|     73|						npath.len - tpath.len, 0, 0);
  305|     73|				if (r != SC_SUCCESS)
  ------------------
  |  |   28|     73|#define SC_SUCCESS				0
  ------------------
  |  Branch (305:9): [True: 0, False: 73]
  ------------------
  306|      0|					return r;
  307|     73|				if (npath.len == 2)
  ------------------
  |  Branch (307:9): [True: 6, False: 67]
  ------------------
  308|      6|					npath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      6|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  309|     67|				else
  310|     67|					npath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     67|#define SC_PATH_TYPE_PATH		2
  ------------------
  311|     73|			}
  312|     73|		}
  313|    183|	}
  314|       |
  315|    511|	r = iso_ops->select_file(card, &npath, file);
  316|       |	/* XXX: this doesn't look right */
  317|    511|	if (file != NULL && *file != NULL)
  ------------------
  |  Branch (317:6): [True: 158, False: 353]
  |  Branch (317:22): [True: 100, False: 58]
  ------------------
  318|    100|		if ((*file)->ef_structure == SC_FILE_EF_UNKNOWN)
  ------------------
  |  |  220|    100|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  |  Branch (318:7): [True: 76, False: 24]
  ------------------
  319|     76|			(*file)->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     76|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    511|	if (r == SC_SUCCESS && file != NULL && *file != NULL) {
  ------------------
  |  |   28|  1.02k|#define SC_SUCCESS				0
  ------------------
  |  Branch (320:6): [True: 150, False: 361]
  |  Branch (320:25): [True: 100, False: 50]
  |  Branch (320:41): [True: 100, False: 0]
  ------------------
  321|    100|		r = asepcos_parse_sec_attr(card, *file, (*file)->sec_attr, (*file)->sec_attr_len);
  322|    100|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|    100|#define SC_SUCCESS				0
  ------------------
  |  Branch (322:7): [True: 73, False: 27]
  ------------------
  323|     73|			sc_log(card->ctx,  "error parsing security attributes");
  ------------------
  |  |   71|     73|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  324|    100|	}
  325|    511|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    511|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    511|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    511|	int _ret = r; \
  |  |  |  |  155|    511|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 511, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    511|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    434|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 434, False: 77]
  |  |  |  |  ------------------
  |  |  |  |  157|    511|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    511|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    511|	return _ret; \
  |  |  |  |  163|    511|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  326|    511|}
card-asepcos.c:asepcos_get_current_df_path:
  252|    511|{
  253|    511|	int r;
  254|    511|	sc_apdu_t apdu;
  255|    511|	u8        rbuf[SC_MAX_APDU_BUFFER_SIZE];
  256|       |
  257|    511|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x83);
  ------------------
  |  |  292|    511|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  258|    511|	apdu.resp    = rbuf;
  259|    511|	apdu.resplen = sizeof(rbuf);
  260|    511|	apdu.le      = 256;
  261|       |
  262|    511|	r = sc_transmit_apdu(card, &apdu);
  263|    511|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    511|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    511|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    511|	int _ret = (r); \
  |  |  |  |  168|    511|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 498]
  |  |  |  |  ------------------
  |  |  |  |  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|    511|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 498]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  264|    498|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (264:6): [True: 275, False: 223]
  |  Branch (264:26): [True: 23, False: 200]
  ------------------
  265|    298|		return sc_check_sw(card, apdu.sw1, apdu.sw2);
  266|    200|	return asepcos_tlvpath_to_scpath(path, apdu.resp, apdu.resplen);
  267|    498|}
card-asepcos.c:asepcos_tlvpath_to_scpath:
  221|    200|{
  222|    200|	int    r;
  223|    200|	size_t len = in_len;
  224|       |
  225|    200|	memset(out, 0, sizeof(sc_path_t));
  226|       |
  227|    236|	while (len != 0) {
  ------------------
  |  Branch (227:9): [True: 148, False: 88]
  ------------------
  228|    148|		if (len < 4)
  ------------------
  |  Branch (228:7): [True: 16, False: 132]
  ------------------
  229|     16|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     16|#define SC_ERROR_INTERNAL			-1400
  ------------------
  230|    132|		if (in[0] != 0x8b || in[1] != 0x02)
  ------------------
  |  Branch (230:7): [True: 89, False: 43]
  |  Branch (230:24): [True: 6, False: 37]
  ------------------
  231|     95|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     95|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  232|       |		/* append file id to the path */
  233|     37|		r = sc_append_path_id(out, &in[2], 2);
  234|     37|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|     37|#define SC_SUCCESS				0
  ------------------
  |  Branch (234:7): [True: 1, False: 36]
  ------------------
  235|      1|			return r;
  236|     36|		len -= 4;
  237|     36|		in  += 4;
  238|     36|	}
  239|     88|	out->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     88|#define SC_PATH_TYPE_PATH		2
  ------------------
  240|       |
  241|     88|	return SC_SUCCESS;
  ------------------
  |  |   28|     88|#define SC_SUCCESS				0
  ------------------
  242|    200|}
card-asepcos.c:asepcos_parse_sec_attr:
  167|    100|{
  168|    100|	const u8 *p = buf;
  169|       |
  170|    130|	while (len > 0) {
  ------------------
  |  Branch (170:9): [True: 103, False: 27]
  ------------------
  171|    103|		unsigned int amode, tlen = 3;
  172|    103|		if (len < 5 || p[0] != 0x80 || p[1] != 0x01) {
  ------------------
  |  Branch (172:7): [True: 13, False: 90]
  |  Branch (172:18): [True: 16, False: 74]
  |  Branch (172:34): [True: 5, False: 69]
  ------------------
  173|     34|			sc_log(card->ctx,  "invalid access mode encoding");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  174|     34|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     34|#define SC_ERROR_INTERNAL			-1400
  ------------------
  175|     34|		}
  176|     69|		amode = p[2];
  177|     69|		if (p[3] == 0x90 && p[4] == 0x00) {
  ------------------
  |  Branch (177:7): [True: 15, False: 54]
  |  Branch (177:23): [True: 12, False: 3]
  ------------------
  178|     12|			int r = set_sec_attr(file, amode, 0, SC_AC_NONE);
  ------------------
  |  |  150|     12|#define SC_AC_NONE			0x00000000
  ------------------
  179|     12|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  |  Branch (179:8): [True: 3, False: 9]
  ------------------
  180|      3|				return r;
  181|      9|			tlen += 2;
  182|     57|		} else if (p[3] == 0x97 && p[4] == 0x00) {
  ------------------
  |  Branch (182:14): [True: 7, False: 50]
  |  Branch (182:30): [True: 5, False: 2]
  ------------------
  183|      5|			int r = set_sec_attr(file, amode, 0, SC_AC_NEVER);
  ------------------
  |  |  163|      5|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  184|      5|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
  |  Branch (184:8): [True: 1, False: 4]
  ------------------
  185|      1|				return r;
  186|      4|			tlen += 2;
  187|     52|		} else if (p[3] == 0xA0 && len >= 5U + p[4]) {
  ------------------
  |  Branch (187:14): [True: 16, False: 36]
  |  Branch (187:30): [True: 13, False: 3]
  ------------------
  188|     13|			if (len < 6) {
  ------------------
  |  Branch (188:8): [True: 1, False: 12]
  ------------------
  189|      1|				sc_log(card->ctx,  "invalid access mode encoding");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  190|      1|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
  191|      1|			}
  192|       |			/* TODO: support OR expressions */
  193|     12|			int r = set_sec_attr(file, amode, p[5], SC_AC_CHV);
  ------------------
  |  |  151|     12|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  194|     12|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  |  Branch (194:8): [True: 9, False: 3]
  ------------------
  195|      9|				return r;
  196|      3|			tlen += 2 + p[4]; /* FIXME */
  197|     39|		} else if (p[3] == 0xAF && len >= 5U + p[4]) {
  ------------------
  |  Branch (197:14): [True: 21, False: 18]
  |  Branch (197:30): [True: 18, False: 3]
  ------------------
  198|     18|			if (len < 6) {
  ------------------
  |  Branch (198:8): [True: 1, False: 17]
  ------------------
  199|      1|				sc_log(card->ctx,  "invalid access mode encoding");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  200|      1|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
  201|      1|			}
  202|       |			/* TODO: support AND expressions */
  203|     17|			int r = set_sec_attr(file, amode, p[5], SC_AC_CHV);
  ------------------
  |  |  151|     17|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  204|     17|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (204:8): [True: 3, False: 14]
  ------------------
  205|      3|				return r;
  206|     14|			tlen += 2 + p[4];	/* FIXME */
  207|     21|		} else {
  208|     21|			sc_log(card->ctx,  "invalid security condition");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  209|     21|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     21|#define SC_ERROR_INTERNAL			-1400
  ------------------
  210|     21|		}
  211|     30|		p   += tlen;
  212|     30|		len -= tlen;
  213|     30|	}
  214|       |
  215|     27|	return SC_SUCCESS;
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
  216|    100|}
card-asepcos.c:set_sec_attr:
  140|     46|{
  141|     46|	const amode_entry_t *table;
  142|       |
  143|       |        /* CHV with reference '0' is the transport PIN
  144|       |	 * and is presented as 'AUT' key with reference '0'*/
  145|     46|	if (meth == SC_AC_CHV && ac == 0)
  ------------------
  |  |  151|     92|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (145:6): [True: 29, False: 17]
  |  Branch (145:27): [True: 7, False: 22]
  ------------------
  146|      7|		meth = SC_AC_AUT;
  ------------------
  |  |  154|      7|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  147|       |
  148|     46|	if (file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|     46|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (148:6): [True: 21, False: 25]
  ------------------
  149|     21|		table = df_amode_table;
  150|     25|	else if (file->type == SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|     25|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (150:11): [True: 4, False: 21]
  ------------------
  151|      4|		table = wef_amode_table;
  152|     21|	else if (file->type == SC_FILE_TYPE_INTERNAL_EF)
  ------------------
  |  |  215|     21|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (152:11): [True: 5, False: 16]
  ------------------
  153|      5|		table = ief_amode_table;
  154|     16|	else
  155|     16|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     16|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  156|    178|	for (; table->am != 0; table++) {
  ------------------
  |  Branch (156:9): [True: 148, False: 30]
  ------------------
  157|    148|		if (table->am & am)
  ------------------
  |  Branch (157:7): [True: 100, False: 48]
  ------------------
  158|    100|			sc_file_add_acl_entry(file, table->sc, meth, ac);
  159|    148|	}
  160|     30|	return SC_SUCCESS;
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  161|     46|}
card-asepcos.c:asepcos_card_ctl:
  838|     13|{
  839|     13|	switch (cmd) {
  ------------------
  |  Branch (839:10): [True: 13, False: 0]
  ------------------
  840|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (840:2): [True: 0, False: 13]
  ------------------
  841|      0|		return asepcos_get_default_key(card, (struct sc_cardctl_default_key *) ptr);
  842|     13|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (842:2): [True: 13, False: 0]
  ------------------
  843|     13|		return asepcos_get_serialnr(card, (sc_serial_number_t *)ptr);
  844|      0|	case SC_CARDCTL_ASEPCOS_CHANGE_KEY:
  ------------------
  |  Branch (844:2): [True: 0, False: 13]
  ------------------
  845|      0|		return asepcos_change_key(card, (sc_cardctl_asepcos_change_key_t*)ptr);
  846|      0|	case SC_CARDCTL_ASEPCOS_AKN2FILEID:
  ------------------
  |  Branch (846:2): [True: 0, False: 13]
  ------------------
  847|      0|		return asepcos_akn_to_fileid(card, (sc_cardctl_asepcos_akn2fileid_t*)ptr);
  848|      0|	case SC_CARDCTL_ASEPCOS_SET_SATTR:
  ------------------
  |  Branch (848:2): [True: 0, False: 13]
  ------------------
  849|      0|		return asepcos_set_security_attributes(card, (sc_file_t*)ptr);
  850|      0|	case SC_CARDCTL_ASEPCOS_ACTIVATE_FILE:
  ------------------
  |  Branch (850:2): [True: 0, False: 13]
  ------------------
  851|      0|		return asepcos_activate_file(card, ((sc_cardctl_asepcos_activate_file_t*)ptr)->fileid,
  852|      0|		                           ((sc_cardctl_asepcos_activate_file_t *)ptr)->is_ef);
  853|     13|	}
  854|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  855|     13|}
card-asepcos.c:asepcos_get_serialnr:
  792|     13|{
  793|     13|	int r;
  794|     13|	sc_apdu_t apdu;
  795|     13|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
  796|       |
  797|     13|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x14);
  ------------------
  |  |  292|     13|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  798|     13|	apdu.resp = rbuf;
  799|     13|	apdu.resplen = sizeof(rbuf);
  800|     13|	apdu.le   = 256;
  801|     13|	r = sc_transmit_apdu(card, &apdu);
  802|     13|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  803|     12|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (803:6): [True: 4, False: 8]
  |  Branch (803:26): [True: 3, False: 5]
  ------------------
  804|      7|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
  805|      5|	if (apdu.resplen != 8) {
  ------------------
  |  Branch (805:6): [True: 4, False: 1]
  ------------------
  806|      4|		sc_log(card->ctx,  "unexpected response to GET DATA serial number\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__
  |  |  ------------------
  ------------------
  807|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
  808|      4|	}
  809|       |	/* cache serial number */
  810|      1|	memcpy(card->serialnr.value, rbuf, 8);
  811|      1|	card->serialnr.len = 8;
  812|       |	/* copy and return serial number */
  813|      1|	memcpy(serial, &card->serialnr, sizeof(*serial));
  814|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  815|      5|}
card-asepcos.c:asepcos_pin_cmd:
  933|     10|{
  934|     10|	sc_apdu_t apdu;
  935|     10|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  936|     10|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
  937|       |
  938|       |	/* only PIN verification is supported at the moment  */
  939|       |
  940|       |	/* check PIN length */
  941|     10|	if (pdata->pin1.len < 4 || pdata->pin1.len > 16) {
  ------------------
  |  Branch (941:6): [True: 10, False: 0]
  |  Branch (941:29): [True: 0, False: 0]
  ------------------
  942|     10|		sc_log(card->ctx,  "invalid PIN1 length");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  943|     10|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     10|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  944|     10|	}
  945|       |
  946|      0|	switch (pdata->cmd) {
  947|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (947:2): [True: 0, False: 0]
  ------------------
  948|      0|		if (pdata->pin_type != SC_AC_CHV && pdata->pin_type != SC_AC_AUT)
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
              		if (pdata->pin_type != SC_AC_CHV && pdata->pin_type != SC_AC_AUT)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (948:7): [True: 0, False: 0]
  |  Branch (948:39): [True: 0, False: 0]
  ------------------
  949|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  950|       |		/* 'AUT' key is the transport PIN and should have reference '0' */
  951|      0|		if (pdata->pin_type == SC_AC_AUT && pdata->pin_reference)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (951:7): [True: 0, False: 0]
  |  Branch (951:39): [True: 0, False: 0]
  ------------------
  952|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  953|       |		/* build verify APDU and send it to the card */
  954|      0|		r = asepcos_build_pin_apdu(card, &apdu, pdata, sbuf, sizeof(sbuf), SC_PIN_CMD_VERIFY, 0);
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  955|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (955:7): [True: 0, False: 0]
  ------------------
  956|      0|			break;
  957|      0|		r = sc_transmit_apdu(card, &apdu);
  958|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (958:7): [True: 0, False: 0]
  ------------------
  959|      0|			sc_log(card->ctx,  "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__
  |  |  ------------------
  ------------------
  960|      0|		break;
  961|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (961:2): [True: 0, False: 0]
  ------------------
  962|      0|		if (pdata->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (962:7): [True: 0, False: 0]
  ------------------
  963|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  964|      0|		if (pdata->pin2.len < 4 || pdata->pin2.len > 16) {
  ------------------
  |  Branch (964:7): [True: 0, False: 0]
  |  Branch (964:30): [True: 0, False: 0]
  ------------------
  965|      0|			sc_log(card->ctx,  "invalid PIN2 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__
  |  |  ------------------
  ------------------
  966|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  967|      0|		}
  968|       |		/* 1. step: verify the old pin */
  969|      0|		r = asepcos_build_pin_apdu(card, &apdu, pdata, sbuf, sizeof(sbuf), SC_PIN_CMD_VERIFY, 0);
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  970|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (970:7): [True: 0, False: 0]
  ------------------
  971|      0|			break;
  972|      0|		r = sc_transmit_apdu(card, &apdu);
  973|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (973:7): [True: 0, False: 0]
  ------------------
  974|      0|			sc_log(card->ctx,  "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__
  |  |  ------------------
  ------------------
  975|      0|			break;
  976|      0|		}
  977|      0|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00) {
  ------------------
  |  Branch (977:7): [True: 0, False: 0]
  |  Branch (977:27): [True: 0, False: 0]
  ------------------
  978|       |			/* unable to verify the old PIN */
  979|      0|			break;
  980|      0|		}
  981|       |		/* 2, step: use CHANGE KEY to update the PIN */
  982|      0|		r = asepcos_build_pin_apdu(card, &apdu, pdata, sbuf, sizeof(sbuf), SC_PIN_CMD_CHANGE, 0);
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  983|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (983:7): [True: 0, False: 0]
  ------------------
  984|      0|			break;
  985|      0|		r = sc_transmit_apdu(card, &apdu);
  986|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (986:7): [True: 0, False: 0]
  ------------------
  987|      0|			sc_log(card->ctx,  "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__
  |  |  ------------------
  ------------------
  988|      0|		break;
  989|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (989:2): [True: 0, False: 0]
  ------------------
  990|      0|		if (pdata->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (990:7): [True: 0, False: 0]
  ------------------
  991|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  992|      0|		if (pdata->pin2.len < 4 || pdata->pin2.len > 16) {
  ------------------
  |  Branch (992:7): [True: 0, False: 0]
  |  Branch (992:30): [True: 0, False: 0]
  ------------------
  993|      0|			sc_log(card->ctx,  "invalid PIN2 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__
  |  |  ------------------
  ------------------
  994|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  995|      0|		}
  996|       |		/* 1. step: verify the puk */
  997|      0|		r = asepcos_build_pin_apdu(card, &apdu, pdata, sbuf, sizeof(sbuf), SC_PIN_CMD_VERIFY, 1);
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  998|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (998:7): [True: 0, False: 0]
  ------------------
  999|      0|			break;
 1000|      0|		r = sc_transmit_apdu(card, &apdu);
 1001|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1001:7): [True: 0, False: 0]
  ------------------
 1002|      0|			sc_log(card->ctx,  "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__
  |  |  ------------------
  ------------------
 1003|      0|			break;
 1004|      0|		}
 1005|       |		/* 2, step: unblock and change the pin */
 1006|      0|		r = asepcos_build_pin_apdu(card, &apdu, pdata, sbuf, sizeof(sbuf), SC_PIN_CMD_UNBLOCK, 0);
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
 1007|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1007:7): [True: 0, False: 0]
  ------------------
 1008|      0|			break;
 1009|      0|		r = sc_transmit_apdu(card, &apdu);
 1010|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1010:7): [True: 0, False: 0]
  ------------------
 1011|      0|			sc_log(card->ctx,  "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__
  |  |  ------------------
  ------------------
 1012|      0|			break;
 1013|      0|		}
 1014|      0|		break;
 1015|      0|	default:
  ------------------
  |  Branch (1015:2): [True: 0, False: 0]
  ------------------
 1016|      0|		sc_log(card->ctx,  "error: unknown cmd 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__
  |  |  ------------------
  ------------------
 1017|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1018|      0|	}
 1019|       |	/* Clear the buffer - it may contain pins */
 1020|      0|	sc_mem_clear(sbuf, sizeof(sbuf));
 1021|       |	/* check for remaining tries if verification failed */
 1022|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1022:6): [True: 0, False: 0]
  ------------------
 1023|      0|		if (apdu.sw1 == 0x63) {
  ------------------
  |  Branch (1023:7): [True: 0, False: 0]
  ------------------
 1024|      0|			if ((apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1024:8): [True: 0, False: 0]
  ------------------
 1025|      0|				pdata->pin1.tries_left = apdu.sw2 & 0x0F;
 1026|      0|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 1027|      0|			return r;
 1028|      0|		}
 1029|      0|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1030|      0|	}
 1031|       |
 1032|      0|	return r;
 1033|      0|}
card-asepcos.c:asepcos_card_reader_lock_obtained:
 1036|    164|{
 1037|    164|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    164|#define SC_SUCCESS				0
  ------------------
 1038|       |
 1039|    164|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    164|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    164|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    164|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 164]
  |  |  ------------------
  ------------------
 1040|       |
 1041|    164|	if (was_reset > 0 && card->type == SC_CARD_TYPE_ASEPCOS_JAVA) {
  ------------------
  |  Branch (1041:6): [True: 0, False: 164]
  |  Branch (1041:23): [True: 0, False: 0]
  ------------------
 1042|       |		/* in case of a Java card try to select the ASEPCOS applet */
 1043|      0|		r = asepcos_select_asepcos_applet(card);
 1044|      0|	}
 1045|       |
 1046|    164|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    164|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    164|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    164|	int _ret = r; \
  |  |  |  |  155|    164|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 164, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    164|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  157|    164|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    164|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    164|	return _ret; \
  |  |  |  |  163|    164|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1047|    164|}

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

sc_get_authentic_driver:
 2155|  16.9k|{
 2156|  16.9k|	return sc_get_driver();
 2157|  16.9k|}
card-authentic.c:sc_get_driver:
 2120|  16.9k|{
 2121|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2122|       |
 2123|  16.9k|	if (!iso_ops)
  ------------------
  |  Branch (2123:6): [True: 1, False: 16.9k]
  ------------------
 2124|      1|		iso_ops = iso_drv->ops;
 2125|       |
 2126|  16.9k|	authentic_ops = *iso_ops;
 2127|       |
 2128|  16.9k|	authentic_ops.match_card = authentic_match_card;
 2129|  16.9k|	authentic_ops.init = authentic_init;
 2130|  16.9k|	authentic_ops.finish = authentic_finish;
 2131|  16.9k|	authentic_ops.read_binary = authentic_read_binary;
 2132|  16.9k|	authentic_ops.write_binary = authentic_write_binary;
 2133|  16.9k|	authentic_ops.update_binary = authentic_update_binary;
 2134|  16.9k|	authentic_ops.erase_binary = authentic_erase_binary;
 2135|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2136|  16.9k|	authentic_ops.select_file = authentic_select_file;
 2137|       |	/* get_response: Untested */
 2138|  16.9k|	authentic_ops.get_challenge = authentic_get_challenge;
 2139|  16.9k|	authentic_ops.set_security_env = authentic_set_security_env;
 2140|       |	/* decipher: Untested */
 2141|  16.9k|	authentic_ops.decipher = authentic_decipher;
 2142|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2143|  16.9k|	authentic_ops.create_file = authentic_create_file;
 2144|  16.9k|	authentic_ops.delete_file = authentic_delete_file;
 2145|  16.9k|	authentic_ops.card_ctl = authentic_card_ctl;
 2146|  16.9k|	authentic_ops.process_fci = authentic_process_fci;
 2147|  16.9k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2148|  16.9k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2149|       |
 2150|  16.9k|	return &authentic_drv;
 2151|  16.9k|}
card-authentic.c:authentic_match_card:
  396|  11.5k|{
  397|  11.5k|	struct sc_context *ctx = card->ctx;
  398|  11.5k|	int i;
  399|       |
  400|  11.5k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  11.5k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  11.5k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  401|  11.5k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  402|  11.5k|	if (i < 0)   {
  ------------------
  |  Branch (402:6): [True: 11.2k, False: 318]
  ------------------
  403|  11.2k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  11.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__
  |  |  ------------------
  ------------------
  404|  11.2k|		return 0;
  405|  11.2k|	}
  406|       |
  407|    318|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   71|    318|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  408|    318|	return 1;
  409|  11.5k|}
card-authentic.c:authentic_init:
  448|    318|{
  449|    318|	struct sc_context *ctx = card->ctx;
  450|    318|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    318|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  451|       |
  452|    318|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    318|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    318|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    318|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    318|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 318]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|    318|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (453:11): [True: 318, False: 0]
  ------------------
  454|    318|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (454:7): [True: 318, False: 0]
  ------------------
  455|    318|			card->name = authentic_known_atrs[ii].name;
  456|    318|			card->flags = authentic_known_atrs[ii].flags;
  457|    318|			break;
  458|    318|		}
  459|    318|	}
  460|       |
  461|    318|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (461:6): [True: 0, False: 318]
  ------------------
  462|    318|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|       |
  464|    318|	card->cla  = 0x00;
  465|    318|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  466|    318|	if (!card->drv_data)
  ------------------
  |  Branch (466:6): [True: 0, False: 318]
  ------------------
  467|    318|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  468|       |
  469|    318|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (469:6): [True: 318, False: 0]
  ------------------
  470|    318|		rv = authentic_init_oberthur_authentic_3_2(card);
  471|       |
  472|    318|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    318|#define SC_SUCCESS				0
  ------------------
  |  Branch (472:6): [True: 134, False: 184]
  ------------------
  473|    134|		rv = authentic_get_serialnr(card, NULL);
  474|       |
  475|    318|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    318|#define SC_SUCCESS				0
  ------------------
  |  Branch (475:6): [True: 31, False: 287]
  ------------------
  476|     31|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     31|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  477|       |
  478|       |	/* Free private data on error */
  479|    318|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    318|#define SC_SUCCESS				0
  ------------------
  |  Branch (479:6): [True: 31, False: 287]
  ------------------
  480|     31|		free(card->drv_data);
  481|     31|		card->drv_data = NULL;
  482|     31|	}
  483|    318|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    318|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    318|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    318|	int _ret = r; \
  |  |  |  |  155|    318|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 318, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    318|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 287]
  |  |  |  |  ------------------
  |  |  |  |  157|    318|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    318|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    318|	return _ret; \
  |  |  |  |  163|    318|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|    318|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  414|    318|{
  415|    318|	struct sc_context *ctx = card->ctx;
  416|    318|	unsigned int flags;
  417|    318|	int rv = 0;
  418|       |
  419|    318|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    318|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    318|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    318|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    318|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 318]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|       |
  421|    318|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    318|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    318|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    318|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    318|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    318|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    318|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    318|#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|    318|#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|    318|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    318|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    318|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    318|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    318|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    318|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    318|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  422|       |
  423|    318|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    318|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  424|    318|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    318|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  425|    318|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    318|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  426|       |
  427|    318|#ifdef ENABLE_SM
  428|    318|	card->sm_ctx.ops.open = authentic_sm_open;
  429|    318|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  430|    318|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  431|    318|#endif
  432|       |
  433|    318|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  434|    318|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    318|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    318|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    318|	int _ret = (r); \
  |  |  |  |  168|    318|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 119, False: 199]
  |  |  |  |  ------------------
  |  |  |  |  169|    119|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    119|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    119|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    119|		return _ret; \
  |  |  |  |  172|    119|	} \
  |  |  |  |  173|    318|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 199]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  435|       |
  436|    199|	rv = authentic_select_mf(card, NULL);
  437|    199|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    199|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    199|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    199|	int _ret = (r); \
  |  |  |  |  168|    199|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  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|    199|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|       |
  439|    184|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  440|    184|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  441|       |
  442|    184|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    184|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    184|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    184|	int _ret = r; \
  |  |  |  |  155|    184|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 184, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    184|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  157|    184|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    184|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    184|	return _ret; \
  |  |  |  |  163|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|    184|}
card-authentic.c:authentic_select_mf:
  550|    199|{
  551|    199|	struct sc_context *ctx = card->ctx;
  552|    199|	struct sc_path mfpath;
  553|    199|	int rv;
  554|       |
  555|    199|	struct sc_apdu apdu;
  556|    199|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  557|       |
  558|    199|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    199|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    199|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    199|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    199|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 199]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|       |
  560|    199|	sc_format_path("3F00", &mfpath);
  561|    199|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    199|#define SC_PATH_TYPE_PATH		2
  ------------------
  562|       |
  563|    199|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    199|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  564|       |
  565|    199|	apdu.resp = rbuf;
  566|    199|	apdu.resplen = sizeof(rbuf);
  567|       |
  568|    199|	rv = sc_transmit_apdu(card, &apdu);
  569|    199|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    199|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    199|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    199|	int _ret = (r); \
  |  |  |  |  168|    199|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 198]
  |  |  |  |  ------------------
  |  |  |  |  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|    199|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 198]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|    198|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  571|    198|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|    198|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    198|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    198|	int _ret = (r); \
  |  |  |  |  168|    198|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 192]
  |  |  |  |  ------------------
  |  |  |  |  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|    198|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 192]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  572|       |
  573|    192|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  574|    192|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    192|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    192|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    192|	int _ret = (r); \
  |  |  |  |  168|    192|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|    192|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  575|       |
  576|    184|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    184|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    184|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    184|	int _ret = r; \
  |  |  |  |  155|    184|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 184, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    184|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  157|    184|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    184|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    184|	return _ret; \
  |  |  |  |  163|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  577|    184|}
card-authentic.c:authentic_set_current_files:
  511|    875|{
  512|    875|	struct sc_context *ctx = card->ctx;
  513|    875|	struct sc_file *file = NULL;
  514|    875|	int rv;
  515|       |
  516|    875|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    875|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    875|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    875|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    875|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 875]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|    875|	if (resplen)   {
  ------------------
  |  Branch (517:6): [True: 318, False: 557]
  ------------------
  518|    318|		switch (resp[0]) {
  519|     65|		case 0x62:
  ------------------
  |  Branch (519:3): [True: 65, False: 253]
  ------------------
  520|    237|		case 0x6F:
  ------------------
  |  Branch (520:3): [True: 172, False: 146]
  ------------------
  521|    237|			file = sc_file_new();
  522|    237|			if (file == NULL)
  ------------------
  |  Branch (522:8): [True: 0, False: 237]
  ------------------
  523|    237|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|    237|			if (path)
  ------------------
  |  Branch (524:8): [True: 237, False: 0]
  ------------------
  525|    237|				file->path = *path;
  526|       |
  527|    237|			rv = authentic_process_fci(card, file, resp, resplen);
  528|    237|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    237|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:8): [True: 32, False: 205]
  ------------------
  529|     32|				sc_file_free(file);
  530|     32|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  531|     32|			}
  532|       |
  533|    205|			break;
  534|    205|		default:
  ------------------
  |  Branch (534:3): [True: 81, False: 237]
  ------------------
  535|     81|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     81|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     81|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     81|	int _ret = r; \
  |  |  |  |  155|     81|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     81|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    318|		}
  537|       |
  538|    205|		if (file_out)
  ------------------
  |  Branch (538:7): [True: 77, False: 128]
  ------------------
  539|     77|			*file_out = file;
  540|    128|		else
  541|    128|			sc_file_free(file);
  542|    205|	}
  543|       |
  544|    762|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    762|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    762|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    762|	int _ret = r; \
  |  |  |  |  155|    762|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 762, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    762|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 762]
  |  |  |  |  ------------------
  |  |  |  |  157|    762|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    762|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    762|	return _ret; \
  |  |  |  |  163|    762|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  545|    762|}
card-authentic.c:authentic_get_serialnr:
 1470|    303|{
 1471|    303|	struct sc_context *ctx = card->ctx;
 1472|    303|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1473|    303|	int rv;
 1474|       |
 1475|    303|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    303|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    303|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    303|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    303|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 303]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1476|    303|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1476:6): [True: 230, False: 73]
  ------------------
 1477|    230|		rv = authentic_get_cplc(card);
 1478|    230|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    230|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    230|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    230|	int _ret = (r); \
  |  |  |  |  168|    230|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 100, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  169|    100|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    100|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    100|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    100|		return _ret; \
  |  |  |  |  172|    100|	} \
  |  |  |  |  173|    230|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1479|       |
 1480|    130|		card->serialnr.len = 4;
 1481|    130|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1482|       |
 1483|    130|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   71|    130|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1484|    130|				card->serialnr.value[0], card->serialnr.value[1],
 1485|    130|				card->serialnr.value[2], card->serialnr.value[3]);
 1486|    130|	}
 1487|       |
 1488|    203|	if (serial)
  ------------------
  |  Branch (1488:6): [True: 100, False: 103]
  ------------------
 1489|    100|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1490|       |
 1491|    203|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    203|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    203|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    203|	int _ret = r; \
  |  |  |  |  155|    203|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 203, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    203|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 203]
  |  |  |  |  ------------------
  |  |  |  |  157|    203|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    203|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    203|	return _ret; \
  |  |  |  |  163|    203|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|    203|}
card-authentic.c:authentic_get_cplc:
  366|    230|{
  367|    230|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  368|    230|	struct sc_apdu apdu;
  369|    230|	int rv, ii;
  370|    230|	unsigned char p1, p2;
  371|       |
  372|    230|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    230|#define SC_CPLC_TAG		0x9F7F
  ------------------
  373|    230|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    230|#define SC_CPLC_TAG		0x9F7F
  ------------------
  374|    230|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    230|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  375|    233|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (375:12): [True: 232, False: 1]
  ------------------
  376|    232|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    232|#define SC_CPLC_DER_SIZE	45
  ------------------
  377|    232|		apdu.resplen = sizeof(prv_data->cplc.value);
  378|    232|		apdu.resp = prv_data->cplc.value;
  379|       |
  380|    232|		rv = sc_transmit_apdu(card, &apdu);
  381|    232|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    232|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    232|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    232|	int _ret = (r); \
  |  |  |  |  168|    232|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  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|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|    228|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  383|    228|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    228|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (383:7): [True: 225, False: 3]
  ------------------
  384|    225|			break;
  385|       |
  386|      3|		apdu.cla = 0x80;
  387|      3|	}
  388|    226|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    226|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    226|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    226|	int _ret = (r); \
  |  |  |  |  168|    226|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 96, False: 130]
  |  |  |  |  ------------------
  |  |  |  |  169|     96|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     96|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     96|		return _ret; \
  |  |  |  |  172|     96|	} \
  |  |  |  |  173|    226|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 130]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  389|       |
  390|    130|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    130|#define SC_CPLC_DER_SIZE	45
  ------------------
  391|    130|	return SC_SUCCESS;
  ------------------
  |  |   28|    130|#define SC_SUCCESS				0
  ------------------
  392|    226|}
card-authentic.c:authentic_finish:
 1853|    287|{
 1854|    287|	struct sc_context *ctx = card->ctx;
 1855|       |
 1856|    287|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    287|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    287|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    287|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    287|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 287]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1857|       |
 1858|    287|#ifdef ENABLE_SM
 1859|    287|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1859:6): [True: 0, False: 287]
  ------------------
 1860|      0|		card->sm_ctx.ops.close(card);
 1861|    287|#endif
 1862|       |
 1863|    287|	if (card->drv_data)
  ------------------
  |  Branch (1863:6): [True: 287, False: 0]
  ------------------
 1864|    287|		free(card->drv_data);
 1865|    287|	card->drv_data = NULL;
 1866|    287|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    287|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    287|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    287|	int _ret = r; \
  |  |  |  |  155|    287|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 287, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    287|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  157|    287|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    287|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    287|	return _ret; \
  |  |  |  |  163|    287|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1867|    287|}
card-authentic.c:authentic_read_binary:
  649|    242|{
  650|    242|	struct sc_context *ctx = card->ctx;
  651|    242|	struct sc_apdu apdu;
  652|    242|	size_t sz, rest, ret_count = 0;
  653|    242|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    242|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  654|       |
  655|    242|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    242|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    242|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    242|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    242|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 242]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|    242|	sc_log(ctx, "offs:%i,count:%zu,max_recv_size:%zu", idx, count, card->max_recv_size);
  ------------------
  |  |   71|    242|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  657|       |
  658|    242|	rest = count;
  659|  1.87k|	while(rest)   {
  ------------------
  |  Branch (659:8): [True: 1.64k, False: 236]
  ------------------
  660|  1.64k|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (660:8): [True: 1.40k, False: 237]
  ------------------
  661|  1.64k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|  1.64k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  662|  1.64k|		apdu.le = sz;
  663|  1.64k|		apdu.resplen = sz;
  664|  1.64k|		apdu.resp = (buf + ret_count);
  665|       |
  666|  1.64k|		rv = sc_transmit_apdu(card, &apdu);
  667|  1.64k|		if(!rv)
  ------------------
  |  Branch (667:6): [True: 1.63k, False: 6]
  ------------------
  668|  1.63k|			ret_count += apdu.resplen;
  669|      6|		else
  670|      6|			break;
  671|       |
  672|  1.63k|		idx += sz;
  673|  1.63k|		rest -= sz;
  674|  1.63k|	}
  675|       |
  676|    242|	if (rv)   {
  ------------------
  |  Branch (676:6): [True: 6, False: 236]
  ------------------
  677|      6|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  678|      0|		LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  679|      0|	}
  680|       |
  681|    236|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  682|    236|	if (!rv)
  ------------------
  |  Branch (682:6): [True: 209, False: 27]
  ------------------
  683|    209|		count = ret_count;
  684|       |
  685|    236|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    236|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    236|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    236|	int _ret = (r); \
  |  |  |  |  168|    236|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 209]
  |  |  |  |  ------------------
  |  |  |  |  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|    236|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 209]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  686|    209|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|    209|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    209|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    209|	int _ret = r; \
  |  |  |  |  155|    209|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 203]
  |  |  |  |  ------------------
  |  |  |  |  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|    203|	} else { \
  |  |  |  |  159|    203|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    203|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    203|	} \
  |  |  |  |  162|    209|	return _ret; \
  |  |  |  |  163|    209|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|    209|}
card-authentic.c:authentic_select_file:
  582|  1.83k|{
  583|  1.83k|	struct sc_context *ctx = card->ctx;
  584|  1.83k|	struct sc_apdu apdu;
  585|  1.83k|	struct sc_path lpath;
  586|  1.83k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  587|  1.83k|	size_t pathlen;
  588|  1.83k|	int rv;
  589|       |
  590|  1.83k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.83k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.83k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.83k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.83k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.83k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|       |
  592|  1.83k|	memcpy(&lpath, path, sizeof(struct sc_path));
  593|       |
  594|  1.83k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  3.67k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (594:6): [True: 1.10k, False: 733]
  |  Branch (594:41): [True: 240, False: 862]
  ------------------
  595|    240|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    240|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  596|       |
  597|  1.83k|	pathlen = lpath.len;
  598|  1.83k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.83k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  599|       |
  600|  1.83k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (600:6): [True: 0, False: 1.83k]
  ------------------
  601|  1.83k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported card");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|       |
  603|  1.83k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.83k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (603:6): [True: 240, False: 1.59k]
  ------------------
  604|    240|		apdu.p1 = 0x00;
  605|    240|	}
  606|  1.59k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.59k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (606:11): [True: 862, False: 733]
  ------------------
  607|    862|		apdu.p1 = 0x08;
  608|    862|	}
  609|    733|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    733|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (609:11): [True: 0, False: 733]
  ------------------
  610|      0|		apdu.p1 = 0x09;
  611|      0|	}
  612|    733|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    733|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (612:11): [True: 733, False: 0]
  ------------------
  613|    733|		apdu.p1 = 4;
  614|    733|	}
  615|      0|	else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (615:11): [True: 0, False: 0]
  ------------------
  616|      0|		apdu.p1 = 0x03;
  617|      0|		pathlen = 0;
  618|      0|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  619|      0|	}
  620|      0|	else   {
  621|      0|		sc_log(ctx, "Invalid PATH type: 0x%X", lpath.type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  622|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "authentic_select_file() invalid PATH type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  623|      0|	}
  624|       |
  625|  1.83k|	apdu.lc = pathlen;
  626|  1.83k|	apdu.data = lpath.value;
  627|  1.83k|	apdu.datalen = pathlen;
  628|       |
  629|  1.83k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  3.67k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (629:6): [True: 1.83k, False: 0]
  |  Branch (629:42): [True: 0, False: 0]
  ------------------
  630|  1.83k|		apdu.resp = rbuf;
  631|  1.83k|		apdu.resplen = sizeof(rbuf);
  632|  1.83k|		apdu.le = 256;
  633|  1.83k|	}
  634|       |
  635|  1.83k|	rv = sc_transmit_apdu(card, &apdu);
  636|  1.83k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.83k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.83k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.83k|	int _ret = (r); \
  |  |  |  |  168|  1.83k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 1.80k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.80k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  637|  1.80k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  638|  1.80k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.80k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.80k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.80k|	int _ret = (r); \
  |  |  |  |  168|  1.80k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.12k, False: 683]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.12k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.12k|		return _ret; \
  |  |  |  |  172|  1.12k|	} \
  |  |  |  |  173|  1.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 683]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  639|       |
  640|    683|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  641|    683|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    683|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    683|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    683|	int _ret = (r); \
  |  |  |  |  168|    683|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 105, False: 578]
  |  |  |  |  ------------------
  |  |  |  |  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|    683|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 578]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|       |
  643|    578|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    578|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    578|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    578|	int _ret = r; \
  |  |  |  |  155|    578|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 578, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    578|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 578]
  |  |  |  |  ------------------
  |  |  |  |  157|    578|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    578|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    578|	return _ret; \
  |  |  |  |  163|    578|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|    578|}
card-authentic.c:authentic_set_security_env:
 1771|    410|{
 1772|    410|	struct sc_context *ctx = card->ctx;
 1773|    410|	struct sc_apdu apdu;
 1774|    410|	unsigned char cse_crt_dst[] = {
 1775|    410|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    410|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1776|    410|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    410|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1777|    410|	};
 1778|    410|	unsigned char cse_crt_ct[] = {
 1779|    410|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    410|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1780|    410|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    410|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1781|    410|	};
 1782|    410|	int rv;
 1783|       |
 1784|    410|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    410|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    410|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    410|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    410|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 410]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1785|    410|	sc_log(ctx, "set SE#%i(op:0x%X,algo:0x%lX,algo_ref:0x%lX,flags:0x%lX), key_ref:0x%X",
  ------------------
  |  |   71|    410|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1786|    410|			se_num, env->operation, env->algorithm, env->algorithm_ref, env->algorithm_flags, env->key_ref[0]);
 1787|    410|	switch (env->operation)  {
 1788|    330|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    330|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1788:2): [True: 330, False: 80]
  ------------------
 1789|    330|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  293|    330|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  109|    330|#define AUTHENTIC_TAG_CRT_DST	0xB6
  ------------------
 1790|    330|		apdu.data = cse_crt_dst;
 1791|    330|		apdu.datalen = sizeof(cse_crt_dst);
 1792|    330|		apdu.lc = sizeof(cse_crt_dst);
 1793|    330|		break;
 1794|     80|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     80|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1794:2): [True: 80, False: 330]
  ------------------
 1795|     80|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  293|     80|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  110|     80|#define AUTHENTIC_TAG_CRT_CT	0xB8
  ------------------
 1796|     80|		apdu.data = cse_crt_ct;
 1797|     80|		apdu.datalen = sizeof(cse_crt_ct);
 1798|     80|		apdu.lc = sizeof(cse_crt_ct);
 1799|     80|		break;
 1800|      0|	default:
  ------------------
  |  Branch (1800:2): [True: 0, False: 410]
  ------------------
 1801|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1802|    410|	}
 1803|       |
 1804|    410|	rv = sc_transmit_apdu(card, &apdu);
 1805|    410|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    410|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    410|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    410|	int _ret = (r); \
  |  |  |  |  168|    410|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 385]
  |  |  |  |  ------------------
  |  |  |  |  169|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     25|		return _ret; \
  |  |  |  |  172|     25|	} \
  |  |  |  |  173|    410|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 385]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1806|    385|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1807|    385|	LOG_TEST_RET(ctx, rv, "MSE restore error");
  ------------------
  |  |  174|    385|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    385|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    385|	int _ret = (r); \
  |  |  |  |  168|    385|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 221, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  169|    221|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    221|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    221|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    221|		return _ret; \
  |  |  |  |  172|    221|	} \
  |  |  |  |  173|    385|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 164]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1808|       |
 1809|    164|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    164|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    164|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    164|	int _ret = r; \
  |  |  |  |  155|    164|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 164, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    164|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  157|    164|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    164|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    164|	return _ret; \
  |  |  |  |  163|    164|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1810|    164|}
card-authentic.c:authentic_decipher:
 1816|     52|{
 1817|     52|	struct sc_context *ctx = card->ctx;
 1818|     52|	struct sc_apdu apdu;
 1819|     52|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1820|     52|	int rv;
 1821|       |
 1822|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1823|     52|	sc_log(ctx, "crgram_len %zu;  outlen %zu", in_len, out_len);
  ------------------
  |  |   71|     52|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1824|     52|	if (!out || !out_len || in_len > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|     52|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1824:6): [True: 0, False: 52]
  |  Branch (1824:14): [True: 0, False: 52]
  |  Branch (1824:26): [True: 3, False: 49]
  ------------------
 1825|     52|		LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1826|       |
 1827|     49|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     49|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1828|     49|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     49|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1829|     49|	apdu.data = in;
 1830|     49|	apdu.datalen = in_len;
 1831|     49|	apdu.lc = in_len;
 1832|     49|	apdu.resp = resp;
 1833|     49|	apdu.resplen = sizeof(resp);
 1834|     49|	apdu.le = 256;
 1835|       |
 1836|     49|	rv = sc_transmit_apdu(card, &apdu);
 1837|     49|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     49|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     49|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     49|	int _ret = (r); \
  |  |  |  |  168|     49|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1838|     34|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1839|     34|	LOG_TEST_RET(ctx, rv, "Card returned error");
  ------------------
  |  |  174|     34|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     34|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     34|	int _ret = (r); \
  |  |  |  |  168|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|       |
 1841|     23|	if (out_len > apdu.resplen)
  ------------------
  |  Branch (1841:6): [True: 23, False: 0]
  ------------------
 1842|     23|		out_len = apdu.resplen;
 1843|       |
 1844|     23|	memcpy(out, apdu.resp, out_len);
 1845|     23|	rv = (int)out_len;
 1846|       |
 1847|     23|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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: 14, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|      9|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      9|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      9|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1848|     23|}
card-authentic.c:authentic_card_ctl:
 1744|    169|{
 1745|    169|	struct sc_context *ctx = card->ctx;
 1746|    169|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1747|       |
 1748|    169|	switch (cmd) {
  ------------------
  |  Branch (1748:10): [True: 169, False: 0]
  ------------------
 1749|    169|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1749:2): [True: 169, False: 0]
  ------------------
 1750|    169|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1751|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1751:2): [True: 0, False: 169]
  ------------------
 1752|      0|		sc_log(ctx, "CARDCTL SDO_CREATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1753|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1754|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1754:2): [True: 0, False: 169]
  ------------------
 1755|      0|		sc_log(ctx, "CARDCTL SDO_DELETE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1756|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1757|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1757:2): [True: 0, False: 169]
  ------------------
 1758|      0|		sc_log(ctx, "CARDCTL SDO_STORE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1759|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1760|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1760:2): [True: 0, False: 169]
  ------------------
 1761|      0|		sc_log(ctx, "CARDCTL SDO_GENERATE: sdo(mech:%X,id:%X)", sdo->docp.mech, sdo->docp.id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1762|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1763|    169|	}
 1764|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1765|    169|}
card-authentic.c:authentic_get_tagged_data:
  177|    651|{
  178|    651|	size_t size_len, tag_len, offs, size;
  179|    651|	int rv;
  180|    651|	unsigned tag;
  181|       |
  182|    651|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 651]
  |  Branch (182:14): [True: 0, False: 651]
  ------------------
  183|    651|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|  4.61k|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 4.46k, False: 154]
  ------------------
  186|  4.46k|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 1.14k, False: 3.32k]
  |  Branch (186:33): [True: 221, False: 3.09k]
  ------------------
  187|  1.36k|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 5, False: 1.35k]
  ------------------
  188|  1.36k|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|  1.35k|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|  1.35k|			tag_len = 2;
  191|  1.35k|		}
  192|  3.09k|		else   {
  193|  3.09k|			tag = *(in + offs);
  194|  3.09k|			tag_len = 1;
  195|  3.09k|		}
  196|       |
  197|  4.45k|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 35, False: 4.42k]
  ------------------
  198|  4.45k|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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: 35, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     35|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     35|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     35|		return _ret; \
  |  |  |  |  172|     35|	} \
  |  |  |  |  173|     35|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|  4.42k|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|  4.42k|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|  4.42k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.42k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.42k|	int _ret = (r); \
  |  |  |  |  168|  4.42k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 73, False: 4.34k]
  |  |  |  |  ------------------
  |  |  |  |  169|     73|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     73|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     73|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     73|		return _ret; \
  |  |  |  |  172|     73|	} \
  |  |  |  |  173|  4.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.34k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|  4.34k|		size_len = rv;
  203|       |
  204|  4.34k|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 384, False: 3.96k]
  ------------------
  205|    384|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 4, False: 380]
  ------------------
  206|    384|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|    380|			*out = in + offs + tag_len + size_len;
  209|    380|			*out_len = size;
  210|       |
  211|    380|			return SC_SUCCESS;
  ------------------
  |  |   28|    380|#define SC_SUCCESS				0
  ------------------
  212|    384|		}
  213|       |
  214|  3.96k|		offs += tag_len + size_len + size;
  215|  3.96k|	}
  216|       |
  217|    154|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    154|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    651|}
card-authentic.c:authentic_parse_size:
  149|  4.42k|{
  150|  4.42k|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 4.42k]
  |  Branch (150:13): [True: 0, False: 4.42k]
  |  Branch (150:21): [True: 0, False: 4.42k]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|  4.42k|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 3.09k, False: 1.32k]
  ------------------
  154|  3.09k|		*out = *in;
  155|  3.09k|		return 1;
  156|  3.09k|	}
  157|  1.32k|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 1.14k, False: 178]
  ------------------
  158|  1.14k|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 1, False: 1.14k]
  ------------------
  159|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|  1.14k|		*out = *(in + 1);
  161|  1.14k|		return 2;
  162|  1.14k|	}
  163|    178|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 107, False: 71]
  ------------------
  164|    107|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 1, False: 106]
  ------------------
  165|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|    106|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|    106|		return 3;
  168|    107|	}
  169|       |
  170|     71|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     71|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|  4.42k|}
card-authentic.c:authentic_process_fci:
  775|    237|{
  776|    237|	struct sc_context *ctx = card->ctx;
  777|    237|	size_t taglen;
  778|    237|	int rv;
  779|    237|	unsigned ii;
  780|    237|	const unsigned char *tag = NULL;
  781|    237|	unsigned char ops_DF[8] = {
  782|    237|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    237|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    237|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    237|#define SC_AC_OP_CRYPTO			7
  ------------------
  783|    237|	};
  784|    237|	unsigned char ops_EF[8] = {
  785|    237|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    237|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    237|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  189|    237|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  191|    237|#define SC_AC_OP_RESIZE			25
  ------------------
  786|    237|	};
  787|       |
  788|    237|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    237|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    237|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    237|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    237|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 237]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|       |
  790|    237|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  791|    237|	if (tag != NULL) {
  ------------------
  |  Branch (791:6): [True: 160, False: 77]
  ------------------
  792|    160|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    160|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  793|    160|		buf = tag;
  794|    160|		buflen = taglen;
  795|    160|	}
  796|       |
  797|    237|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  798|    237|	if (tag != NULL) {
  ------------------
  |  Branch (798:6): [True: 53, False: 184]
  ------------------
  799|     53|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|     53|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  800|     53|		buf = tag;
  801|     53|		buflen = taglen;
  802|     53|	}
  803|       |
  804|    237|	rv = iso_ops->process_fci(card, file, buf, buflen);
  805|    237|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    237|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    237|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    237|	int _ret = (r); \
  |  |  |  |  168|    237|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 237]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    237|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 237]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|       |
  807|    237|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (807:6): [True: 128, False: 109]
  ------------------
  808|    128|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|    128|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    128|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|    128|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   71|    128|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  810|    128|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    256|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    114|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (810:7): [True: 14, False: 114]
  |  Branch (810:50): [True: 82, False: 32]
  ------------------
  811|     96|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     96|#define SC_FILE_TYPE_DF			0x04
  ------------------
  812|     96|		}
  813|     32|		else   {
  814|     32|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|     32|		}
  816|    128|	}
  817|       |
  818|    205|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    205|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    205|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  819|    793|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (819:15): [True: 611, False: 182]
  |  Branch (819:46): [True: 588, False: 23]
  ------------------
  820|    588|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    588|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (820:22): [True: 91, False: 497]
  ------------------
  821|    588|		unsigned char acl = *(file->sec_attr + ii*2);
  822|    588|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  823|    588|		unsigned sc = acl * 0x100 + cred_id;
  824|       |
  825|    588|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    588|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  826|    588|		if (op == 0xFF)
  ------------------
  |  Branch (826:7): [True: 201, False: 387]
  ------------------
  827|    201|			;
  828|    387|		else if (!acl && !cred_id)
  ------------------
  |  Branch (828:12): [True: 124, False: 263]
  |  Branch (828:20): [True: 57, False: 67]
  ------------------
  829|     57|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     57|#define SC_AC_NONE			0x00000000
  ------------------
  830|    330|		else if (acl == 0xFF)
  ------------------
  |  Branch (830:12): [True: 59, False: 271]
  ------------------
  831|     59|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     59|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    271|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    271|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (832:12): [True: 131, False: 140]
  ------------------
  833|    131|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    131|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  834|    140|		else if (cred_id)
  ------------------
  |  Branch (834:12): [True: 105, False: 35]
  ------------------
  835|    105|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    105|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  836|     35|		else
  837|     35|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     35|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  838|    588|	}
  839|       |
  840|    205|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    205|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    205|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    205|	int _ret = r; \
  |  |  |  |  155|    205|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 205, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    205|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 205]
  |  |  |  |  ------------------
  |  |  |  |  157|    205|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    205|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    205|	return _ret; \
  |  |  |  |  163|    205|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|    205|}
card-authentic.c:authentic_pin_cmd:
 1438|    419|{
 1439|    419|	struct sc_context *ctx = card->ctx;
 1440|    419|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    419|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1441|       |
 1442|    419|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    419|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    419|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    419|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    419|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 419]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1443|    419|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|    419|#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|    419|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|    419|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1445|    419|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|    419|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1446|       |
 1447|    419|	switch (data->cmd)   {
 1448|     34|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     34|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1448:2): [True: 34, False: 385]
  ------------------
 1449|     34|		rv = authentic_pin_verify(card, data);
 1450|     34|		break;
 1451|     32|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     32|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1451:2): [True: 32, False: 387]
  ------------------
 1452|     32|		rv = authentic_pin_change(card, data);
 1453|     32|		break;
 1454|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1454:2): [True: 0, False: 419]
  ------------------
 1455|      0|		rv = authentic_pin_reset(card, data);
 1456|      0|		break;
 1457|    353|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    353|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1457:2): [True: 353, False: 66]
  ------------------
 1458|    353|		rv = authentic_pin_get_policy(card, data, NULL);
 1459|    353|		break;
 1460|      0|	default:
  ------------------
  |  Branch (1460:2): [True: 0, False: 419]
  ------------------
 1461|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN command");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1462|    419|	}
 1463|       |
 1464|    419|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    419|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    419|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    419|	int _ret = r; \
  |  |  |  |  155|    419|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 419, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    419|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    318|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 318, False: 101]
  |  |  |  |  ------------------
  |  |  |  |  157|    419|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    419|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    419|	return _ret; \
  |  |  |  |  163|    419|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1465|    419|}
card-authentic.c:authentic_pin_verify:
 1103|     34|{
 1104|     34|	struct sc_context *ctx = card->ctx;
 1105|     34|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1106|     34|	unsigned char pin_sha1[SHA_DIGEST_LENGTH];
 1107|     34|	int rv;
 1108|       |
 1109|     34|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     34|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     34|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     34|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     34|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1110|     34|	sc_log(ctx, "PIN(type:%X,reference:%X,data:%p,length:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1111|     34|			pin_cmd->pin_type, pin_cmd->pin_reference, pin_cmd->pin1.data, pin_cmd->pin1.len);
 1112|       |
 1113|     34|	if (pin_cmd->pin_reference < 0 || pin_cmd->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|     34|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1113:6): [True: 0, False: 34]
  |  Branch (1113:36): [True: 0, False: 34]
  ------------------
 1114|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN reference out of bounds");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|      0|	}
 1116|       |
 1117|     34|	if (pin_cmd->pin1.data && !pin_cmd->pin1.len)   {
  ------------------
  |  Branch (1117:6): [True: 34, False: 0]
  |  Branch (1117:28): [True: 0, False: 34]
  ------------------
 1118|      0|		pin_cmd->pin1.tries_left = -1;
 1119|      0|		rv = authentic_pin_is_verified(card, pin_cmd);
 1120|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1121|      0|	}
 1122|       |
 1123|     34|	if (pin_cmd->pin1.data)
  ------------------
  |  Branch (1123:6): [True: 34, False: 0]
  ------------------
 1124|     34|		SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, pin_sha1);
 1125|      0|	else
 1126|      0|		SHA1((unsigned char *)"", 0, pin_sha1);
 1127|       |
 1128|     34|	if (!memcmp(pin_sha1, prv_data->pins_sha1[pin_cmd->pin_reference], SHA_DIGEST_LENGTH))   {
  ------------------
  |  Branch (1128:6): [True: 0, False: 34]
  ------------------
 1129|      0|		sc_log(ctx, "Already verified");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1130|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|      0|	}
 1132|       |
 1133|     34|	memset(prv_data->pins_sha1[pin_cmd->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1134|       |
 1135|     34|	rv = authentic_pin_get_policy(card, pin_cmd, NULL);
 1136|     34|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  174|     34|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     34|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     34|	int _ret = (r); \
  |  |  |  |  168|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1137|       |
 1138|     11|	if (pin_cmd->pin1.len > pin_cmd->pin1.max_length)
  ------------------
  |  Branch (1138:6): [True: 0, False: 11]
  ------------------
 1139|     11|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_LENGTH, "PIN policy check failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1140|       |
 1141|     11|	pin_cmd->pin1.tries_left = -1;
 1142|     11|	rv = authentic_chv_verify(card, pin_cmd);
 1143|     11|	LOG_TEST_RET(ctx, rv, "PIN CHV verification error");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|       |
 1145|      6|	memcpy(prv_data->pins_sha1[pin_cmd->pin_reference], pin_sha1, SHA_DIGEST_LENGTH);
 1146|      6|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|      6|}
card-authentic.c:authentic_chv_verify:
 1020|     11|{
 1021|     11|	struct sc_context *ctx = card->ctx;
 1022|     11|	struct sc_apdu apdu;
 1023|     11|	struct sc_pin_cmd_pin *pin1 = &pin_cmd->pin1;
 1024|     11|	unsigned char pin_buff[SC_MAX_APDU_BUFFER_SIZE];
 1025|     11|	size_t pin_len;
 1026|     11|	int rv;
 1027|       |
 1028|     11|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1029|     11|	sc_log(ctx, "CHV PIN reference %i, pin1(%p,len:%zu)", pin_cmd->pin_reference, pin1->data, pin1->len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1030|       |
 1031|     11|	if (pin1->data && !pin1->len)   {
  ------------------
  |  Branch (1031:6): [True: 11, False: 0]
  |  Branch (1031:20): [True: 0, False: 11]
  ------------------
 1032|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1033|      0|	}
 1034|     11|	else if (pin1->data && pin1->len)   {
  ------------------
  |  Branch (1034:11): [True: 11, False: 0]
  |  Branch (1034:25): [True: 11, False: 0]
  ------------------
 1035|     11|		if (pin1->len > sizeof(pin_buff)) {
  ------------------
  |  Branch (1035:7): [True: 0, False: 11]
  ------------------
 1036|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1037|      0|		}
 1038|     11|		memcpy(pin_buff, pin1->data, pin1->len);
 1039|     11|		pin_len = pin1->len;
 1040|       |
 1041|     11|		if (pin1->pad_length && pin_cmd->flags & SC_PIN_CMD_NEED_PADDING)   {
  ------------------
  |  |  422|     11|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1041:7): [True: 11, False: 0]
  |  Branch (1041:27): [True: 11, False: 0]
  ------------------
 1042|     11|			if (pin1->len > pin1->pad_length || pin1->pad_length > sizeof(pin_buff)) {
  ------------------
  |  Branch (1042:8): [True: 0, False: 11]
  |  Branch (1042:40): [True: 0, False: 11]
  ------------------
 1043|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_PIN_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1044|      0|			}
 1045|     11|			if (pin1->len < sizeof(pin_buff)) {
  ------------------
  |  Branch (1045:8): [True: 11, False: 0]
  ------------------
 1046|     11|				memset(pin_buff + pin1->len, pin1->pad_char,
 1047|     11|						pin1->pad_length - pin1->len);
 1048|     11|			}
 1049|     11|			pin_len = pin1->pad_length;
 1050|     11|		}
 1051|       |
 1052|     11|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  293|     11|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1053|     11|		apdu.data = pin_buff;
 1054|     11|		apdu.datalen = pin_len;
 1055|     11|		apdu.lc = pin_len;
 1056|     11|	}
 1057|      0|	else if ((card->reader->capabilities & SC_READER_CAP_PIN_PAD) && !pin1->data && !pin1->len)   {
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1057:11): [True: 0, False: 0]
  |  Branch (1057:67): [True: 0, False: 0]
  |  Branch (1057:82): [True: 0, False: 0]
  ------------------
 1058|      0|		rv = authentic_chv_verify_pinpad(card, pin_cmd);
 1059|      0|		sc_log(ctx, "authentic_chv_verify() authentic_chv_verify_pinpad returned %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__
  |  |  ------------------
  ------------------
 1060|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1061|      0|	}
 1062|      0|	else   {
 1063|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1064|      0|	}
 1065|       |
 1066|     11|	rv = sc_transmit_apdu(card, &apdu);
 1067|     11|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1068|       |
 1069|     10|	if (apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)   {
  ------------------
  |  Branch (1069:6): [True: 3, False: 7]
  |  Branch (1069:26): [True: 1, False: 2]
  ------------------
 1070|      1|		pin1->tries_left = apdu.sw2 & 0x0F;
 1071|      1|	}
 1072|       |
 1073|     10|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1074|       |
 1075|     10|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1076|     10|}
card-authentic.c:authentic_pin_change:
 1198|     32|{
 1199|     32|	struct sc_context *ctx = card->ctx;
 1200|     32|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1201|     32|	struct sc_apdu apdu;
 1202|     32|	unsigned char pin_data[SC_MAX_APDU_BUFFER_SIZE];
 1203|     32|	size_t offs;
 1204|     32|	int rv;
 1205|       |
 1206|     32|	rv = authentic_pin_get_policy(card, data, NULL);
 1207|     32|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1208|       |
 1209|      5|	if (data->pin_reference < 0 || data->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|      5|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1209:6): [True: 0, False: 5]
  |  Branch (1209:33): [True: 0, False: 5]
  ------------------
 1210|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN reference out of bounds");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1211|      0|	}
 1212|       |
 1213|      5|	memset(prv_data->pins_sha1[data->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1214|       |
 1215|      5|	if (!data->pin1.data && !data->pin1.len && !data->pin2.data && !data->pin2.len)   {
  ------------------
  |  Branch (1215:6): [True: 0, False: 5]
  |  Branch (1215:26): [True: 0, False: 0]
  |  Branch (1215:45): [True: 0, False: 0]
  |  Branch (1215:65): [True: 0, False: 0]
  ------------------
 1216|      0|		if (!(card->reader->capabilities & SC_READER_CAP_PIN_PAD))
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1216:7): [True: 0, False: 0]
  ------------------
 1217|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "PIN pad 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1218|      0|		rv = authentic_pin_change_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1219|      0|		sc_log(ctx, "authentic_pin_cmd(SC_PIN_CMD_CHANGE) chv_change_pinpad returned %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__
  |  |  ------------------
  ------------------
 1220|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1221|      0|	}
 1222|       |
 1223|      5|	if (card->max_send_size && (data->pin1.len + data->pin2.len > card->max_send_size))
  ------------------
  |  Branch (1223:6): [True: 5, False: 0]
  |  Branch (1223:29): [True: 0, False: 5]
  ------------------
 1224|      5|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_LENGTH, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1225|       |
 1226|      5|	memset(pin_data, data->pin1.pad_char, sizeof(pin_data));
 1227|      5|	offs = 0;
 1228|      5|	if (data->pin1.data && data->pin1.len)   {
  ------------------
  |  Branch (1228:6): [True: 5, False: 0]
  |  Branch (1228:25): [True: 5, False: 0]
  ------------------
 1229|      5|		if (data->pin1.pad_length > sizeof(pin_data) || data->pin1.len > sizeof(pin_data)) {
  ------------------
  |  Branch (1229:7): [True: 0, False: 5]
  |  Branch (1229:51): [True: 0, False: 5]
  ------------------
 1230|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN length exceeds buffer");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1231|      0|		}
 1232|      5|		memcpy(pin_data, data->pin1.data, data->pin1.len);
 1233|      5|		offs += data->pin1.pad_length;
 1234|      5|	}
 1235|      5|	if (data->pin2.data && data->pin2.len) {
  ------------------
  |  Branch (1235:6): [True: 5, False: 0]
  |  Branch (1235:25): [True: 5, False: 0]
  ------------------
 1236|      5|		if (data->pin2.len + offs > sizeof(pin_data)) {
  ------------------
  |  Branch (1236:7): [True: 0, False: 5]
  ------------------
 1237|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "PIN2 length exceeds buffer");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1238|      0|		}
 1239|      5|		memcpy(pin_data + offs, data->pin2.data, data->pin2.len);
 1240|      5|	}
 1241|       |
 1242|      5|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, offs ? 0x00 : 0x01, data->pin_reference);
  ------------------
  |  |  293|      5|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1242:58): [True: 5, False: 0]
  ------------------
 1243|      5|	apdu.data = pin_data;
 1244|      5|	apdu.datalen = offs + data->pin1.pad_length;
 1245|      5|	apdu.lc = offs + data->pin1.pad_length;
 1246|       |
 1247|      5|	rv = sc_transmit_apdu(card, &apdu);
 1248|      5|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1249|      4|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1250|       |
 1251|      4|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|      4|}
card-authentic.c:authentic_pin_get_policy:
 1299|    419|{
 1300|    419|	struct sc_context *ctx = card->ctx;
 1301|    419|	struct sc_apdu apdu;
 1302|    419|	unsigned char rbuf[0x100];
 1303|    419|	int ii, rv;
 1304|       |
 1305|    419|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    419|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    419|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    419|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    419|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 419]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1306|    419|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|    419|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|       |
 1308|    419|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    419|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1309|    422|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1309:12): [True: 421, False: 1]
  ------------------
 1310|    421|		apdu.le = sizeof(rbuf);
 1311|    421|		apdu.resp = rbuf;
 1312|    421|		apdu.resplen = sizeof(rbuf);
 1313|       |
 1314|    421|		rv = sc_transmit_apdu(card, &apdu);
 1315|    421|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    421|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    421|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    421|	int _ret = (r); \
  |  |  |  |  168|    421|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 406]
  |  |  |  |  ------------------
  |  |  |  |  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|    421|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 406]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1316|    406|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1317|       |
 1318|    406|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    406|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1318:7): [True: 403, False: 3]
  ------------------
 1319|    403|			break;
 1320|       |
 1321|      3|		apdu.cla = 0x80;
 1322|      3|	}
 1323|    404|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  174|    404|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    404|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    404|	int _ret = (r); \
  |  |  |  |  168|    404|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 122, False: 282]
  |  |  |  |  ------------------
  |  |  |  |  169|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    122|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    122|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    122|		return _ret; \
  |  |  |  |  172|    122|	} \
  |  |  |  |  173|    404|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 282]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1324|       |
 1325|    282|	data->pin1.tries_left = -1;
 1326|       |
 1327|    282|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1328|    282|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  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: 172, False: 110]
  |  |  |  |  ------------------
  |  |  |  |  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|    282|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 110]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1329|       |
 1330|    110|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    110|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1331|    110|	data->pin1.offset = 5;
 1332|    110|	data->pin1.pad_char = 0xFF;
 1333|    110|	data->pin1.pad_length = data->pin1.max_length;
 1334|    110|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    110|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1335|       |
 1336|    110|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    110|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1337|       |
 1338|    110|	sc_log(ctx, "PIN policy: size max/min/pad %zu/%zu/%zu, tries max/left %i/%i",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1339|    110|			data->pin1.max_length, data->pin1.min_length, data->pin1.pad_length,
 1340|    110|			data->pin1.max_tries, data->pin1.tries_left);
 1341|       |
 1342|    110|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    110|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    110|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    110|	int _ret = r; \
  |  |  |  |  155|    110|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 110, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    110|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 110]
  |  |  |  |  ------------------
  |  |  |  |  157|    110|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    110|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    110|	return _ret; \
  |  |  |  |  163|    110|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1343|    110|}
card-authentic.c:authentic_parse_credential_data:
  286|    282|{
  287|    282|	unsigned char *data;
  288|    282|	size_t data_len;
  289|    282|	int rv, ii;
  290|    282|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|    282|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|    282|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|    282|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  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: 149, False: 133]
  |  |  |  |  ------------------
  |  |  |  |  169|    149|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    149|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    149|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    149|		return _ret; \
  |  |  |  |  172|    149|	} \
  |  |  |  |  173|    282|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 133]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|    133|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|    133|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|    133|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  174|    133|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    133|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    133|	int _ret = (r); \
  |  |  |  |  168|    133|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  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|    133|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|    127|	if (data_len < 1)
  ------------------
  |  Branch (297:6): [True: 3, False: 124]
  ------------------
  298|    127|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid try limit");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|    124|	pin_cmd->pin1.max_tries = *data;
  300|       |
  301|    124|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|    124|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  302|    124|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|    124|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    124|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    124|	int _ret = (r); \
  |  |  |  |  168|    124|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 119]
  |  |  |  |  ------------------
  |  |  |  |  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|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 119]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|    119|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (303:6): [True: 116, False: 3]
  |  Branch (303:22): [True: 4, False: 112]
  ------------------
  304|      4|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      4|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  305|    115|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (305:11): [True: 112, False: 3]
  |  Branch (305:27): [True: 111, False: 1]
  |  Branch (305:41): [True: 107, False: 4]
  ------------------
  306|    107|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|    107|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  307|      8|	else
  308|      8|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|       |
  310|       |	/* Parse optional ACLs when requested */
  311|    111|	if (acls) {
  ------------------
  |  Branch (311:6): [True: 0, False: 111]
  ------------------
  312|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_ACLS, &data, &data_len);
  ------------------
  |  |   75|      0|#define AUTHENTIC_TAG_DOCP_ACLS			0x86
  ------------------
  313|      0|		LOG_TEST_RET(ctx, rv, "failed to get ACLs");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|      0|		sc_log(ctx, "data_len:%zu", data_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|		if (data_len == 10)   {
  ------------------
  |  Branch (315:7): [True: 0, False: 0]
  ------------------
  316|      0|			for (ii=0; ii<5; ii++)   {
  ------------------
  |  Branch (316:15): [True: 0, False: 0]
  ------------------
  317|      0|				unsigned char acl = *(data + ii*2);
  318|      0|				unsigned char cred_id = *(data + ii*2 + 1);
  319|      0|				unsigned sc = acl * 0x100 + cred_id;
  320|       |
  321|      0|				sc_log(ctx, "%i: SC:%X", ii, sc);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  322|      0|				if (!sc)
  ------------------
  |  Branch (322:9): [True: 0, False: 0]
  ------------------
  323|      0|					continue;
  324|       |
  325|      0|				if (acl & AUTHENTIC_AC_SM_MASK)   {
  ------------------
  |  |  119|      0|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (325:9): [True: 0, False: 0]
  ------------------
  326|      0|					acls[ii].method = SC_AC_SCB;
  ------------------
  |  |  157|      0|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  327|      0|					acls[ii].key_ref = sc;
  328|      0|				}
  329|      0|				else if (acl!=0xFF && cred_id)   {
  ------------------
  |  Branch (329:14): [True: 0, False: 0]
  |  Branch (329:27): [True: 0, False: 0]
  ------------------
  330|      0|					sc_log(ctx, "%i: ACL(method:SC_AC_CHV,id:%i)", ii, cred_id);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  331|      0|					acls[ii].method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  332|      0|					acls[ii].key_ref = cred_id;
  333|      0|				}
  334|      0|				else   {
  335|      0|					acls[ii].method = SC_AC_NEVER;
  ------------------
  |  |  163|      0|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  336|      0|					acls[ii].key_ref = 0;
  337|      0|				}
  338|      0|			}
  339|      0|		}
  340|      0|	}
  341|       |
  342|    111|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|    111|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  343|    111|	if (!rv)   {
  ------------------
  |  Branch (343:6): [True: 1, False: 110]
  ------------------
  344|      1|		blob = data;
  345|      1|		blob_len = data_len;
  346|       |
  347|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  348|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|      0|		if (data_len < 1)
  ------------------
  |  Branch (349:7): [True: 0, False: 0]
  ------------------
  350|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid PIN max.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		pin_cmd->pin1.max_length = *data;
  352|       |
  353|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      0|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  354|      0|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  355|      0|		if (data_len < 1)
  ------------------
  |  Branch (355:7): [True: 0, False: 0]
  ------------------
  356|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|      0|		pin_cmd->pin1.min_length = *data;
  358|      0|	}
  359|       |
  360|    110|	return SC_SUCCESS;
  ------------------
  |  |   28|    110|#define SC_SUCCESS				0
  ------------------
  361|    111|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1871|  1.60k|{
 1872|  1.60k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.60k|#define SC_SUCCESS				0
  ------------------
 1873|       |
 1874|  1.60k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.60k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.60k]
  |  |  ------------------
  ------------------
 1875|       |
 1876|  1.60k|	if (was_reset > 0
  ------------------
  |  Branch (1876:6): [True: 0, False: 1.60k]
  ------------------
 1877|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1877:7): [True: 0, False: 0]
  ------------------
 1878|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1879|      0|	}
 1880|       |
 1881|  1.60k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 1.60k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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: 1.60k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.60k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.60k|	return _ret; \
  |  |  |  |  163|  1.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1882|  1.60k|}

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

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

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

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

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

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

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

coolkey_get_attribute_data:
  603|  4.53k|{
  604|       |	/* handle the V0 objects first */
  605|  4.53k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  4.53k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (605:6): [True: 624, False: 3.91k]
  ------------------
  606|    624|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  607|    624|	}
  608|       |
  609|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  610|  3.91k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  3.91k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (610:6): [True: 0, False: 3.91k]
  ------------------
  611|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  612|      0|	}
  613|       |
  614|  3.91k|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  615|       |
  616|  3.91k|}
coolkey_compare_id:
  758|   391k|{
  759|   391k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (759:6): [True: 0, False: 391k]
  |  Branch (759:19): [True: 0, False: 391k]
  ------------------
  760|      0|		return 1;
  761|   391k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  762|   391k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  763|   391k|}
coolkey_list_meter:
  766|  9.83k|size_t coolkey_list_meter(const void *el) {
  767|  9.83k|	return sizeof(sc_cardctl_coolkey_object_t);
  768|  9.83k|}
coolkey_fill_object:
 1365|  48.2k|{
 1366|  48.2k|	int r;
 1367|  48.2k|	size_t buf_len = obj->length;
 1368|  48.2k|	u8 *new_obj_data = NULL;
 1369|  48.2k|	sc_cardctl_coolkey_object_t *obj_entry;
 1370|  48.2k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  48.2k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1371|       |
 1372|  48.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  48.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  48.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  48.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  48.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 48.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|       |
 1374|  48.2k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1374:6): [True: 0, False: 48.2k]
  ------------------
 1375|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1376|      0|	}
 1377|  48.2k|	new_obj_data = malloc(buf_len);
 1378|  48.2k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1378:6): [True: 0, False: 48.2k]
  ------------------
 1379|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1380|      0|	}
 1381|  48.2k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1382|  48.2k|				priv->nonce, sizeof(priv->nonce));
 1383|  48.2k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1383:6): [True: 44.9k, False: 3.33k]
  ------------------
 1384|  44.9k|		free(new_obj_data);
 1385|  44.9k|		if (r < 0) {
  ------------------
  |  Branch (1385:7): [True: 44.9k, False: 0]
  ------------------
 1386|  44.9k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  44.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  44.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  44.9k|	int _ret = r; \
  |  |  |  |  155|  44.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 44.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  44.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|  44.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 44.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  44.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  44.9k|	} else { \
  |  |  |  |  159|      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.9k|	return _ret; \
  |  |  |  |  163|  44.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1387|  44.9k|		}
 1388|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_CORRUPTED_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1389|      0|	}
 1390|  3.33k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1391|  3.33k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1391:6): [True: 0, False: 3.33k]
  ------------------
 1392|      0|		free(new_obj_data);
 1393|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1394|      0|	}
 1395|  3.33k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1395:6): [True: 0, False: 3.33k]
  ------------------
 1396|      0|		free(new_obj_data);
 1397|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1398|      0|	}
 1399|       |	/* Make sure we will not go over the allocated limits in the other
 1400|       |	 * objects if they somehow got different lengths in matching objects */
 1401|  3.33k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1401:6): [True: 0, False: 3.33k]
  ------------------
 1402|      0|		free(new_obj_data);
 1403|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1404|      0|	}
 1405|  3.33k|	obj_entry->data = new_obj_data;
 1406|  3.33k|	obj->data = new_obj_data;
 1407|  3.33k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.33k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.33k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.33k|	int _ret = r; \
  |  |  |  |  155|  3.33k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.33k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.33k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.33k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.33k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.33k|	} else { \
  |  |  |  |  159|      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.33k|	return _ret; \
  |  |  |  |  163|  3.33k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1408|  3.33k|}
coolkey_find_object_by_template:
 1497|  2.34k|{
 1498|  2.34k|	list_t *list;
 1499|  2.34k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1500|  2.34k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  2.34k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1501|  2.34k|	int i, r;
 1502|  2.34k|	unsigned int tmp_pos = (unsigned int) -1;
 1503|       |
 1504|  2.34k|	list = &priv->objects_list;
 1505|  2.34k|	if (list->iter_active) {
  ------------------
  |  Branch (1505:6): [True: 2.34k, False: 0]
  ------------------
 1506|       |		/* workaround missing functionality of second iterator */
 1507|  2.34k|		tmp_pos = list->iter_pos;
 1508|  2.34k|		list_iterator_stop(list);
 1509|  2.34k|	}
 1510|       |
 1511|  2.34k|	list_iterator_start(list);
 1512|  54.0k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1512:9): [True: 53.2k, False: 784]
  ------------------
 1513|  53.2k|		sc_cardctl_coolkey_attribute_t attribute;
 1514|  53.2k|		current = list_iterator_next(list);
 1515|  53.2k|		attribute.object = current;
 1516|       |
 1517|  60.6k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1517:13): [True: 59.0k, False: 1.56k]
  ------------------
 1518|  59.0k|			attribute.attribute_type = template[i].attribute_type;
 1519|  59.0k|			r = coolkey_find_attribute(card, &attribute);
 1520|  59.0k|			if (r < 0) {
  ------------------
  |  Branch (1520:8): [True: 34.4k, False: 24.5k]
  ------------------
 1521|  34.4k|				break;
 1522|  34.4k|			}
 1523|  24.5k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1523:8): [True: 187, False: 24.3k]
  ------------------
 1524|    187|				break;
 1525|    187|			}
 1526|  24.3k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1526:8): [True: 103, False: 24.2k]
  ------------------
 1527|    103|				break;
 1528|    103|			}
 1529|  24.2k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1529:8): [True: 16.9k, False: 7.38k]
  ------------------
 1530|  24.2k|							attribute.attribute_length) != 0) {
 1531|  16.9k|				break;
 1532|  16.9k|			}
 1533|  24.2k|		}
 1534|       |		/* just return the first one */
 1535|  53.2k|		if (i == count) {
  ------------------
  |  Branch (1535:7): [True: 1.56k, False: 51.6k]
  ------------------
 1536|  1.56k|			rv = current;
 1537|  1.56k|			break;
 1538|  1.56k|		}
 1539|  53.2k|	}
 1540|       |
 1541|  2.34k|	list_iterator_stop(list);
 1542|  2.34k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1542:6): [True: 2.34k, False: 0]
  ------------------
 1543|       |		/* workaround missing functionality of second iterator */
 1544|  2.34k|		list_iterator_start(list);
 1545|  45.8k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1545:10): [True: 45.6k, False: 145]
  |  Branch (1545:41): [True: 43.5k, False: 2.19k]
  ------------------
 1546|  43.5k|			(void) list_iterator_next(list);
 1547|  2.34k|	}
 1548|  2.34k|	return rv;
 1549|  2.34k|}
sc_get_coolkey_driver:
 2469|  16.9k|{
 2470|  16.9k|	return sc_get_driver();
 2471|  16.9k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  518|    624|{
  519|       |	/* we need to manually detect types CK_ULONG */
  520|    624|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|    624|#define COOLKEY_V0_OBJECT 0
  ------------------
  521|    624|	int r;
  522|    624|	size_t len;
  523|       |
  524|    624|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|    624|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  525|    624|	attr_out->attribute_length = 0;
  526|    624|	attr_out->attribute_value = NULL;
  527|       |
  528|    624|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  529|    624|	if (r < 0) {
  ------------------
  |  Branch (529:6): [True: 0, False: 624]
  ------------------
  530|      0|		return r;
  531|      0|	}
  532|    624|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (532:6): [True: 219, False: 405]
  ------------------
  533|    219|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    219|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  534|    219|	}
  535|    405|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    405|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     16|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (535:6): [True: 389, False: 16]
  |  Branch (535:34): [True: 0, False: 16]
  ------------------
  536|    392|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     16|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (536:14): [True: 3, False: 13]
  ------------------
  537|    392|		if (len != 4) {
  ------------------
  |  Branch (537:7): [True: 346, False: 46]
  ------------------
  538|    346|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    346|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  539|    346|		}
  540|     46|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|     46|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  541|     46|	}
  542|       |	/* return the length and the data */
  543|     59|	attr_out->attribute_length = len;
  544|     59|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  545|     59|	return SC_SUCCESS;
  ------------------
  |  |   28|     59|#define SC_SUCCESS				0
  ------------------
  546|    405|}
card-coolkey.c:coolkey_get_attribute_type:
  411|  54.1k|{
  412|  54.1k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  413|       |
  414|  54.1k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  415|  54.1k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  351|  5.88k|{
  352|  5.88k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  353|       |	/* don't reference beyond our buffer */
  354|  5.88k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (354:6): [True: 358, False: 5.52k]
  ------------------
  355|    358|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    358|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  356|    358|	}
  357|  5.52k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  358|  5.52k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.52k|#define SC_SUCCESS				0
  ------------------
  359|  5.88k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  553|  3.91k|{
  554|  3.91k|	int r;
  555|  3.91k|	size_t len;
  556|  3.91k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  557|       |
  558|  3.91k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (558:6): [True: 68, False: 3.84k]
  ------------------
  559|     68|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     68|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  560|     68|	}
  561|       |
  562|       |	/* we must have type V1. Process according to data type */
  563|  3.84k|	switch (attribute_head->attribute_data_type) {
  564|       |	/* ULONG has implied length of 4 */
  565|    275|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|    275|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (565:2): [True: 275, False: 3.57k]
  ------------------
  566|    275|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (566:7): [True: 18, False: 257]
  ------------------
  567|     18|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     18|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  568|     18|		}
  569|    257|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|    257|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  570|    257|		attr_out->attribute_length = 4;
  571|    257|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  572|    257|		return SC_SUCCESS;
  ------------------
  |  |   28|    257|#define SC_SUCCESS				0
  ------------------
  573|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  574|       |	/* return type STRING for BOOLS */
  575|     79|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|     79|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (575:2): [True: 79, False: 3.76k]
  ------------------
  576|     79|		attr_out->attribute_length = 1;
  577|     79|		attr_out->attribute_value =  &coolkey_static_false;
  578|     79|		return SC_SUCCESS;
  ------------------
  |  |   28|     79|#define SC_SUCCESS				0
  ------------------
  579|     76|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|     76|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (579:2): [True: 76, False: 3.76k]
  ------------------
  580|     76|		attr_out->attribute_length = 1;
  581|     76|		attr_out->attribute_value =  &coolkey_static_true;
  582|     76|		return SC_SUCCESS;
  ------------------
  |  |   28|     76|#define SC_SUCCESS				0
  ------------------
  583|       |	/* string type has encoded length */
  584|  1.84k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|  1.84k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (584:2): [True: 1.84k, False: 1.99k]
  ------------------
  585|  1.84k|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  586|  1.84k|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|  1.84k|#define SC_SUCCESS				0
  ------------------
  |  Branch (586:7): [True: 42, False: 1.80k]
  ------------------
  587|     42|			return r;
  588|     42|		}
  589|  1.80k|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (589:7): [True: 334, False: 1.47k]
  ------------------
  590|    334|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    334|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  591|    334|		}
  592|  1.47k|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  593|  1.47k|		attr_out->attribute_length = len;
  594|  1.47k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.47k|#define SC_SUCCESS				0
  ------------------
  595|  1.56k|	default:
  ------------------
  |  Branch (595:2): [True: 1.56k, False: 2.27k]
  ------------------
  596|  1.56k|		break;
  597|  3.84k|	}
  598|  1.56k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  1.56k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  599|  3.84k|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  314|   128k|{
  315|   128k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  316|       |
  317|   128k|	*len = 0;
  318|       |	/* don't reference beyond our buffer */
  319|   128k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (319:6): [True: 74.2k, False: 53.7k]
  ------------------
  320|  74.2k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  74.2k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  321|  74.2k|	}
  322|  53.7k|	switch (attribute_head->attribute_data_type) {
  323|  17.4k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|  17.4k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (323:2): [True: 17.4k, False: 36.3k]
  ------------------
  324|  17.4k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (324:7): [True: 320, False: 17.1k]
  ------------------
  325|    320|			break;
  326|    320|		}
  327|  17.1k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  328|  17.1k|		if (encoded_len) {
  ------------------
  |  Branch (328:7): [True: 15.3k, False: 1.80k]
  ------------------
  329|  15.3k|			*len += 2;
  330|  15.3k|		}
  331|  17.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  17.1k|#define SC_SUCCESS				0
  ------------------
  332|  1.31k|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|  1.31k|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (332:2): [True: 1.31k, False: 52.4k]
  ------------------
  333|  7.41k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|  7.41k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (333:2): [True: 6.09k, False: 47.6k]
  ------------------
  334|       |		/* NOTE: there is no encoded data from TYPE_BOOL_XXX, so we return length 0, but the length
  335|       |		 * of the attribute is actually 1 byte, so if encoded_len == false, return 1 */
  336|  7.41k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (336:10): [True: 7.41k, False: 0]
  ------------------
  337|  7.41k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.41k|#define SC_SUCCESS				0
  ------------------
  338|      0|		break;
  339|  4.98k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|  4.98k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (339:2): [True: 4.98k, False: 48.8k]
  ------------------
  340|  4.98k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  341|  4.98k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.98k|#define SC_SUCCESS				0
  ------------------
  342|  23.9k|	default:
  ------------------
  |  Branch (342:2): [True: 23.9k, False: 29.8k]
  ------------------
  343|  23.9k|		break;
  344|  53.7k|	}
  345|  24.2k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  24.2k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  346|  53.7k|}
card-coolkey.c:coolkey_read_object:
 1097|  48.6k|{
 1098|  48.6k|	coolkey_read_object_param_t params;
 1099|  48.6k|	u8 *out_ptr;
 1100|  48.6k|	size_t left = 0;
 1101|  48.6k|	size_t len;
 1102|  48.6k|	int r;
 1103|       |
 1104|  48.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  48.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  48.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  48.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 48.6k]
  |  |  ------------------
  ------------------
 1105|       |
 1106|  48.6k|	ulong2bebytes(&params.object_id[0], object_id);
 1107|       |
 1108|  48.6k|	out_ptr = out_buf;
 1109|  48.6k|	left = out_len;
 1110|  60.8k|	do {
 1111|  60.8k|		ulong2bebytes(&params.offset[0], offset);
 1112|  60.8k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   69|  60.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 47.3k, False: 13.4k]
  |  |  ------------------
  ------------------
 1113|  60.8k|		len = left;
 1114|  60.8k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   73|  60.8k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   89|  60.8k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1115|  60.8k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1116|  60.8k|		if (r < 0) {
  ------------------
  |  Branch (1116:7): [True: 42.8k, False: 17.9k]
  ------------------
 1117|  42.8k|			goto fail;
 1118|  42.8k|		}
 1119|       |		/* sanity check to make sure we don't overflow left */
 1120|  17.9k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1120:7): [True: 736, False: 17.1k]
  |  Branch (1120:23): [True: 1.43k, False: 15.7k]
  ------------------
 1121|  2.17k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.17k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1122|  2.17k|			goto fail;
 1123|  2.17k|		}
 1124|  15.7k|		out_ptr += len;
 1125|  15.7k|		offset += len;
 1126|  15.7k|		left -= len;
 1127|  15.7k|	} while (left != 0);
  ------------------
  |  Branch (1127:11): [True: 12.1k, False: 3.58k]
  ------------------
 1128|       |
 1129|  3.58k|	return (int)out_len;
 1130|       |
 1131|  45.0k|fail:
 1132|  45.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  45.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  45.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  45.0k|	int _ret = r; \
  |  |  |  |  155|  45.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  45.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  45.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  45.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  45.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  45.0k|	return _ret; \
  |  |  |  |  163|  45.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1133|  45.0k|}
card-coolkey.c:coolkey_apdu_io:
  913|  89.0k|{
  914|  89.0k|	int r;
  915|  89.0k|	sc_apdu_t apdu;
  916|  89.0k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  917|  89.0k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  918|  89.0k|	u8 *rbuf;
  919|  89.0k|	size_t rbuflen;
  920|  89.0k|	int cse = 0;
  921|       |
  922|       |
  923|  89.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  89.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  89.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  89.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 89.0k]
  |  |  ------------------
  ------------------
  924|       |
  925|  89.0k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  89.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  926|  89.0k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  927|       |
  928|  89.0k|	rbuf = rbufinitbuf;
  929|  89.0k|	rbuflen = sizeof(rbufinitbuf);
  930|       |
  931|       |	/* if caller provided a buffer and length */
  932|  89.0k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (932:6): [True: 76.1k, False: 12.9k]
  |  Branch (932:17): [True: 76.1k, False: 0]
  |  Branch (932:29): [True: 76.1k, False: 0]
  |  Branch (932:43): [True: 70.8k, False: 5.29k]
  ------------------
  933|  70.8k|		rbuf = *recvbuf;
  934|  70.8k|		rbuflen = *recvbuflen;
  935|  70.8k|	}
  936|       |
  937|  89.0k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (937:6): [True: 73.9k, False: 15.1k]
  |  Branch (937:17): [True: 0, False: 15.1k]
  ------------------
  938|  73.9k|		if (recvbuf) {
  ------------------
  |  Branch (938:7): [True: 60.9k, False: 12.9k]
  ------------------
  939|  60.9k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  60.9k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  940|  60.9k|		} else {
  941|  12.9k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  12.9k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  942|  12.9k|		}
  943|  73.9k|	} else {
  944|  15.1k|		if (recvbuf) {
  ------------------
  |  Branch (944:7): [True: 15.1k, False: 0]
  ------------------
  945|  15.1k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  15.1k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  946|  15.1k|		} else {
  947|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  948|      0|		}
  949|  15.1k|	}
  950|       |
  951|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  952|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  953|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  954|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  955|       |	 * and we should be fine */
  956|  89.0k|	if (nonce) {
  ------------------
  |  Branch (956:6): [True: 62.7k, False: 26.3k]
  ------------------
  957|  62.7k|		u8 *buf = rsendbuf;
  958|  62.7k|		if (sendbuf) {
  ------------------
  |  Branch (958:7): [True: 62.7k, False: 0]
  ------------------
  959|  62.7k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   69|  62.7k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 62.7k, False: 0]
  |  |  ------------------
  ------------------
  960|  62.7k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  961|  62.7k|			buf += sendbuflen;
  962|  62.7k|		}
  963|  62.7k|		memcpy(buf, nonce, nonce_len);
  964|  62.7k|		sendbuflen += nonce_len;
  965|  62.7k|		sendbuf =rsendbuf;
  966|  62.7k|	}
  967|       |
  968|  89.0k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  969|       |
  970|  89.0k|	apdu.lc = sendbuflen;
  971|  89.0k|	apdu.datalen = sendbuflen;
  972|  89.0k|	apdu.data = sendbuf;
  973|       |
  974|       |
  975|       |	/* coolkey uses non-standard classes */
  976|  89.0k|	apdu.cla = cla;
  977|       |
  978|  89.0k|	if (recvbuf) {
  ------------------
  |  Branch (978:6): [True: 76.1k, False: 12.9k]
  ------------------
  979|  76.1k|		apdu.resp = rbuf;
  980|  76.1k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (980:13): [True: 17.3k, False: 58.7k]
  ------------------
  981|  76.1k|		apdu.resplen = rbuflen;
  982|  76.1k|	} else {
  983|  12.9k|		 apdu.resp =  rbuf;
  984|  12.9k|		 apdu.le = 0;
  985|  12.9k|		 apdu.resplen = 0;
  986|  12.9k|	}
  987|       |
  988|  89.0k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  89.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  989|  89.0k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  990|       |
  991|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  992|  89.0k|	r = sc_transmit_apdu(card, &apdu);
  993|       |
  994|  89.0k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  89.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  995|  89.0k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  996|       |
  997|  89.0k|	if (r < 0) {
  ------------------
  |  Branch (997:6): [True: 1.02k, False: 88.0k]
  ------------------
  998|  1.02k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  1.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  999|  1.02k|		goto err;
 1000|  1.02k|	}
 1001|  88.0k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1002|  88.0k|	if (r < 0) {
  ------------------
  |  Branch (1002:6): [True: 50.8k, False: 37.1k]
  ------------------
 1003|  50.8k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  50.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__
  |  |  ------------------
  ------------------
 1004|  50.8k|		goto err;
 1005|  50.8k|	}
 1006|       |
 1007|  37.1k|	if (recvbuflen) {
  ------------------
  |  Branch (1007:6): [True: 32.2k, False: 4.92k]
  ------------------
 1008|  32.2k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1008:7): [True: 32.1k, False: 72]
  |  Branch (1008:18): [True: 0, False: 32.1k]
  ------------------
 1009|      0|			*recvbuf =  malloc(apdu.resplen);
 1010|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1010:8): [True: 0, False: 0]
  ------------------
 1011|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1012|      0|				goto err;
 1013|      0|			}
 1014|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1015|      0|		}
 1016|  32.2k|		*recvbuflen =  apdu.resplen;
 1017|  32.2k|		r = (int)*recvbuflen;
 1018|  32.2k|	}
 1019|       |
 1020|  89.0k|err:
 1021|  89.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  89.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  89.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  89.0k|	int _ret = r; \
  |  |  |  |  155|  89.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58.3k, False: 30.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  58.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|  51.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51.8k, False: 6.48k]
  |  |  |  |  ------------------
  |  |  |  |  157|  58.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  58.3k|	} else { \
  |  |  |  |  159|  30.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  30.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  30.7k|	} \
  |  |  |  |  162|  89.0k|	return _ret; \
  |  |  |  |  163|  89.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1022|  89.0k|}
card-coolkey.c:coolkey_find_object_by_id:
  826|  18.8k|{
  827|  18.8k|	int pos;
  828|  18.8k|	static sc_cardctl_coolkey_object_t cmp = {{
  829|  18.8k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  18.8k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  830|  18.8k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  18.8k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  18.8k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  831|  18.8k|	}, 0, 0, NULL};
  832|       |
  833|  18.8k|	cmp.id = object_id;
  834|  18.8k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (834:6): [True: 11.0k, False: 7.77k]
  ------------------
  835|  11.0k|		return NULL;
  836|       |
  837|  7.77k|	return list_get_at(list, pos);
  838|  18.8k|}
card-coolkey.c:coolkey_find_attribute:
 1417|   131k|{
 1418|   131k|	u8 object_record_type;
 1419|   131k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1420|   131k|	const u8 *obj = attribute->object->data;
 1421|   131k|	const u8 *attr = NULL;
 1422|   131k|	size_t buf_len = attribute->object->length;
 1423|   131k|	coolkey_object_header_t *object_head;
 1424|   131k|	int attribute_count,i;
 1425|   131k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|   131k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1426|   131k|	attribute->attribute_length = 0;
 1427|   131k|	attribute->attribute_value = NULL;
 1428|       |
 1429|   131k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   131k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   131k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   131k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   131k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 131k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1430|       |
 1431|   131k|	if (obj == NULL) {
  ------------------
  |  Branch (1431:6): [True: 48.1k, False: 83.1k]
  ------------------
 1432|       |		/* cast away const so we can cache the data value */
 1433|  48.1k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1434|  48.1k|		if (r < 0) {
  ------------------
  |  Branch (1434:7): [True: 44.8k, False: 3.32k]
  ------------------
 1435|  44.8k|			return r;
 1436|  44.8k|		}
 1437|  3.32k|		obj = attribute->object->data;
 1438|  3.32k|		if (obj == NULL) {
  ------------------
  |  Branch (1438:7): [True: 0, False: 3.32k]
  ------------------
 1439|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1440|      0|		}
 1441|  3.32k|	}
 1442|       |
 1443|       |	/* should be a static assert so we catch this at compile time */
 1444|   131k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1445|       |	/* make sure we have enough of the object to read the record_type */
 1446|  86.5k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1446:6): [True: 1.09k, False: 85.4k]
  ------------------
 1447|  1.09k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  1.09k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1448|  1.09k|	}
 1449|  85.4k|	object_head = (coolkey_object_header_t *)obj;
 1450|  85.4k|	object_record_type = object_head->record_type;
 1451|       |	/* make sure it's a type we recognize */
 1452|  85.4k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  85.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  10.3k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1452:6): [True: 10.3k, False: 75.0k]
  |  Branch (1452:51): [True: 7.14k, False: 3.20k]
  ------------------
 1453|  7.14k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  7.14k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1454|  7.14k|	}
 1455|       |
 1456|       |	/*
 1457|       |	 * now loop through all the attributes in the list. first find the start of the list
 1458|       |	 */
 1459|  78.2k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1460|  78.2k|	if (attr == NULL) {
  ------------------
  |  Branch (1460:6): [True: 206, False: 78.0k]
  ------------------
 1461|    206|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    206|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1462|    206|	}
 1463|  78.0k|	buf_len -= (attr-obj);
 1464|       |
 1465|       |	/* now get the count */
 1466|  78.0k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1467|   127k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1467:12): [True: 55.5k, False: 71.4k]
  ------------------
 1468|  55.5k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1469|       |		/* make sure we have the complete record */
 1470|  55.5k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1470:7): [True: 0, False: 55.5k]
  |  Branch (1470:31): [True: 2.06k, False: 53.4k]
  ------------------
 1471|  2.06k|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  2.06k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1472|  2.06k|		}
 1473|       |		/* does the attribute match the one we are looking for */
 1474|  53.4k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1474:7): [True: 4.53k, False: 48.9k]
  ------------------
 1475|       |			/* yup, return it */
 1476|  4.53k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1477|  4.53k|		}
 1478|       |		/* go to the next attribute on the list */
 1479|  48.9k|		buf_len -= record_len;
 1480|  48.9k|		attr += record_len;
 1481|  48.9k|	}
 1482|       |	/* not find in attribute list, check the fixed attribute record */
 1483|  71.4k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  71.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1483:6): [True: 68.8k, False: 2.58k]
  ------------------
 1484|  68.8k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1485|       |
 1486|  68.8k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1487|  68.8k|	}
 1488|  2.58k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  2.58k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.58k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.58k|	int _ret = r; \
  |  |  |  |  155|  2.58k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.58k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.58k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.58k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.58k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.58k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.58k|	} else { \
  |  |  |  |  159|      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.58k|	return _ret; \
  |  |  |  |  163|  2.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1489|  2.58k|}
card-coolkey.c:coolkey_attribute_start:
  422|  81.3k|{
  423|  81.3k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  230|  81.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (423:18): [True: 75.0k, False: 6.31k]
  ------------------
  424|  81.3k|			sizeof(coolkey_v0_object_header_t);
  425|       |
  426|  81.3k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  81.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  6.31k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (426:6): [True: 6.31k, False: 75.0k]
  |  Branch (426:51): [True: 0, False: 6.31k]
  ------------------
  427|      0|		return NULL;
  428|      0|	}
  429|  81.3k|	if (offset > buf_len) {
  ------------------
  |  Branch (429:6): [True: 206, False: 81.1k]
  ------------------
  430|    206|		return NULL;
  431|    206|	}
  432|  81.1k|	return obj + offset;
  433|  81.3k|}
card-coolkey.c:coolkey_get_attribute_count:
  503|  78.0k|{
  504|  78.0k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  78.0k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (504:6): [True: 3.20k, False: 74.8k]
  ------------------
  505|  3.20k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  506|  3.20k|	}
  507|  74.8k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  74.8k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (507:6): [True: 0, False: 74.8k]
  ------------------
  508|      0|		return 0;
  509|      0|	}
  510|  74.8k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  511|  74.8k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  441|  3.20k|{
  442|  3.20k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  443|  3.20k|	const u8 *attr;
  444|  3.20k|	int count = 0;
  445|  3.20k|	size_t attribute_data_len;
  446|       |
  447|       |	/* make sure we have enough of the object to read the record_type */
  448|  3.20k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (448:6): [True: 105, False: 3.10k]
  ------------------
  449|    105|		return 0;
  450|    105|	}
  451|       |	/*
  452|       |	 * now loop through all the attributes in the list. first find the start of the list
  453|       |	 */
  454|  3.10k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|  3.10k|#define COOLKEY_V0_OBJECT 0
  ------------------
  455|  3.10k|	if (attr == NULL) {
  ------------------
  |  Branch (455:6): [True: 0, False: 3.10k]
  ------------------
  456|      0|		return 0;
  457|      0|	}
  458|       |
  459|  3.10k|	buf_len -= (attr-obj);
  460|  3.10k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  461|  3.10k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (461:6): [True: 1.23k, False: 1.87k]
  ------------------
  462|  1.23k|		return 0;
  463|  1.23k|	}
  464|       |
  465|  4.27k|	while (attribute_data_len) {
  ------------------
  |  Branch (465:9): [True: 3.08k, False: 1.19k]
  ------------------
  466|  3.08k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  467|       |
  468|  3.08k|		if (len == 0) {
  ------------------
  |  Branch (468:7): [True: 0, False: 3.08k]
  ------------------
  469|      0|			break;
  470|      0|		}
  471|       |		/*  This is an error in the token data, don't parse the last attribute */
  472|  3.08k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (472:7): [True: 681, False: 2.40k]
  ------------------
  473|    681|			break;
  474|    681|		}
  475|       |		/* we know that coolkey_v0_get_attribute_record_len never
  476|       |		 * 	returns more than buf_len, so we can safely assert that.
  477|       |		 * 	If the assert is true, you can easily see that the loop
  478|       |		 * 	will eventually break with len == 0, even if attribute_data_len
  479|       |		 * 	was invalid */
  480|  2.40k|		if (len > buf_len)
  ------------------
  |  Branch (480:7): [True: 0, False: 2.40k]
  ------------------
  481|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  482|  2.40k|		count++;
  483|  2.40k|		attr += len;
  484|  2.40k|		buf_len -= len;
  485|  2.40k|		attribute_data_len -= len;
  486|  2.40k|	}
  487|  1.87k|	return count;
  488|  1.87k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  381|  5.25k|{
  382|  5.25k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  383|  5.25k|	size_t len;
  384|  5.25k|	int r;
  385|       |
  386|  5.25k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  387|  5.25k|	if (r < 0) {
  ------------------
  |  Branch (387:6): [True: 358, False: 4.90k]
  ------------------
  388|    358|		return buf_len; /* skip to the end, ignore the rest of the record */
  389|    358|	}
  390|  4.90k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  4.90k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.08k, False: 3.82k]
  |  |  ------------------
  ------------------
  391|  5.25k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  492|  74.8k|{
  493|  74.8k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  494|       |
  495|  74.8k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (495:6): [True: 25.3k, False: 49.5k]
  ------------------
  496|  25.3k|		return 0;
  497|  25.3k|	}
  498|  49.5k|	return bebytes2ushort(object_head->attribute_count);
  499|  74.8k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  395|  55.5k|{
  396|  55.5k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  55.5k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (396:6): [True: 2.17k, False: 53.3k]
  ------------------
  397|  2.17k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  398|  2.17k|	}
  399|  53.3k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  53.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (399:6): [True: 0, False: 53.3k]
  ------------------
  400|      0|		return buf_len; /* skip to the end */
  401|      0|	}
  402|  53.3k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  403|  53.3k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  365|   126k|{
  366|   126k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  367|   126k|	size_t len = 0;
  368|   126k|	int r;
  369|       |
  370|   126k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  371|   126k|	if (r < 0) {
  ------------------
  |  Branch (371:6): [True: 98.4k, False: 27.7k]
  ------------------
  372|  98.4k|		return buf_len; /* skip to the end, ignore the rest of the record */
  373|  98.4k|	}
  374|       |
  375|  27.7k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  27.7k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.66k, False: 26.0k]
  |  |  ------------------
  ------------------
  376|   126k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  675|  68.8k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  676|  68.8k|	unsigned long cka_id = fixed_attributes & 0xf;
  677|  68.8k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  678|  68.8k|	unsigned long mask, bit;
  679|       |
  680|  68.8k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  68.8k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (680:6): [True: 9.48k, False: 59.4k]
  ------------------
  681|  9.48k|		attr_out->attribute_length = 1;
  682|  9.48k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  683|  9.48k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.48k|#define SC_SUCCESS				0
  ------------------
  684|  9.48k|	}
  685|  59.4k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  59.4k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (685:6): [True: 22.2k, False: 37.1k]
  ------------------
  686|  22.2k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|  22.2k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  687|  22.2k|		attr_out->attribute_length = 4;
  688|  22.2k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  689|  22.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  22.2k|#define SC_SUCCESS				0
  ------------------
  690|  22.2k|	}
  691|       |	/* If it matched, it must be one of the booleans */
  692|  37.1k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  693|  37.1k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  694|       |	/* attribute isn't in the list */
  695|  37.1k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (695:6): [True: 14.7k, False: 22.4k]
  ------------------
  696|  14.7k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  14.7k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  697|  14.7k|	}
  698|  22.4k|	attr_out->attribute_length = 1;
  699|  22.4k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (699:30): [True: 7.46k, False: 14.9k]
  ------------------
  700|  22.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  22.4k|#define SC_SUCCESS				0
  ------------------
  701|  37.1k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  621|  37.1k|{
  622|  37.1k|	switch(type) {
  623|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (623:2): [True: 0, False: 37.1k]
  ------------------
  624|  2.46k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  2.46k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (624:2): [True: 2.46k, False: 34.7k]
  ------------------
  625|  3.37k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  3.37k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (625:2): [True: 3.37k, False: 33.8k]
  ------------------
  626|  1.76k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.76k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (626:2): [True: 1.76k, False: 35.4k]
  ------------------
  627|  1.76k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.76k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (627:2): [True: 1.76k, False: 35.4k]
  ------------------
  628|  1.76k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.76k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (628:2): [True: 1.76k, False: 35.4k]
  ------------------
  629|  1.76k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.76k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (629:2): [True: 1.76k, False: 35.4k]
  ------------------
  630|  1.76k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.76k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (630:2): [True: 1.76k, False: 35.4k]
  ------------------
  631|  1.76k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.76k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (631:2): [True: 1.76k, False: 35.4k]
  ------------------
  632|  1.76k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.76k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (632:2): [True: 1.76k, False: 35.4k]
  ------------------
  633|  1.76k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.76k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (633:2): [True: 1.76k, False: 35.4k]
  ------------------
  634|  1.76k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.76k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (634:2): [True: 1.76k, False: 35.4k]
  ------------------
  635|  1.76k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.76k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (635:2): [True: 1.76k, False: 35.4k]
  ------------------
  636|  1.76k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.76k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (636:2): [True: 1.76k, False: 35.4k]
  ------------------
  637|  1.76k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.76k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (637:2): [True: 1.76k, False: 35.4k]
  ------------------
  638|  1.76k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.76k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (638:2): [True: 1.76k, False: 35.4k]
  ------------------
  639|  1.76k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.76k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (639:2): [True: 1.76k, False: 35.4k]
  ------------------
  640|  6.67k|	default: break;
  ------------------
  |  Branch (640:2): [True: 6.67k, False: 30.5k]
  ------------------
  641|  37.1k|	}
  642|  6.67k|	return 0; /* return no bits */
  643|  37.1k|}
card-coolkey.c:sc_get_driver:
 2442|  16.9k|{
 2443|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2444|       |
 2445|  16.9k|	coolkey_ops = *iso_drv->ops;
 2446|  16.9k|	coolkey_ops.match_card = coolkey_match_card;
 2447|  16.9k|	coolkey_ops.init = coolkey_init;
 2448|  16.9k|	coolkey_ops.finish = coolkey_finish;
 2449|       |
 2450|  16.9k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2451|  16.9k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2452|  16.9k|	coolkey_ops.read_binary = coolkey_read_binary;
 2453|  16.9k|	coolkey_ops.write_binary = coolkey_write_binary;
 2454|  16.9k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2455|  16.9k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2456|  16.9k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2457|  16.9k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2458|  16.9k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2459|  16.9k|	coolkey_ops.check_sw = coolkey_check_sw;
 2460|  16.9k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2461|  16.9k|	coolkey_ops.logout = coolkey_logout;
 2462|  16.9k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2463|       |
 2464|  16.9k|	return &coolkey_drv;
 2465|  16.9k|}
card-coolkey.c:coolkey_match_card:
 2281|  7.55k|{
 2282|  7.55k|	int r;
 2283|       |
 2284|  7.55k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.55k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.55k]
  |  |  ------------------
  ------------------
 2285|       |
 2286|  7.55k|	r = coolkey_select_applet(card);
 2287|  7.55k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.55k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2287:6): [True: 1.38k, False: 6.17k]
  ------------------
 2288|  1.38k|		sc_apdu_t apdu;
 2289|       |
 2290|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2291|       |		 * on Coolkey applet (reserved for GetMemory function),
 2292|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2293|       |		 */
 2294|  1.38k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.38k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   80|  1.38k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2295|  1.38k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   73|  1.38k|#define COOLKEY_CLASS           0xb0
  ------------------
 2296|  1.38k|		apdu.le = 0x00;
 2297|  1.38k|		apdu.resplen = 0;
 2298|  1.38k|		apdu.resp = NULL;
 2299|  1.38k|		r = sc_transmit_apdu(card, &apdu);
 2300|  1.38k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.76k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2300:7): [True: 1.37k, False: 2]
  |  Branch (2300:26): [True: 1.09k, False: 285]
  |  Branch (2300:46): [True: 1.08k, False: 11]
  ------------------
 2301|  1.08k|			return 1;
 2302|  1.08k|		}
 2303|    298|		return 0;
 2304|  1.38k|	}
 2305|  6.17k|	return 0;
 2306|  7.55k|}
card-coolkey.c:coolkey_select_applet:
 1071|  11.1k|{
 1072|  11.1k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1073|  11.1k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   72|  11.1k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   76|  11.1k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1074|  11.1k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1075|  11.1k|}
card-coolkey.c:coolkey_init:
 2310|  1.08k|{
 2311|  1.08k|	int r;
 2312|  1.08k|	unsigned long flags;
 2313|  1.08k|	unsigned long ext_flags;
 2314|  1.08k|	coolkey_private_data_t * priv;
 2315|       |
 2316|  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]
  |  |  ------------------
  ------------------
 2317|       |
 2318|  1.08k|	r = coolkey_initialize(card);
 2319|  1.08k|	if (r < 0) {
  ------------------
  |  Branch (2319:6): [True: 413, False: 669]
  ------------------
 2320|    413|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    413|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    413|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    413|	int _ret = r; \
  |  |  |  |  155|    413|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 413, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    413|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    413|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 413, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    413|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    413|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    413|	return _ret; \
  |  |  |  |  163|    413|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2321|    413|	}
 2322|       |
 2323|    669|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2324|       |
 2325|       |	/* set Token Major/minor version */
 2326|    669|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    669|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2327|       |
 2328|    669|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2329|    669|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2330|    669|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2331|       |
 2332|    669|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    669|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    669|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    669|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    669|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2333|    669|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    669|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    669|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2334|       |
 2335|    669|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2336|    669|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2337|    669|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2338|       |
 2339|       |
 2340|    669|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    669|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2341|    669|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2341:6): [True: 377, False: 292]
  ------------------
 2342|    377|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    377|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2343|    377|	}
 2344|       |
 2345|    669|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 669]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2346|    669|}
card-coolkey.c:coolkey_initialize:
 2150|  1.08k|{
 2151|  1.08k|	int r;
 2152|  1.08k|	coolkey_private_data_t *priv = NULL;
 2153|  1.08k|	coolkey_life_cycle_t life_cycle;
 2154|  1.08k|	coolkey_object_info_t object_info;
 2155|  1.08k|	int combined_processed = 0;
 2156|       |
 2157|       |	/* already found? */
 2158|  1.08k|	if (card->drv_data) {
  ------------------
  |  Branch (2158:6): [True: 0, False: 1.08k]
  ------------------
 2159|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2160|      0|	}
 2161|  1.08k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.08k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2162|       |
 2163|  1.08k|	priv = coolkey_new_private_data();
 2164|  1.08k|	if (priv == NULL) {
  ------------------
  |  Branch (2164:6): [True: 0, False: 1.08k]
  ------------------
 2165|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2166|      0|		goto cleanup;
 2167|      0|	}
 2168|  1.08k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2169|  1.08k|	if (r < 0) {
  ------------------
  |  Branch (2169:6): [True: 73, False: 1.00k]
  ------------------
 2170|     73|		goto cleanup;
 2171|     73|	}
 2172|       |
 2173|       |	/* Select a coolkey read the coolkey objects out */
 2174|  1.00k|	r = coolkey_select_applet(card);
 2175|  1.00k|	if (r < 0) {
  ------------------
  |  Branch (2175:6): [True: 6, False: 1.00k]
  ------------------
 2176|      6|		goto cleanup;
 2177|      6|	}
 2178|       |
 2179|  1.00k|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2180|  1.00k|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2181|  1.00k|	priv->pin_count = life_cycle.pin_count;
 2182|  1.00k|	priv->life_cycle = life_cycle.life_cycle;
 2183|       |
 2184|       |	/* walk down the list of objects and read them off the token */
 2185|  1.00k|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  105|  1.00k|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2186|  13.9k|	while (r >= 0) {
  ------------------
  |  Branch (2186:9): [True: 13.1k, False: 853]
  ------------------
 2187|  13.1k|		unsigned long object_id;
 2188|  13.1k|		unsigned long object_len;
 2189|       |
 2190|       |		/* The card did not return what we expected: Lets try other objects */
 2191|  13.1k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2191:7): [True: 12, False: 13.1k]
  ------------------
 2192|     12|			break;
 2193|       |
 2194|       |		/* TODO also look at the ACL... */
 2195|       |
 2196|  13.1k|		object_id = bebytes2ulong(object_info.object_id);
 2197|  13.1k|		object_len = bebytes2ulong(object_info.object_length);
 2198|       |		/* Avoid insanely large data */
 2199|  13.1k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  13.1k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2199:7): [True: 13, False: 13.0k]
  ------------------
 2200|     13|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     13|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2201|     13|			goto cleanup;
 2202|     13|		}
 2203|       |
 2204|       |		/* the combined object is a single object that can store the other objects.
 2205|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2206|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2207|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2208|       |		 * process it separately so that we can have both combined objects managed
 2209|       |		 * by TPS and user managed certs on the same token */
 2210|  13.0k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  110|  13.0k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2210:7): [True: 252, False: 12.8k]
  ------------------
 2211|    252|			u8 *object = malloc(object_len);
 2212|    252|			if (object == NULL) {
  ------------------
  |  Branch (2212:8): [True: 0, False: 252]
  ------------------
 2213|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2214|      0|				break;
 2215|      0|			}
 2216|    252|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  110|    252|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2217|    252|				priv->nonce, sizeof(priv->nonce));
 2218|    252|			if (r < 0) {
  ------------------
  |  Branch (2218:8): [True: 57, False: 195]
  ------------------
 2219|     57|				free(object);
 2220|     57|				break;
 2221|     57|			}
 2222|    195|			r = coolkey_process_combined_object(card, priv, object, r);
 2223|    195|			free(object);
 2224|    195|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    195|#define SC_SUCCESS				0
  ------------------
  |  Branch (2224:8): [True: 68, False: 127]
  ------------------
 2225|     68|				break;
 2226|     68|			}
 2227|    127|			combined_processed = 1;
 2228|  12.8k|		} else {
 2229|  12.8k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  12.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2230|  12.8k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2231|  12.8k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  12.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2231:8): [True: 3.80k, False: 9.04k]
  ------------------
 2232|  3.80k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  3.80k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2233|  12.8k|		}
 2234|       |
 2235|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2236|  12.9k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  106|  12.9k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2237|  12.9k|	}
 2238|    990|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    990|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2238:6): [True: 306, False: 684]
  ------------------
 2239|       |		/* This means the card does not cooperate at all: bail out */
 2240|    306|		if (r >= 0) {
  ------------------
  |  Branch (2240:7): [True: 12, False: 294]
  ------------------
 2241|     12|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     12|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2242|     12|		}
 2243|    306|		goto cleanup;
 2244|    306|	}
 2245|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2246|    684|	if (!combined_processed) {
  ------------------
  |  Branch (2246:6): [True: 563, False: 121]
  ------------------
 2247|    563|		global_platform_cplc_data_t cplc_data;
 2248|       |		/* select the card manager, because a card with applet only will have
 2249|       |		   already selected the coolkey applet */
 2250|       |
 2251|    563|		r = gp_select_card_manager(card);
 2252|    563|		if (r < 0) {
  ------------------
  |  Branch (2252:7): [True: 2, False: 561]
  ------------------
 2253|      2|			goto cleanup;
 2254|      2|		}
 2255|       |
 2256|    561|		r = gp_get_cplc_data(card, &cplc_data);
 2257|    561|		if (r < 0) {
  ------------------
  |  Branch (2257:7): [True: 13, False: 548]
  ------------------
 2258|     13|			goto cleanup;
 2259|     13|		}
 2260|    548|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2261|    548|		priv->token_name = (u8 *)strdup("COOLKEY");
 2262|    548|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2262:7): [True: 0, False: 548]
  ------------------
 2263|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2264|      0|			goto cleanup;
 2265|      0|		}
 2266|    548|		priv->token_name_length = sizeof("COOLKEY")-1;
 2267|    548|	}
 2268|    669|	card->drv_data = priv;
 2269|    669|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 669]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2270|       |
 2271|    413|cleanup:
 2272|    413|	if (priv) {
  ------------------
  |  Branch (2272:6): [True: 413, False: 0]
  ------------------
 2273|    413|		coolkey_free_private_data(priv);
 2274|    413|	}
 2275|    413|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    413|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    413|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    413|	int _ret = r; \
  |  |  |  |  155|    413|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 413, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    413|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    413|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 413, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    413|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    413|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    413|	return _ret; \
  |  |  |  |  163|    413|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|    413|}
card-coolkey.c:coolkey_new_private_data:
  773|  1.08k|{
  774|  1.08k|	coolkey_private_data_t *priv;
  775|       |
  776|       |	/* allocate priv and zero all the fields */
  777|  1.08k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  778|  1.08k|	if (!priv)
  ------------------
  |  Branch (778:6): [True: 0, False: 1.08k]
  ------------------
  779|      0|		return NULL;
  780|       |
  781|       |	/* set other fields as appropriate */
  782|  1.08k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|  1.08k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  783|  1.08k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.08k]
  ------------------
  784|  1.08k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (784:6): [True: 0, False: 1.08k]
  ------------------
  785|  1.08k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (785:6): [True: 0, False: 1.08k]
  ------------------
  786|      0|		coolkey_free_private_data(priv);
  787|      0|		return NULL;
  788|      0|	}
  789|       |
  790|  1.08k|	return priv;
  791|  1.08k|}
card-coolkey.c:coolkey_get_life_cycle:
 1029|  1.08k|{
 1030|  1.08k|	coolkey_status_t status;
 1031|  1.08k|	u8 *receive_buf;
 1032|  1.08k|	size_t receive_len;
 1033|  1.08k|	int len;
 1034|       |
 1035|  1.08k|	receive_len = sizeof(*life_cycle);
 1036|  1.08k|	receive_buf = (u8 *)life_cycle;
 1037|  1.08k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|  1.08k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|  1.08k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1038|  1.08k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1039|  1.08k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1039:6): [True: 1.00k, False: 75]
  ------------------
 1040|  1.00k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.00k|#define SC_SUCCESS				0
  ------------------
 1041|  1.00k|	}
 1042|       |
 1043|     75|	receive_len = 1;
 1044|     75|	receive_buf = &life_cycle->life_cycle;
 1045|     75|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|     75|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|     75|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1046|     75|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1047|     75|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1047:6): [True: 60, False: 15]
  ------------------
 1048|     60|		return len;
 1049|     60|	}
 1050|     15|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1050:6): [True: 2, False: 13]
  ------------------
 1051|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1052|      2|	}
 1053|     13|	receive_len = sizeof(status);
 1054|     13|	receive_buf = (u8 *)&status;
 1055|     13|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   73|     13|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   80|     13|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1056|     13|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1057|     13|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1057:6): [True: 8, False: 5]
  ------------------
 1058|      8|		return len;
 1059|      8|	}
 1060|      5|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1060:6): [True: 3, False: 2]
  ------------------
 1061|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1062|      3|	}
 1063|      2|	life_cycle->protocol_version_major = status.protocol_version_major;
 1064|      2|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1065|      2|	life_cycle->pin_count = status.pin_count;
 1066|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 1067|      5|}
card-coolkey.c:coolkey_list_object:
 2137|  13.9k|{
 2138|  13.9k|	u8 *rbuf = (u8 *) object_info;
 2139|  13.9k|	size_t rbuflen = sizeof(*object_info);
 2140|       |
 2141|  13.9k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   73|  13.9k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   82|  13.9k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2142|  13.9k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2143|       |
 2144|  13.9k|}
card-coolkey.c:coolkey_process_combined_object:
 2001|    195|{
 2002|    195|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2003|    195|	unsigned short compressed_offset;
 2004|    195|	unsigned short compressed_length;
 2005|    195|	unsigned short compressed_type;
 2006|    195|	size_t object_offset;
 2007|    195|	unsigned short object_count;
 2008|    195|	coolkey_decompressed_header_t *decompressed_header;
 2009|    195|	u8 *decompressed_object = NULL;
 2010|    195|	size_t decompressed_object_len = 0;
 2011|    195|	int free_decompressed = 0;
 2012|    195|	int i, r;
 2013|       |
 2014|    195|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2014:6): [True: 1, False: 194]
  ------------------
 2015|      1|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2016|      1|	}
 2017|    194|	compressed_offset = bebytes2ushort(header->compression_offset);
 2018|    194|	compressed_length = bebytes2ushort(header->compression_length);
 2019|    194|	compressed_type   = bebytes2ushort(header->compression_type);
 2020|       |
 2021|    194|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2021:6): [True: 16, False: 178]
  ------------------
 2022|     16|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     16|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2023|     16|	}
 2024|       |
 2025|       |	/* store the CUID */
 2026|    178|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2027|       |
 2028|    178|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  181|    178|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2028:6): [True: 139, False: 39]
  ------------------
 2029|    139|#ifdef ENABLE_ZLIB
 2030|    139|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|    139|#define COMPRESSION_AUTO	0
  ------------------
 2031|    139|		if (r)
  ------------------
  |  Branch (2031:7): [True: 14, False: 125]
  ------------------
 2032|     14|			goto done;
 2033|    125|		free_decompressed = 1;
 2034|       |#else
 2035|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2036|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2037|       |#endif
 2038|    125|	}  else {
 2039|     39|		decompressed_object =&object[compressed_offset];
 2040|     39|		decompressed_object_len = (size_t) compressed_length;
 2041|     39|	}
 2042|       |
 2043|    164|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2044|       |
 2045|    164|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2045:6): [True: 9, False: 155]
  ------------------
 2046|      9|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      9|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2047|      9|		goto done;
 2048|      9|	}
 2049|    155|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2050|    155|	object_count = bebytes2ushort(decompressed_header->object_count);
 2051|       |
 2052|       |
 2053|       |	/*
 2054|       |	 * using 2 different tests here so we can log different errors if logging is
 2055|       |	 * turned on.
 2056|       |	 */
 2057|       |	/* make sure token_name doesn't overrun the buffer */
 2058|    155|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2058:6): [True: 0, False: 155]
  ------------------
 2059|    155|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2060|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2061|      0|		goto done;
 2062|      0|	}
 2063|       |	/* make sure it doesn't overlap the object space */
 2064|    155|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2064:6): [True: 8, False: 147]
  ------------------
 2065|    155|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2066|      8|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      8|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2067|      8|		goto done;
 2068|      8|	}
 2069|       |
 2070|       |	/* store the token name in the priv structure so the emulator can set it */
 2071|    147|	free(priv->token_name);
 2072|    147|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2073|    147|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2073:6): [True: 0, False: 147]
  ------------------
 2074|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2075|      0|		goto done;
 2076|      0|	}
 2077|    147|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2078|    147|							decompressed_header->token_name_length);
 2079|    147|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2080|    147|	priv->token_name_length = decompressed_header->token_name_length;
 2081|       |
 2082|    147|	if (object_count > decompressed_object_len / sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2082:6): [True: 10, False: 137]
  ------------------
 2083|     10|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     10|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2084|     10|		goto done;
 2085|     10|	}
 2086|       |
 2087|    924|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2087:12): [True: 797, False: 127]
  ------------------
 2088|    797|		u8 *current_object = NULL;
 2089|    797|		coolkey_combined_object_header_t *object_header = NULL;
 2090|    797|		unsigned long object_id;
 2091|    797|		int current_object_len;
 2092|       |
 2093|       |		/* Can we read the object header at all? */
 2094|    797|		if (decompressed_object_len < sizeof(coolkey_combined_object_header_t) ||
  ------------------
  |  Branch (2094:7): [True: 0, False: 797]
  ------------------
 2095|    797|		    object_offset > decompressed_object_len - sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2095:7): [True: 5, False: 792]
  ------------------
 2096|      5|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      5|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2097|      5|			goto done;
 2098|      5|		}
 2099|       |
 2100|    792|		current_object = &decompressed_object[object_offset];
 2101|    792|		object_header = (coolkey_combined_object_header_t *)current_object;
 2102|       |
 2103|       |		/* Parse object ID */
 2104|    792|		object_id = bebytes2ulong(object_header->object_id);
 2105|       |
 2106|       |		/* figure out how big it is */
 2107|    792|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2108|    792|		if (r < 0) {
  ------------------
  |  Branch (2108:7): [True: 0, False: 792]
  ------------------
 2109|      0|			goto done;
 2110|      0|		}
 2111|    792|		if ((size_t)r > decompressed_object_len - object_offset) {
  ------------------
  |  Branch (2111:7): [True: 0, False: 792]
  ------------------
 2112|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2113|      0|			goto done;
 2114|      0|		}
 2115|    792|		current_object_len = r;
 2116|    792|		object_offset += current_object_len;
 2117|       |
 2118|       |		/* record this object */
 2119|    792|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|    792|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2120|    792|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2121|    792|		if (r) {
  ------------------
  |  Branch (2121:7): [True: 5, False: 787]
  ------------------
 2122|      5|			goto done;
 2123|      5|		}
 2124|       |
 2125|    792|	}
 2126|    127|	r = SC_SUCCESS;
  ------------------
  |  |   28|    127|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|    178|done:
 2129|    178|	if (free_decompressed) {
  ------------------
  |  Branch (2129:6): [True: 125, False: 53]
  ------------------
 2130|    125|		free(decompressed_object);
 2131|    125|	}
 2132|    178|	return r;
 2133|    127|}
card-coolkey.c:coolkey_v1_get_object_length:
  707|    792|{
  708|    792|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  709|    792|	int attribute_count;
  710|    792|	u8 *current_attribute;
  711|    792|	int j;
  712|    792|	size_t len;
  713|       |
  714|    792|	len = sizeof(coolkey_combined_object_header_t);
  715|    792|	if (buf_len <= len) {
  ------------------
  |  Branch (715:6): [True: 1, False: 791]
  ------------------
  716|      1|		return (int)buf_len;
  717|      1|	}
  718|    791|	attribute_count = bebytes2ushort(object_head->attribute_count);
  719|    791|	buf_len -= len;
  720|       |
  721|  73.6k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (721:45): [True: 72.8k, False: 791]
  ------------------
  722|  72.8k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  723|       |
  724|  72.8k|		len += attribute_len;
  725|  72.8k|		current_attribute += attribute_len;
  726|  72.8k|		buf_len -= attribute_len;
  727|  72.8k|	}
  728|    791|	return (int)len;
  729|    792|}
card-coolkey.c:coolkey_add_object:
 1960|  13.6k|{
 1961|  13.6k|	sc_cardctl_coolkey_object_t new_object;
 1962|  13.6k|	int r;
 1963|       |
 1964|  13.6k|	memset(&new_object, 0, sizeof(new_object));
 1965|  13.6k|	new_object.path = coolkey_template_path;
 1966|  13.6k|	new_object.path.len = 4;
 1967|  13.6k|	ulong2bebytes(new_object.path.value, object_id);
 1968|  13.6k|	new_object.id = object_id;
 1969|  13.6k|	new_object.length = object_length;
 1970|       |
 1971|       |	/* The object ID needs to be unique */
 1972|  13.6k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1972:6): [True: 3.80k, False: 9.83k]
  ------------------
 1973|  3.80k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.80k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1974|  3.80k|	}
 1975|       |
 1976|  9.83k|	if (object_data) {
  ------------------
  |  Branch (1976:6): [True: 787, False: 9.04k]
  ------------------
 1977|    787|		new_object.data = malloc(object_length + add_v1_record);
 1978|    787|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1978:7): [True: 0, False: 787]
  ------------------
 1979|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1980|      0|		}
 1981|    787|		if (add_v1_record) {
  ------------------
  |  Branch (1981:7): [True: 787, False: 0]
  ------------------
 1982|    787|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  230|    787|#define COOLKEY_V1_OBJECT 1
  ------------------
 1983|    787|			new_object.length++;
 1984|    787|		}
 1985|    787|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1986|    787|	}
 1987|       |
 1988|  9.83k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 1989|  9.83k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  9.83k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1989:6): [True: 0, False: 9.83k]
  ------------------
 1990|       |		/* if we didn't successfully put the object on the list,
 1991|       |		 * the data space didn't get adopted. free it before we return */
 1992|      0|		free(new_object.data);
 1993|       |		new_object.data = NULL;
 1994|      0|	}
 1995|  9.83k|	return r;
 1996|  9.83k|}
card-coolkey.c:coolkey_add_object_to_list:
  817|  9.83k|{
  818|  9.83k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (818:6): [True: 0, False: 9.83k]
  ------------------
  819|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  820|  9.83k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.83k|#define SC_SUCCESS				0
  ------------------
  821|  9.83k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1079|    548|{
 1080|    548|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1081|    548|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1082|    548|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1083|    548|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1084|    548|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1085|    548|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1086|    548|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1087|    548|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1088|    548|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1089|    548|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1090|    548|}
card-coolkey.c:coolkey_free_private_data:
  794|  1.08k|{
  795|  1.08k|	list_t *l = &priv->objects_list;
  796|  1.08k|	sc_cardctl_coolkey_object_t *o;
  797|       |
  798|       |	/* Clean up the allocated memory in the items */
  799|  1.08k|	list_iterator_start(l);
  800|  10.9k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (800:9): [True: 9.83k, False: 1.08k]
  ------------------
  801|  9.83k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  802|  9.83k|		free(o->data);
  803|  9.83k|		o->data = NULL;
  804|  9.83k|	}
  805|  1.08k|	list_iterator_stop(l);
  806|       |
  807|  1.08k|	list_destroy(&priv->objects_list);
  808|  1.08k|	free(priv->token_name);
  809|  1.08k|	free(priv);
  810|  1.08k|	return;
  811|  1.08k|}
card-coolkey.c:coolkey_finish:
 1948|    669|{
 1949|    669|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    669|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1950|       |
 1951|    669|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    669|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    669|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    669|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 669]
  |  |  ------------------
  ------------------
 1952|    669|	if (priv) {
  ------------------
  |  Branch (1952:6): [True: 669, False: 0]
  ------------------
 1953|    669|		coolkey_free_private_data(priv);
 1954|    669|	}
 1955|    669|	return SC_SUCCESS;
  ------------------
  |  |   28|    669|#define SC_SUCCESS				0
  ------------------
 1956|    669|}
card-coolkey.c:coolkey_select_file:
 1901|  2.60k|{
 1902|  2.60k|	int r;
 1903|  2.60k|	struct sc_file *file = NULL;
 1904|  2.60k|	coolkey_private_data_t *priv;
 1905|  2.60k|	unsigned long object_id;
 1906|       |
 1907|  2.60k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1907:6): [True: 0, False: 2.60k]
  |  Branch (1907:22): [True: 0, False: 2.60k]
  ------------------
 1908|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1909|       |
 1910|  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]
  |  |  ------------------
  ------------------
 1911|       |
 1912|  2.60k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  2.60k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1913|       |
 1914|  2.60k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1914:6): [True: 1, False: 2.60k]
  ------------------
 1915|      1|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      1|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1916|      1|	}
 1917|  2.60k|	r = coolkey_select_applet(card);
 1918|  2.60k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.60k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1918:6): [True: 1.73k, False: 870]
  ------------------
 1919|  1.73k|		return r;
 1920|  1.73k|	}
 1921|    870|	object_id = bebytes2ulong(in_path->value);
 1922|    870|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1923|    870|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1923:6): [True: 542, False: 328]
  ------------------
 1924|    542|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    542|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1925|    542|	}
 1926|       |
 1927|    328|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|    328|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1928|    328|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  112|    328|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1928:6): [True: 291, False: 37]
  ------------------
 1929|    291|		priv->key_id = coolkey_get_key_id(object_id);
 1930|    291|	}
 1931|    328|	if (file_out) {
  ------------------
  |  Branch (1931:6): [True: 24, False: 304]
  ------------------
 1932|     24|		file = sc_file_new();
 1933|     24|		if (file == NULL)
  ------------------
  |  Branch (1933:7): [True: 0, False: 24]
  ------------------
 1934|     24|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1935|     24|		file->path = *in_path;
 1936|       |		/* this could be like the FCI */
 1937|     24|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     24|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1938|     24|		file->shareable = 0;
 1939|     24|		file->ef_structure = 0;
 1940|     24|		file->size = priv->obj->length;
 1941|     24|		*file_out = file;
 1942|     24|	}
 1943|       |
 1944|    328|	return SC_SUCCESS;
  ------------------
  |  |   28|    328|#define SC_SUCCESS				0
  ------------------
 1945|    328|}
card-coolkey.c:coolkey_class:
 1874|    328|static u8 coolkey_class(unsigned long object_id) {
 1875|    328|	return (object_id >> 24) & 0xff;
 1876|    328|}
card-coolkey.c:coolkey_get_key_id:
 1878|    291|static unsigned short coolkey_get_key_id(unsigned long object_id) {
 1879|    291|	char char_index = (object_id >> 16) & 0xff;
 1880|    291|	if (char_index >= '0' && char_index <= '9') {
  ------------------
  |  Branch (1880:6): [True: 278, False: 13]
  |  Branch (1880:27): [True: 212, False: 66]
  ------------------
 1881|    212|		return (u8)(char_index - '0');
 1882|    212|	}
 1883|     79|	if (char_index >= 'A' && char_index <= 'Z') {
  ------------------
  |  Branch (1883:6): [True: 66, False: 13]
  |  Branch (1883:27): [True: 50, False: 16]
  ------------------
 1884|     50|		return (u8)(char_index - 'A' + 10);
 1885|     50|	}
 1886|     29|	if (char_index >= 'a' && char_index <= 'z') {
  ------------------
  |  Branch (1886:6): [True: 16, False: 13]
  |  Branch (1886:27): [True: 10, False: 6]
  ------------------
 1887|     10|		return (u8)(char_index - 'a' + 26 + 10);
 1888|     10|	}
 1889|     19|	return COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|     19|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1890|     29|}
card-coolkey.c:coolkey_read_binary:
 1181|     54|{
 1182|     54|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|     54|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1183|     54|	int r = 0;
 1184|     54|	size_t len;
 1185|     54|	u8 *data = NULL;
 1186|       |
 1187|     54|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     54|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     54|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     54|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1188|     54|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1188:6): [True: 0, False: 54]
  ------------------
 1189|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_END_REACHED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|      0|	}
 1191|       |
 1192|       |	/* if we've already read the data, just return it */
 1193|     54|	if (priv->obj->data) {
  ------------------
  |  Branch (1193:6): [True: 32, False: 22]
  ------------------
 1194|     32|		sc_log(card->ctx, "returning cached value idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1195|     32|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|     32|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 25, False: 7]
  |  |  ------------------
  ------------------
 1196|     32|		memcpy(buf, &priv->obj->data[idx], len);
 1197|     32|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  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: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|     32|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     32|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     32|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1198|     32|	}
 1199|       |
 1200|     22|	sc_log(card->ctx, "clearing cache idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1201|       |
 1202|     22|	data = malloc(priv->obj->length);
 1203|     22|	if (data == NULL) {
  ------------------
  |  Branch (1203:6): [True: 0, False: 22]
  ------------------
 1204|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1205|      0|		goto done;
 1206|      0|	}
 1207|       |
 1208|       |
 1209|     22|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1210|     22|		priv->nonce, sizeof(priv->nonce));
 1211|     22|	if (r < 0)
  ------------------
  |  Branch (1211:6): [True: 14, False: 8]
  ------------------
 1212|     14|		goto done;
 1213|       |
 1214|      8|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1214:6): [True: 0, False: 8]
  ------------------
 1215|      0|		priv->obj->length = r;
 1216|      0|	}
 1217|       |
 1218|       |
 1219|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1220|      8|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|      8|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 7, False: 1]
  |  |  ------------------
  ------------------
 1221|      8|	memcpy(buf, &data[idx], len);
 1222|      8|	r = (int)len;
 1223|       |	/* cache the data in the object */
 1224|      8|	priv->obj->data=data;
 1225|      8|	data = NULL;
 1226|       |
 1227|     22|done:
 1228|     22|	if (data)
  ------------------
  |  Branch (1228:6): [True: 14, False: 8]
  ------------------
 1229|     14|		free(data);
 1230|     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: 14, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      8|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      8|	} \
  |  |  |  |  162|     22|	return _ret; \
  |  |  |  |  163|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1231|     22|}
card-coolkey.c:coolkey_set_security_env:
 1627|    303|{
 1628|    303|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    303|#define SC_SUCCESS				0
  ------------------
 1629|    303|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    303|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1630|       |
 1631|    303|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    303|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    303|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    303|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 303]
  |  |  ------------------
  ------------------
 1632|       |
 1633|    303|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1634|    303|			env->flags, env->operation, env->algorithm, env->algorithm_flags, env->algorithm_ref,
 1635|    303|			env->key_ref[0], env->key_ref_len);
 1636|       |
 1637|    303|	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   69|    303|#define SC_ALGORITHM_RSA		0
  ------------------
              	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1637:6): [True: 0, False: 303]
  |  Branch (1637:46): [True: 0, False: 0]
  ------------------
 1638|      0|		 r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1639|      0|	}
 1640|    303|	priv->algorithm = env->algorithm;
 1641|    303|	priv->operation = env->operation;
 1642|       |
 1643|    303|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    303|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    303|	int _ret = r; \
  |  |  155|    303|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 303, False: 0]
  |  |  ------------------
  |  |  156|    303|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 303]
  |  |  ------------------
  |  |  157|    303|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    303|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    303|	return _ret; \
  |  |  163|    303|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1644|    303|}
card-coolkey.c:coolkey_compute_crypt:
 1853|    303|{
 1854|    303|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    303|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1855|    303|	int r;
 1856|    303|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    303|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    303|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    303|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 303]
  |  |  ------------------
  ------------------
 1857|       |
 1858|    303|	switch (priv->algorithm) {
 1859|    303|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    303|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1859:2): [True: 303, False: 0]
  ------------------
 1860|    303|		r = coolkey_rsa_op(card, data, datalen, out, outlen);
 1861|    303|		break;
 1862|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1862:2): [True: 0, False: 303]
  ------------------
 1863|      0|		r = coolkey_ecc_op(card, data, datalen, out, outlen);
 1864|      0|		break;
 1865|      0|	default:
  ------------------
  |  Branch (1865:2): [True: 0, False: 303]
  ------------------
 1866|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1867|      0|		break;
 1868|    303|	}
 1869|       |
 1870|    303|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    303|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    303|	int _ret = r; \
  |  |  155|    303|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 284, False: 19]
  |  |  ------------------
  |  |  156|    284|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 9]
  |  |  ------------------
  |  |  157|    284|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    284|	} else { \
  |  |  159|     19|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     19|			"returning with: %d\n", _ret); \
  |  |  161|     19|	} \
  |  |  162|    303|	return _ret; \
  |  |  163|    303|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1871|    303|}
card-coolkey.c:coolkey_rsa_op:
 1675|    303|{
 1676|    303|	int r;
 1677|    303|	u8 **crypt_out_p = NULL;
 1678|    303|	size_t crypt_out_len_p = 0;
 1679|    303|	coolkey_private_data_t *priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    303|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1680|    303|	coolkey_compute_crypt_params_t params;
 1681|    303|	u8 key_number;
 1682|    303|	size_t params_len;
 1683|    303|	u8 buf[MAX_COMPUTE_BUF + 2];
 1684|    303|	size_t buf_len;
 1685|    303|	u8 *buf_out;
 1686|       |
 1687|    303|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    303|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    303|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    303|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 303]
  |  |  ------------------
  ------------------
 1688|    303|	sc_log(card->ctx, "datalen=%zu outlen=%zu\n", datalen, max_out_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1689|       |
 1690|    303|	if (datalen > 0xFFFF) {
  ------------------
  |  Branch (1690:6): [True: 0, False: 303]
  ------------------
 1691|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1692|      0|		goto done;
 1693|      0|	}
 1694|       |
 1695|    303|	if (priv->key_id > 0xff) {
  ------------------
  |  Branch (1695:6): [True: 31, False: 272]
  ------------------
 1696|     31|		r = SC_ERROR_NO_DEFAULT_KEY;
  ------------------
  |  |  106|     31|#define SC_ERROR_NO_DEFAULT_KEY			-1504
  ------------------
 1697|     31|		goto done;
 1698|     31|	}
 1699|    272|	key_number = priv->key_id;
 1700|       |
 1701|    272|	memset(&params, 0, sizeof(params));
 1702|    272|	params.init.mode = COOLKEY_CRYPT_MODE_RSA_NO_PAD;
  ------------------
  |  |   99|    272|#define COOLKEY_CRYPT_MODE_RSA_NO_PAD    0x00
  ------------------
 1703|    272|	params.init.direction = COOLKEY_CRYPT_DIRECTION_ENCRYPT; /* for no pad, direction is irrelevant */
  ------------------
  |  |  102|    272|#define COOLKEY_CRYPT_DIRECTION_ENCRYPT  0x03
  ------------------
 1704|       |
 1705|       |	/* send the data to the card if necessary */
 1706|    272|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1654|    272|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1706:6): [True: 142, False: 130]
  ------------------
 1707|       |		/* We need to write data to special object on the card as it does not safely fit APDU */
 1708|    142|		u8 len_buf[2];
 1709|       |
 1710|    142|		params.init.location = COOLKEY_CRYPT_LOCATION_DL_OBJECT;
  ------------------
  |  |  101|    142|#define COOLKEY_CRYPT_LOCATION_DL_OBJECT 0x02
  ------------------
 1711|       |
 1712|    142|		params_len = sizeof(params.init);
 1713|       |
 1714|    142|		ushort2bebytes(len_buf, datalen);
 1715|       |
 1716|    142|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  109|    142|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1717|    142|					priv->nonce, sizeof(priv->nonce));
 1718|    142|		if (r < 0) {
  ------------------
  |  Branch (1718:7): [True: 17, False: 125]
  ------------------
 1719|     17|			goto done;
 1720|     17|		}
 1721|       |
 1722|    125|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 2, data, datalen, priv->nonce, sizeof(priv->nonce));
  ------------------
  |  |  109|    125|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1723|    125|		if (r < 0) {
  ------------------
  |  Branch (1723:7): [True: 49, False: 76]
  ------------------
 1724|     49|			goto done;
 1725|     49|		}
 1726|     76|		ushort2bebytes(params.init.buf_len, 0);
 1727|    130|	} else {
 1728|       |		/* The data fits in APDU. Copy it to the params object */
 1729|    130|		params.init.location = COOLKEY_CRYPT_LOCATION_APDU;
  ------------------
  |  |  100|    130|#define COOLKEY_CRYPT_LOCATION_APDU      0x01
  ------------------
 1730|       |
 1731|    130|		params_len = sizeof(params.init) + datalen;
 1732|       |
 1733|    130|		buf_out = &buf[0];
 1734|    130|		crypt_out_p = &buf_out;
 1735|    130|		buf_len = sizeof(buf);
 1736|    130|		crypt_out_len_p = buf_len;
 1737|       |
 1738|    130|		ushort2bebytes(params.init.buf_len, datalen);
 1739|    130|		memcpy(params.buf, data, datalen);
 1740|    130|	}
 1741|       |
 1742|    206|	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   73|    206|#define COOLKEY_CLASS           0xb0
  ------------------
              	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   85|    206|#define COOLKEY_INS_COMPUTE_CRYPT              0x36
  ------------------
 1743|    206|			key_number, COOLKEY_CRYPT_ONE_STEP, (u8 *)&params, params_len,
  ------------------
  |  |   97|    206|#define COOLKEY_CRYPT_ONE_STEP 4
  ------------------
 1744|    206|			crypt_out_p, &crypt_out_len_p, priv->nonce, sizeof(priv->nonce));
 1745|    206|	if (r < 0) {
  ------------------
  |  Branch (1745:6): [True: 38, False: 168]
  ------------------
 1746|     38|		goto done;
 1747|     38|	}
 1748|    168|	buf_len = crypt_out_len_p;
 1749|       |
 1750|    168|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1654|    168|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1750:6): [True: 72, False: 96]
  ------------------
 1751|     72|		u8 len_buf[2];
 1752|     72|		size_t out_length;
 1753|       |
 1754|     72|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  109|     72|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1755|     72|					priv->nonce, sizeof(priv->nonce));
 1756|     72|		if (r < 0) {
  ------------------
  |  Branch (1756:7): [True: 36, False: 36]
  ------------------
 1757|     36|			goto done;
 1758|     36|		}
 1759|       |
 1760|     36|		out_length = bebytes2ushort(len_buf);
 1761|     36|		out_length = MIN(out_length,max_out_len);
  ------------------
  |  |   69|     36|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 35, False: 1]
  |  |  ------------------
  ------------------
 1762|       |
 1763|     36|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, sizeof(len_buf), out, out_length,
  ------------------
  |  |  109|     36|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1764|     36|					priv->nonce, sizeof(priv->nonce));
 1765|       |
 1766|     96|	} else {
 1767|     96|		size_t out_length;
 1768|     96|		if (buf_len < 2) {
  ------------------
  |  Branch (1768:7): [True: 46, False: 50]
  ------------------
 1769|     46|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     46|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1770|     46|			goto done;
 1771|     46|		}
 1772|     50|		out_length = bebytes2ushort(buf);
 1773|     50|		if (out_length > (buf_len - 2)) {
  ------------------
  |  Branch (1773:7): [True: 33, False: 17]
  ------------------
 1774|     33|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     33|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1775|     33|			goto done;
 1776|     33|		}
 1777|     17|		out_length = MIN(out_length, max_out_len);
  ------------------
  |  |   69|     17|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 17, False: 0]
  |  |  ------------------
  ------------------
 1778|     17|		memcpy(out, buf + 2, out_length);
 1779|     17|		r = (int)out_length;
 1780|     17|	}
 1781|       |
 1782|    303|done:
 1783|    303|	return r;
 1784|    168|}
card-coolkey.c:coolkey_write_object:
 1140|    267|{
 1141|    267|	coolkey_write_object_param_t params;
 1142|    267|	size_t operation_len;
 1143|    267|	size_t left = buf_len;
 1144|    267|	int r;
 1145|    267|	size_t max_operation_len;
 1146|       |
 1147|       |	/* set limit for the card's maximum send size and short write */
 1148|    267|	max_operation_len = MIN(COOLKEY_MAX_CHUNK_SIZE, (card->max_send_size - sizeof(coolkey_read_object_param_t) - nonce_size));
  ------------------
  |  |   69|    267|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 267]
  |  |  ------------------
  ------------------
 1149|       |
 1150|    267|	ulong2bebytes(&params.head.object_id[0], object_id);
 1151|       |
 1152|  1.73k|	do {
 1153|  1.73k|		ulong2bebytes(&params.head.offset[0], offset);
 1154|  1.73k|		operation_len = MIN(left, max_operation_len);
  ------------------
  |  |   69|  1.73k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 230, False: 1.50k]
  |  |  ------------------
  ------------------
 1155|  1.73k|		params.head.length = operation_len;
 1156|  1.73k|		memcpy(params.buf, buf, operation_len);
 1157|  1.73k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   73|  1.73k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   90|  1.73k|#define COOLKEY_INS_WRITE_OBJECT               0x54
  ------------------
 1158|  1.73k|			(u8 *)&params, sizeof(params.head)+operation_len, NULL, 0, nonce, nonce_size);
 1159|  1.73k|		if (r < 0) {
  ------------------
  |  Branch (1159:7): [True: 66, False: 1.67k]
  ------------------
 1160|     66|			goto fail;
 1161|     66|		}
 1162|  1.67k|		buf += operation_len;
 1163|  1.67k|		offset += operation_len;
 1164|  1.67k|		left -= operation_len;
 1165|  1.67k|	} while (left != 0);
  ------------------
  |  Branch (1165:11): [True: 1.47k, False: 201]
  ------------------
 1166|       |
 1167|    201|	return (int)(buf_len - left);
 1168|       |
 1169|     66|fail:
 1170|     66|	return r;
 1171|    267|}
card-coolkey.c:coolkey_card_ctl:
 1582|  86.5k|{
 1583|  86.5k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  86.5k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1584|       |
 1585|  86.5k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  86.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  86.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  86.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  86.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 86.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1586|  86.5k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  86.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1587|       |
 1588|  86.5k|	if (priv == NULL) {
  ------------------
  |  Branch (1588:6): [True: 0, False: 86.5k]
  ------------------
 1589|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1590|      0|	}
 1591|  86.5k|	switch(cmd) {
  ------------------
  |  Branch (1591:9): [True: 86.5k, False: 0]
  ------------------
 1592|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1592:3): [True: 0, False: 86.5k]
  ------------------
 1593|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1594|    669|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1594:3): [True: 669, False: 85.8k]
  ------------------
 1595|    669|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1596|  3.32k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1596:3): [True: 3.32k, False: 83.2k]
  ------------------
 1597|  3.32k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1598|    669|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1598:3): [True: 669, False: 85.8k]
  ------------------
 1599|    669|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1600|  8.88k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1600:3): [True: 8.88k, False: 77.6k]
  ------------------
 1601|  8.88k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1602|    669|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1602:3): [True: 669, False: 85.8k]
  ------------------
 1603|    669|			return coolkey_final_iterator(&priv->objects_list);
 1604|  72.3k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1604:3): [True: 72.3k, False: 14.2k]
  ------------------
 1605|  72.3k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1606|  86.5k|	}
 1607|       |
 1608|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1609|      0|}
card-coolkey.c:coolkey_get_token_info:
 1327|    669|{
 1328|    669|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    669|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1329|    669|	char *label = NULL;
 1330|    669|	char *manufacturer_id = NULL;
 1331|    669|	char *serial_number = NULL;
 1332|       |
 1333|    669|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    669|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    669|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    669|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    669|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 669]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1334|    669|	label = strdup((char *)priv->token_name);
 1335|    669|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1336|    669|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1337|       |
 1338|    669|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1338:6): [True: 669, False: 0]
  |  Branch (1338:15): [True: 669, False: 0]
  |  Branch (1338:34): [True: 669, False: 0]
  ------------------
 1339|    669|		free(token_info->label);
 1340|    669|		token_info->label = label;
 1341|    669|		free(token_info->manufacturer_id);
 1342|    669|		token_info->manufacturer_id = manufacturer_id;
 1343|    669|		free(token_info->serial_number);
 1344|    669|		token_info->serial_number = serial_number;
 1345|    669|		return SC_SUCCESS;
  ------------------
  |  |   28|    669|#define SC_SUCCESS				0
  ------------------
 1346|    669|	}
 1347|      0|	free(label);
 1348|      0|	free(manufacturer_id);
 1349|      0|	free(serial_number);
 1350|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1351|    669|}
card-coolkey.c:coolkey_get_manufacturer:
 1298|    669|{
 1299|    669|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1300|    669|	int i;
 1301|    669|	char *buf;
 1302|    669|	const char *manufacturer_string = "%04x Unknown";
 1303|    669|	size_t len;
 1304|    669|	int r;
 1305|       |
 1306|  3.99k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1306:12): [True: 3.34k, False: 652]
  ------------------
 1307|  3.34k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1307:7): [True: 17, False: 3.32k]
  ------------------
 1308|     17|			manufacturer_string = manufacturer_list[i].string;
 1309|     17|			break;
 1310|     17|		}
 1311|  3.34k|	}
 1312|    669|	len = strlen(manufacturer_string)+1;
 1313|    669|	buf= malloc(len);
 1314|    669|	if (buf == NULL) {
  ------------------
  |  Branch (1314:6): [True: 0, False: 669]
  ------------------
 1315|      0|		return NULL;
 1316|      0|	}
 1317|    669|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1318|    669|	if (r < 0) {
  ------------------
  |  Branch (1318:6): [True: 0, False: 669]
  ------------------
 1319|      0|		free(buf);
 1320|      0|		return NULL;
 1321|      0|	}
 1322|    669|	return buf;
 1323|    669|}
card-coolkey.c:coolkey_cuid_to_string:
 1273|    669|{
 1274|    669|	char *buf;
 1275|    669|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1276|    669|	buf = malloc(len);
 1277|    669|	if (buf == NULL) {
  ------------------
  |  Branch (1277:6): [True: 0, False: 669]
  ------------------
 1278|      0|		return NULL;
 1279|      0|	}
 1280|    669|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1281|    669|	return buf;
 1282|    669|}
card-coolkey.c:coolkey_find_object:
 1553|  3.32k|{
 1554|  3.32k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1555|  3.32k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  3.32k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1556|  3.32k|	int r;
 1557|       |
 1558|  3.32k|	switch (fobj->type) {
 1559|    978|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1079|    978|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1559:2): [True: 978, False: 2.34k]
  ------------------
 1560|    978|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1561|    978|		break;
 1562|  2.34k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1080|  2.34k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1562:2): [True: 2.34k, False: 978]
  ------------------
 1563|  2.34k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1564|  2.34k|		break;
 1565|      0|	default:
  ------------------
  |  Branch (1565:2): [True: 0, False: 3.32k]
  ------------------
 1566|      0|		break;
 1567|  3.32k|	}
 1568|  3.32k|	if (obj == NULL) {
  ------------------
  |  Branch (1568:6): [True: 1.46k, False: 1.85k]
  ------------------
 1569|  1.46k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  1.46k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1570|  1.46k|	}
 1571|  1.85k|	if (obj->data == NULL) {
  ------------------
  |  Branch (1571:6): [True: 80, False: 1.77k]
  ------------------
 1572|     80|		r = coolkey_fill_object(card, obj);
 1573|     80|		if (r < 0) {
  ------------------
  |  Branch (1573:7): [True: 62, False: 18]
  ------------------
 1574|     62|			return r;
 1575|     62|		}
 1576|     80|	}
 1577|  1.79k|	fobj->obj = obj;
 1578|  1.79k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.79k|#define SC_SUCCESS				0
  ------------------
 1579|  1.85k|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1246|    669|{
 1247|    669|	*countp = list_size(list);
 1248|    669|	list_iterator_start(list);
 1249|    669|	return SC_SUCCESS;
  ------------------
  |  |   28|    669|#define SC_SUCCESS				0
  ------------------
 1250|    669|}
card-coolkey.c:coolkey_fetch_object:
 1254|  8.88k|{
 1255|  8.88k|	sc_cardctl_coolkey_object_t *ptr;
 1256|  8.88k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1256:6): [True: 0, False: 8.88k]
  ------------------
 1257|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1258|      0|	}
 1259|       |
 1260|  8.88k|	ptr = list_iterator_next(list);
 1261|  8.88k|	*coolkey_obj = *ptr;
 1262|  8.88k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.88k|#define SC_SUCCESS				0
  ------------------
 1263|  8.88k|}
card-coolkey.c:coolkey_final_iterator:
 1267|    669|{
 1268|    669|	list_iterator_stop(list);
 1269|    669|	return SC_SUCCESS;
  ------------------
  |  |   28|    669|#define SC_SUCCESS				0
  ------------------
 1270|    669|}
card-coolkey.c:coolkey_check_sw:
  877|  91.2k|{
  878|  91.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  91.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  879|  91.2k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  880|       |
  881|  91.2k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (881:6): [True: 42.4k, False: 48.7k]
  |  Branch (881:21): [True: 39.4k, False: 3.04k]
  ------------------
  882|  39.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  39.4k|#define SC_SUCCESS				0
  ------------------
  883|       |
  884|  51.8k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (884:6): [True: 1.01k, False: 50.8k]
  ------------------
  885|  1.01k|		if (sw2 == 0xff) {
  ------------------
  |  Branch (885:7): [True: 6, False: 1.00k]
  ------------------
  886|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  887|      6|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      6|#define SC_ERROR_INTERNAL			-1400
  ------------------
  888|      6|		}
  889|  1.00k|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (889:7): [True: 36, False: 970]
  ------------------
  890|     36|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     36|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  891|     36|		}
  892|    970|		return coolkey_error_codes[sw2].sc_error;
  893|  1.00k|	}
  894|       |
  895|       |	/* iso error */
  896|  50.8k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  897|  51.8k|}
card-coolkey.c:coolkey_pin_cmd:
 2351|    706|{
 2352|    706|	int r;
 2353|    706|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    706|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2354|    706|	size_t rbuflen;
 2355|    706|	u8 *rbuf;
 2356|       |
 2357|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2358|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2359|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2360|       |	 * maintain separate per application login states without the application
 2361|       |	 * having to cache the pin */
 2362|    706|	switch (data->cmd) {
 2363|    669|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    669|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2363:2): [True: 669, False: 37]
  ------------------
 2364|    669|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2364:7): [True: 8, False: 661]
  ------------------
 2365|      8|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      8|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2366|    661|		} else {
 2367|    661|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|    661|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2368|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2369|       |			 * instead, coolkey slows down the login command exponentially
 2370|       |			 */
 2371|    661|			data->pin1.tries_left = 0xf;
 2372|    661|		}
 2373|    669|		r = SC_SUCCESS;
  ------------------
  |  |   28|    669|#define SC_SUCCESS				0
  ------------------
 2374|    669|		break;
 2375|       |
 2376|      9|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      9|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2376:2): [True: 9, False: 697]
  ------------------
 2377|     18|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     18|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2377:2): [True: 9, False: 697]
  ------------------
 2378|       |		/* these 2 commands are currently reserved for TPS */
 2379|     18|	default:
  ------------------
  |  Branch (2379:2): [True: 0, False: 706]
  ------------------
 2380|     18|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     18|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2381|     18|		break;
 2382|     19|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     19|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2382:2): [True: 19, False: 687]
  ------------------
 2383|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2384|       |		 * just support the one pin for now (we need an array of nonces to handle
 2385|       |		 * multiple pins) */
 2386|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2387|     19|		rbuflen = sizeof(priv->nonce);
 2388|     19|		rbuf = &priv->nonce[0];
 2389|     19|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   73|     19|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   81|     19|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2390|     19|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2391|     19|			&rbuf, &rbuflen, NULL, 0);
 2392|     19|		if (r < 0) {
  ------------------
  |  Branch (2392:7): [True: 11, False: 8]
  ------------------
 2393|     11|			break;
 2394|     11|		}
 2395|      8|		priv->nonce_valid = 1;
 2396|      8|		r = SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 2397|    706|	}
 2398|    706|	return r;
 2399|    706|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2420|  29.3k|{
 2421|  29.3k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  29.3k|#define SC_SUCCESS				0
  ------------------
 2422|       |
 2423|  29.3k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  29.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  29.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  29.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 29.3k]
  |  |  ------------------
  ------------------
 2424|       |
 2425|  29.3k|	if (was_reset > 0) {
  ------------------
  |  Branch (2425:6): [True: 0, False: 29.3k]
  ------------------
 2426|      0|		r = coolkey_select_applet(card);
 2427|      0|	}
 2428|       |
 2429|  29.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  29.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  29.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  29.3k|	int _ret = r; \
  |  |  |  |  155|  29.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  29.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 29.3k]
  |  |  |  |  ------------------
  |  |  |  |  157|  29.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  29.3k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  29.3k|	return _ret; \
  |  |  |  |  163|  29.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2430|  29.3k|}

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

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

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

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

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

sc_get_eoi_driver:
  580|  16.9k|{
  581|  16.9k|	eoi_ops = *sc_get_iso7816_driver()->ops;
  582|       |
  583|  16.9k|	eoi_ops.match_card = eoi_match_card;
  584|  16.9k|	eoi_ops.init = eoi_init;
  585|  16.9k|	eoi_ops.finish = eoi_finish;
  586|  16.9k|	eoi_ops.select_file = eoi_select_file;
  587|  16.9k|	eoi_ops.logout = eoi_logout;
  588|  16.9k|	eoi_ops.pin_cmd = eoi_pin_cmd;
  589|  16.9k|	eoi_ops.card_ctl = eoi_card_ctl;
  590|  16.9k|	eoi_ops.set_security_env = eoi_set_security_env;
  591|  16.9k|	eoi_ops.compute_signature = eoi_compute_signature;
  592|       |
  593|  16.9k|	return &eoi_drv;
  594|  16.9k|}
card-eoi.c:eoi_match_card:
  250|  2.41k|static int eoi_match_card(sc_card_t* card) {
  251|  2.41k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.41k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.41k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.41k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.41k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|  2.41k|	if (_sc_match_atr(card, eoi_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (252:6): [True: 61, False: 2.35k]
  ------------------
  253|     61|		sc_log(card->ctx, "ATR recognized as Slovenian eID card");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  254|     61|		LOG_FUNC_RETURN(card->ctx, ATR_MATCH);
  ------------------
  |  |  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: 0, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     61|	} else { \
  |  |  |  |  159|     61|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     61|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     61|	} \
  |  |  |  |  162|     61|	return _ret; \
  |  |  |  |  163|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  255|     61|	}
  256|  2.35k|	LOG_FUNC_RETURN(card->ctx, !ATR_MATCH);
  ------------------
  |  |  164|  2.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.35k|	int _ret = r; \
  |  |  |  |  155|  2.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.35k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.35k|	} else { \
  |  |  |  |  159|      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.35k|	return _ret; \
  |  |  |  |  163|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  2.35k|}
card-eoi.c:eoi_init:
  259|     61|static int eoi_init(sc_card_t* card) {
  260|     61|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  261|     61|	u8 version[6];
  262|     61|	size_t i, j;
  263|     61|	scconf_block **found_blocks, *block;
  264|     61|	int r;
  265|     61|	char *can;
  266|       |
  267|     61|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|     61|	if (eoi_get_data(card, 0x16, version, sizeof(version)) != SC_SUCCESS)
  ------------------
  |  |   28|     61|#define SC_SUCCESS				0
  ------------------
  |  Branch (269:6): [True: 51, False: 10]
  ------------------
  270|     61|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     51|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|       |
  272|     10|	if (privdata)
  ------------------
  |  Branch (272:6): [True: 0, False: 10]
  ------------------
  273|     10|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  274|     10|	privdata = sc_mem_secure_alloc(sizeof(struct eoi_privdata));
  275|     10|	if (!privdata)
  ------------------
  |  Branch (275:6): [True: 0, False: 10]
  ------------------
  276|     10|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  277|       |	/* sc_mem_secure_alloc()-ed memory may not be zeroized */
  278|     10|	memset(privdata, 0, sizeof(struct eoi_privdata));
  279|     10|	card->drv_data = privdata;
  280|       |
  281|     10|	sprintf(privdata->version, "%X%02X.%02X%02X", version[0], version[1], version[2], version[3]);
  282|     10|	sc_log(card->ctx, "App version: %s", privdata->version);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  283|       |
  284|     10|	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
  285|     10|	card->sm_ctx.ops.open = eoi_sm_open;
  286|       |
  287|     10|	card->max_send_size = SC_MAX_APDU_DATA_SIZE;
  ------------------
  |  |   35|     10|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  288|     10|	card->max_recv_size = SC_MAX_APDU_RESP_SIZE;
  ------------------
  |  |   36|     10|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  289|       |
  290|     20|	for (i = 0; i < sizeof eoi_curves / sizeof * eoi_curves; ++i) {
  ------------------
  |  Branch (290:14): [True: 10, False: 10]
  ------------------
  291|     10|		r = _sc_card_add_ec_alg(card, eoi_curves[i].len, SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE, 0, &eoi_curves[i].oid);
  ------------------
  |  |  174|     10|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		r = _sc_card_add_ec_alg(card, eoi_curves[i].len, SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE, 0, &eoi_curves[i].oid);
  ------------------
  |  |  175|     10|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     10|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  292|     10|		LOG_TEST_GOTO_ERR(card->ctx, r, "Add EC alg failed");
  ------------------
  |  |  184|     10|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     10|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     10|	int _ret = (r); \
  |  |  |  |  178|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|     10|	}
  294|       |
  295|     10|	can = getenv("EOI_CAN");
  296|     10|	if (can)
  ------------------
  |  Branch (296:6): [True: 0, False: 10]
  ------------------
  297|      0|		strlcpy(privdata->can, can, sizeof(privdata->can));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  298|     20|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (298:14): [True: 10, False: 10]
  ------------------
  299|     10|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
  300|     10|					"card_driver", "eoi");
  301|     10|		if (!found_blocks)
  ------------------
  |  Branch (301:7): [True: 0, False: 10]
  ------------------
  302|      0|			continue;
  303|       |
  304|     10|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (304:40): [True: 0, False: 10]
  ------------------
  305|      0|			if (!privdata->can[0]) {
  ------------------
  |  Branch (305:8): [True: 0, False: 0]
  ------------------
  306|      0|				const char *can = scconf_get_str(block, "can", NULL);
  307|      0|				if (can)
  ------------------
  |  Branch (307:9): [True: 0, False: 0]
  ------------------
  308|      0|					strlcpy(privdata->can, can, sizeof(privdata->can));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  309|      0|			}
  310|      0|		}
  311|     10|		free(found_blocks);
  312|     10|	}
  313|       |
  314|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|       |
  316|      0|err:
  317|      0|	if (privdata) {
  ------------------
  |  Branch (317:6): [True: 0, False: 0]
  ------------------
  318|      0|		sc_mem_clear(privdata, sizeof(struct eoi_privdata));
  319|      0|		sc_mem_secure_free(privdata, sizeof(struct eoi_privdata));
  320|      0|	}
  321|      0|	card->drv_data = NULL;
  322|       |
  323|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|      0|}
card-eoi.c:eoi_get_data:
  233|     61|{
  234|     61|	int r;
  235|     61|	sc_apdu_t apdu;
  236|       |
  237|     61|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, data_id);
  ------------------
  |  |  292|     61|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  238|     61|	apdu.resp = buf;
  239|     61|	apdu.resplen = len;
  240|     61|	apdu.le = len;
  241|       |
  242|     61|	r = sc_transmit_apdu(card, &apdu);
  243|     61|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 3, False: 58]
  |  |  |  |  ------------------
  |  |  |  |  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|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 58]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|     58|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  245|     58|	return r;
  246|     61|}
card-eoi.c:eoi_finish:
  327|     10|{
  328|     10|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  329|       |
  330|     10|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|       |
  332|     10|	if (privdata) {
  ------------------
  |  Branch (332:6): [True: 10, False: 0]
  ------------------
  333|     10|		sc_mem_clear(privdata, sizeof(struct eoi_privdata));
  334|     10|		sc_mem_secure_free(privdata, sizeof(struct eoi_privdata));
  335|     10|	}
  336|       |
  337|     10|	card->drv_data = NULL;
  338|       |
  339|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  340|     10|}
card-eoi.c:eoi_select_file:
  343|     61|{
  344|     61|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  345|     61|	int i;
  346|       |
  347|     61|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  348|       |
  349|     61|	if (!privdata)
  ------------------
  |  Branch (349:6): [True: 0, False: 61]
  ------------------
  350|     61|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|       |
  352|     61|	for (i = 0; i < MAX_OBJECTS && privdata->pin_paths[i]; i++) {
  ------------------
  |  |   24|    122|#define MAX_OBJECTS 8
  ------------------
  |  Branch (352:14): [True: 61, False: 0]
  |  Branch (352:33): [True: 0, False: 61]
  ------------------
  353|      0|		if (privdata->pin_paths[i] && sc_compare_path(privdata->pin_paths[i], in_path)) {
  ------------------
  |  Branch (353:7): [True: 0, False: 0]
  |  Branch (353:33): [True: 0, False: 0]
  ------------------
  354|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  355|      0|		}
  356|      0|	}
  357|       |
  358|     61|	LOG_FUNC_RETURN(card->ctx, sc_get_iso7816_driver()->ops->select_file(card, in_path, file_out));
  ------------------
  |  |  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|     53|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 53, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|     61|}
card-eoi.c:eoi_pin_cmd:
  395|      1|{
  396|      1|	int r;
  397|       |
  398|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  399|       |
  400|      1|	if (data->cmd == SC_PIN_CMD_VERIFY && card->sm_ctx.sm_mode == SM_MODE_NONE) {
  ------------------
  |  |  415|      2|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && card->sm_ctx.sm_mode == SM_MODE_NONE) {
  ------------------
  |  |   43|      0|#define SM_MODE_NONE		0x0
  ------------------
  |  Branch (400:6): [True: 0, False: 1]
  |  Branch (400:40): [True: 0, False: 0]
  ------------------
  401|       |		/* Establish SM before any PIN VERIFY command */
  402|      0|		r = eoi_sm_open(card);
  403|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (403:7): [True: 0, False: 0]
  ------------------
  404|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  405|      0|	}
  406|       |
  407|      1|	if (data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|      1|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (407:6): [True: 0, False: 1]
  ------------------
  408|      0|		int pin_reference = data->pin_reference;
  409|      0|		size_t pin2_len = data->pin2.len;
  410|       |		/* Verify PUK, establish SM if necessary */
  411|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  412|      0|		data->pin_reference = data->puk_reference;
  413|      0|		r = eoi_pin_cmd(card, data);
  414|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (414:7): [True: 0, False: 0]
  ------------------
  415|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |		/* RESET RETRY COUNTER */
  417|      0|		data->cmd = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  418|      0|		data->pin_reference = 0x80|pin_reference;
  419|      0|		data->pin1.len = 0;
  420|      0|		data->pin2.len = 0;
  421|      0|		r = sc_get_iso7816_driver()->ops->pin_cmd(card, data);
  422|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (422:7): [True: 0, False: 0]
  ------------------
  423|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  424|       |		/* Continue as CHANGE PIN */
  425|      0|		data->cmd = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  426|      0|		data->pin2.len = pin2_len;
  427|      0|	}
  428|       |
  429|       |	/* CHANGE PIN command does not send the old PIN as it should already be verified */
  430|      1|	if (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  416|      1|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (430:6): [True: 0, False: 1]
  ------------------
  431|      0|		data->pin1.len = 0;
  432|       |
  433|      1|	LOG_FUNC_RETURN(card->ctx, sc_get_iso7816_driver()->ops->pin_cmd(card, 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|      1|}
card-eoi.c:eoi_card_ctl:
  438|      1|{
  439|      1|	struct sc_card_driver *iso_driver = NULL;
  440|      1|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  441|       |
  442|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|      1|	switch (cmd) {
  444|      0|	case SC_CARDCTL_GET_MODEL:
  ------------------
  |  Branch (444:2): [True: 0, False: 1]
  ------------------
  445|      0|		if (!ptr) {
  ------------------
  |  Branch (445:7): [True: 0, False: 0]
  ------------------
  446|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  447|      0|		} else {
  448|      0|			*(char **)ptr = eoi_model;
  449|      0|			r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  450|      0|		}
  451|      0|		break;
  452|      1|	default:
  ------------------
  |  Branch (452:2): [True: 1, False: 0]
  ------------------
  453|      1|		iso_driver = sc_get_iso7816_driver();
  454|      1|		if (iso_driver->ops->card_ctl != NULL) {
  ------------------
  |  Branch (454:7): [True: 0, False: 1]
  ------------------
  455|      0|			r = sc_get_iso7816_driver()->ops->card_ctl(card, cmd, ptr);
  456|      0|		}
  457|      1|	}
  458|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|      1|}

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

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

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

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

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

sc_get_gids_driver:
 2185|  16.9k|{
 2186|  16.9k|	return sc_get_driver();
 2187|  16.9k|}
card-gids.c:sc_get_driver:
 2140|  16.9k|{
 2141|       |
 2142|  16.9k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2142:6): [True: 1, False: 16.9k]
  ------------------
 2143|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2144|       |
 2145|  16.9k|	gids_ops.match_card = gids_match_card;
 2146|  16.9k|	gids_ops.init = gids_init;
 2147|  16.9k|	gids_ops.finish = gids_finish;
 2148|  16.9k|	gids_ops.read_binary = gids_read_binary;
 2149|  16.9k|	gids_ops.write_binary = NULL;
 2150|  16.9k|	gids_ops.update_binary = NULL;
 2151|  16.9k|	gids_ops.erase_binary = NULL;
 2152|  16.9k|	gids_ops.read_record = NULL;
 2153|  16.9k|	gids_ops.write_record = NULL;
 2154|  16.9k|	gids_ops.append_record = NULL;
 2155|  16.9k|	gids_ops.update_record = NULL;
 2156|  16.9k|	gids_ops.select_file = gids_select_file;
 2157|  16.9k|	gids_ops.get_response = iso_ops->get_response;
 2158|  16.9k|	gids_ops.get_challenge = NULL;
 2159|  16.9k|	gids_ops.verify = NULL; // see pin_cmd
 2160|  16.9k|	gids_ops.logout = gids_logout;
 2161|  16.9k|	gids_ops.restore_security_env = NULL;
 2162|  16.9k|	gids_ops.set_security_env = gids_set_security_env;
 2163|  16.9k|	gids_ops.decipher = gids_decipher;
 2164|  16.9k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2165|  16.9k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2166|  16.9k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2167|  16.9k|	gids_ops.create_file = iso_ops->create_file;
 2168|  16.9k|	gids_ops.delete_file = NULL;
 2169|  16.9k|	gids_ops.list_files = NULL;
 2170|  16.9k|	gids_ops.check_sw = iso_ops->check_sw;
 2171|  16.9k|	gids_ops.card_ctl = gids_card_ctl;
 2172|  16.9k|	gids_ops.process_fci = iso_ops->process_fci;
 2173|  16.9k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2174|  16.9k|	gids_ops.pin_cmd = gids_pin_cmd;
 2175|  16.9k|	gids_ops.get_data = NULL;
 2176|  16.9k|	gids_ops.put_data = NULL;
 2177|  16.9k|	gids_ops.delete_record = NULL;
 2178|  16.9k|	gids_ops.read_public_key = gids_read_public_key;
 2179|  16.9k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2180|       |
 2181|  16.9k|	return &gids_drv;
 2182|  16.9k|}
card-gids.c:gids_match_card:
  563|  3.72k|{
  564|  3.72k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  565|  3.72k|	int r,i;
  566|  3.72k|	size_t resplen = sizeof(rbuf);
  567|  3.72k|	const u8 *tag;
  568|  3.72k|	size_t taglen;
  569|  3.72k|	const u8 *aid;
  570|  3.72k|	size_t aidlen;
  571|       |
  572|  3.72k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.72k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.72k]
  |  |  ------------------
  ------------------
  573|       |
  574|       |	/* Detect by selecting applet */
  575|  3.72k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  576|  3.72k|	if (r<0) return 0;
  ------------------
  |  Branch (576:6): [True: 3.60k, False: 122]
  ------------------
  577|       |
  578|    122|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  579|    122|	if (resplen > 2) {
  ------------------
  |  Branch (579:6): [True: 22, False: 100]
  ------------------
  580|     22|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     22|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  581|     22|		if (tag != NULL) {
  ------------------
  |  Branch (581:7): [True: 19, False: 3]
  ------------------
  582|     19|			aid = sc_asn1_find_tag(card->ctx, tag, taglen, GIDS_APPLICATION_AID_TAG, &aidlen);
  ------------------
  |  |  106|     19|#define GIDS_APPLICATION_AID_TAG 0x4F
  ------------------
  583|     19|			if (aid != NULL ) {
  ------------------
  |  Branch (583:8): [True: 18, False: 1]
  ------------------
  584|     18|				sc_log(card->ctx, "found AID");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  585|     51|				for (i = 0; gids_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (585:17): [True: 35, False: 16]
  ------------------
  586|     35|					if ( aidlen > gids_aids[i].len_long && memcmp(aid, gids_aids[i].value,
  ------------------
  |  Branch (586:11): [True: 33, False: 2]
  |  Branch (586:45): [True: 2, False: 31]
  ------------------
  587|     33|									gids_aids[i].len_long) == 0) {
  588|      2|						card->type = gids_aids[i].enumtag;
  589|      2|						break;
  590|      2|					}
  591|     35|				}
  592|     18|			}
  593|     19|		}
  594|     22|	}
  595|       |
  596|    122|	return 1;
  597|  3.72k|}
card-gids.c:gids_select_aid:
  280|  3.72k|{
  281|  3.72k|	sc_apdu_t apdu;
  282|  3.72k|	int r;
  283|       |
  284|  3.72k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.72k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.72k]
  |  |  ------------------
  ------------------
  285|  3.72k|	sc_log(card->ctx, "Got args: aid=%p, aidlen=%zu, response=%p, responselen=%zu",
  ------------------
  |  |   71|  7.45k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.72k, False: 0]
  |  |  ------------------
  ------------------
  286|  3.72k|			aid, aidlen, response, responselen ? *responselen : 0);
  287|       |
  288|  3.72k|	sc_format_apdu(card, &apdu,
  289|  3.72k|		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |  294|  3.72k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   68|  3.72k|#define INS_SELECT 0xA4
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   72|  3.72k|#define P1_SELECT_DF_BY_NAME 0x04
  ------------------
              		response == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, INS_SELECT, P1_SELECT_DF_BY_NAME, P2_SELECT_FIRST_OR_ONLY_OCCURENCE);
  ------------------
  |  |   75|  3.72k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (289:3): [True: 0, False: 3.72k]
  ------------------
  290|  3.72k|	apdu.lc = aidlen;
  291|  3.72k|	apdu.data = aid;
  292|  3.72k|	apdu.datalen = aidlen;
  293|  3.72k|	apdu.resp = response;
  294|  3.72k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (294:17): [True: 3.72k, False: 0]
  ------------------
  295|  3.72k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (295:12): [True: 0, False: 3.72k]
  ------------------
  296|       |
  297|  3.72k|	r = sc_transmit_apdu(card, &apdu);
  298|  3.72k|	if (responselen)
  ------------------
  |  Branch (298:6): [True: 3.72k, False: 0]
  ------------------
  299|  3.72k|		*responselen = apdu.resplen;
  300|  3.72k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  3.72k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.72k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.72k|	int _ret = (r); \
  |  |  |  |  168|  3.72k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 3.71k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.72k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.71k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|  3.71k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  3.71k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.71k|	int _ret = r; \
  |  |  155|  3.71k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.71k, False: 0]
  |  |  ------------------
  |  |  156|  3.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.59k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.59k, False: 122]
  |  |  ------------------
  |  |  157|  3.71k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.71k|	} else { \
  |  |  159|      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.71k|	return _ret; \
  |  |  163|  3.71k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  302|  3.71k|}
card-gids.c:gids_init:
  631|    122|{
  632|    122|	unsigned long flags;
  633|    122|	struct gids_private_data *data;
  634|    122|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    122|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    122|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    122|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 122]
  |  |  ------------------
  ------------------
  635|       |
  636|       |	// cache some data in memory
  637|    122|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  638|    122|	if (!data) {
  ------------------
  |  Branch (638:6): [True: 0, False: 122]
  ------------------
  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|    122|	memset(data, 0, sizeof(struct gids_private_data));
  642|    122|	card->drv_data = data;
  643|       |	// invalidate the master file and cmap file cache
  644|    122|	data->cmapfilesize = sizeof(data->cmapfile);
  645|    122|	data->masterfilesize = sizeof(data->masterfile);
  646|       |
  647|       |	/* supported RSA keys and how padding is done */
  648|    122|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|    122|#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|    122|#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|    122|#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|    122|#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|    122|#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|    122|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  652|    122|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  653|    122|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  654|    122|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  655|       |
  656|    122|	return SC_SUCCESS;
  ------------------
  |  |   28|    122|#define SC_SUCCESS				0
  ------------------
  657|    122|}
card-gids.c:gids_finish:
  661|    122|{
  662|    122|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    122|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    122|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    122|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 122]
  |  |  ------------------
  ------------------
  663|       |	/* free the private data */
  664|    122|	if (card->drv_data) {
  ------------------
  |  Branch (664:6): [True: 122, False: 0]
  ------------------
  665|    122|		free(card->drv_data);
  666|       |		card->drv_data = NULL;
  667|    122|	}
  668|    122|	return 0;
  669|    122|}
card-gids.c:gids_read_binary:
 1032|      6|		unsigned char *buf, size_t count, unsigned long *flags) {
 1033|      6|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
 1034|      6|	struct sc_context *ctx = card->ctx;
 1035|      6|	int r;
 1036|      6|	int size;
 1037|       |
 1038|      6|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      6|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      6|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1039|       |
 1040|      6|	if (! data->currentDO || ! data->currentEFID) {
  ------------------
  |  Branch (1040:6): [True: 6, False: 0]
  |  Branch (1040:27): [True: 0, False: 0]
  ------------------
 1041|      6|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1042|      6|	}
 1043|      0|	if (data->state != GIDS_STATE_READ_DATA_PRESENT) {
  ------------------
  |  |   58|      0|#define GIDS_STATE_READ_DATA_PRESENT 1
  ------------------
  |  Branch (1043:6): [True: 0, False: 0]
  ------------------
 1044|       |		// this function is called to read the certificate only
 1045|      0|		u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1046|      0|		size_t buffersize = sizeof(buffer);
 1047|      0|		r = gids_get_DO(card, data->currentEFID, data->currentDO, buffer, &(buffersize));
 1048|      0|		if (r <0) return r;
  ------------------
  |  Branch (1048:7): [True: 0, False: 0]
  ------------------
 1049|      0|		if (buffersize < 4) {
  ------------------
  |  Branch (1049:7): [True: 0, False: 0]
  ------------------
 1050|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1051|      0|		}
 1052|      0|		if (buffer[0] == 1 && buffer[1] == 0) {
  ------------------
  |  Branch (1052:7): [True: 0, False: 0]
  |  Branch (1052:25): [True: 0, False: 0]
  ------------------
 1053|      0|			if (flags)
  ------------------
  |  Branch (1053:8): [True: 0, False: 0]
  ------------------
 1054|      0|				*flags |= SC_FILE_FLAG_COMPRESSED_ZLIB;
  ------------------
  |  |  231|      0|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
 1055|       |			/* compressed data are starting on position buffer + 4 */
 1056|      0|			data->buffersize = buffersize - 4;
 1057|      0|			memcpy(data->buffer, buffer + 4, buffersize - 4);
 1058|      0|		} else {
 1059|      0|			sc_log(card->ctx, "unknown compression method %d", buffer[0] + (buffer[1] << 8));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1060|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1061|      0|		}
 1062|      0|		data->state = GIDS_STATE_READ_DATA_PRESENT;
  ------------------
  |  |   58|      0|#define GIDS_STATE_READ_DATA_PRESENT 1
  ------------------
 1063|      0|	}
 1064|      0|	if (offset >= data->buffersize) {
  ------------------
  |  Branch (1064:6): [True: 0, False: 0]
  ------------------
 1065|      0|		return 0;
 1066|      0|	}
 1067|      0|	size = (int) MIN((data->buffersize - offset), count);
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1068|      0|	memcpy(buf, data->buffer + offset, size);
 1069|      0|	return size;
 1070|      0|}
card-gids.c:gids_get_DO:
  210|    132|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|    132|	sc_apdu_t apdu;
  212|    132|	int r;
  213|    132|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|    132|	size_t datasize = 0;
  215|    132|	const u8* p;
  216|    132|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|    132|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|    132|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    132|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    132|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    132|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 132]
  |  |  ------------------
  ------------------
  220|    132|	sc_log(card->ctx, "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%zu",
  ------------------
  |  |   71|    264|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 132, False: 0]
  |  |  ------------------
  ------------------
  221|    132|			fileIdentifier, dataObjectIdentifier, response, responselen ? *responselen : 0);
  222|       |
  223|    132|	sc_format_apdu(card, &apdu,
  224|    132|		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|    132|#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|    132|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (224:3): [True: 0, False: 132]
  ------------------
  225|    132|	apdu.lc = 04;
  226|    132|	apdu.data = data;
  227|    132|	apdu.datalen = 04;
  228|    132|	apdu.resp = buffer;
  229|    132|	apdu.resplen = buffer_len;
  230|    132|	apdu.le = 256;
  231|       |
  232|    132|	r = sc_transmit_apdu(card, &apdu);
  233|    132|	LOG_TEST_RET(card->ctx, r, "gids get data 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: 3, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  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|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    129|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  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: 35, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  169|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     35|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     35|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     35|		return _ret; \
  |  |  |  |  172|     35|	} \
  |  |  |  |  173|    129|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|     94|	buffer_len = apdu.resplen;
  236|       |
  237|     94|	p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize);
  238|     94|	if (!p) {
  ------------------
  |  Branch (238:6): [True: 5, False: 89]
  ------------------
  239|      5|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|      5|	}
  241|     89|	if (response && responselen) {
  ------------------
  |  Branch (241:6): [True: 89, False: 0]
  |  Branch (241:18): [True: 89, False: 0]
  ------------------
  242|     89|		if (datasize > *responselen) {
  ------------------
  |  Branch (242:7): [True: 0, False: 89]
  ------------------
  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|     89|		memcpy(response, p, datasize);
  246|     89|		*responselen = datasize;
  247|     89|	}
  248|     89|	return SC_SUCCESS;
  ------------------
  |  |   28|     89|#define SC_SUCCESS				0
  ------------------
  249|     89|}
card-gids.c:gids_select_file:
  964|    622|			   struct sc_file **file_out) {
  965|    622|	struct sc_file *file = NULL;
  966|    622|	struct sc_context *ctx = card->ctx;
  967|    622|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  968|       |
  969|    622|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    622|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    622|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    622|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    622|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 622]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|       |
  971|    622|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    622|#define GIDS_STATE_NONE 0
  ------------------
  972|    622|	data->currentDO = 0;
  973|    622|	data->currentEFID = 0;
  974|    622|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (974:6): [True: 359, False: 263]
  |  Branch (974:27): [True: 0, False: 359]
  ------------------
  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|    622|	} 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: 359, False: 263]
  |  Branch (991:34): [True: 359, False: 0]
  |  Branch (991:63): [True: 0, False: 359]
  |  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|    622|	} else {
 1002|    622|		return iso_ops->select_file(card, in_path, file_out);
 1003|    622|	}
 1004|    622|}
card-gids.c:gids_card_ctl:
 2089|    132|{
 2090|    132|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    132|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    132|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    132|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    132|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 132]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2091|    132|	switch (cmd) {
 2092|     10|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2092:3): [True: 10, False: 122]
  ------------------
 2093|     10|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2094|    122|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2094:3): [True: 122, False: 10]
  ------------------
 2095|    122|			return gids_get_all_containers(card, (size_t*) ptr);
 2096|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2096:3): [True: 0, False: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 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: 132]
  ------------------
 2116|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2117|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2117:3): [True: 0, False: 132]
  ------------------
 2118|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2119|      0|		default:
  ------------------
  |  Branch (2119:3): [True: 0, False: 132]
  ------------------
 2120|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2121|    132|	}
 2122|    132|}
card-gids.c:gids_get_serialnr:
  602|     10|{
  603|     10|	int r;
  604|     10|	u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  605|     10|	size_t buffersize;
  606|       |
  607|     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]
  |  |  ------------------
  ------------------
  608|       |
  609|     10|	buffersize = sizeof(buffer);
  610|     10|	r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
  611|     10|	LOG_TEST_RET(card->ctx, r, "unable to read cardid");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     91|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  386|     91|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  387|     91|	int r;
  388|     91|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  389|     91|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (389:6): [True: 8, False: 83]
  ------------------
  390|      8|		r = gids_read_masterfile(card);
  391|      8|		LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
  ------------------
  |  |  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: 3, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|      8|	}
  393|     88|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  394|     88|		directory, filename, response, responselen);
  395|     88|	LOG_TEST_RET(card->ctx, r, "unable to read the file");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 88, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     88|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     88|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     88|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     88|		return _ret; \
  |  |  |  |  172|     88|	} \
  |  |  |  |  173|     88|} 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|    130|static int gids_read_masterfile(sc_card_t* card) {
  341|    130|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  342|    130|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    130|#define SC_SUCCESS				0
  ------------------
  343|       |
  344|    130|	data->masterfilesize = sizeof(data->masterfile);
  345|    130|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|    130|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|    130|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|    130|#define MF_DO 0xDF1F
  ------------------
  346|    130|	if (r<0) {
  ------------------
  |  Branch (346:6): [True: 41, False: 89]
  ------------------
  347|     41|		data->masterfilesize = sizeof(data->masterfile);
  348|     41|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     41|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     41|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     41|	int _ret = r; \
  |  |  |  |  155|     41|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     41|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     41|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     41|	return _ret; \
  |  |  |  |  163|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|     41|	}
  350|     89|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (350:6): [True: 1, False: 88]
  |  Branch (350:34): [True: 2, False: 86]
  ------------------
  351|      3|		data->masterfilesize = sizeof(data->masterfile);
  352|      3|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      3|	}
  354|     86|	return r;
  355|     89|}
card-gids.c:gids_read_gidsfile_without_cache:
  308|     88|static int gids_read_gidsfile_without_cache(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, u8* response, size_t *responselen) {
  309|     88|	int r;
  310|     88|	int fileIdentifier;
  311|     88|	int dataObjectIdentifier;
  312|       |
  313|     88|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     88|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     88|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     88|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 88]
  |  |  ------------------
  ------------------
  314|     88|	r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
  315|     88|	LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 86, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|      2|	r = gids_get_DO(card, fileIdentifier, dataObjectIdentifier, response, responselen);
  317|      2|	LOG_TEST_RET(card->ctx, r, "unable to get the data from the file");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|      0|	return r;
  319|      2|}
card-gids.c:gids_get_identifiers:
  163|     88|static int gids_get_identifiers(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, int *fileIdentifier, int *dataObjectIdentifier) {
  164|     88|	gids_mf_record_t *records = (gids_mf_record_t *) (masterfile+1);
  165|     88|	size_t recordcount = ((masterfilesize-1) / sizeof(gids_mf_record_t));
  166|     88|	size_t i;
  167|     88|	if (masterfilesize < 1)
  ------------------
  |  Branch (167:6): [True: 0, False: 88]
  ------------------
  168|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  169|       |
  170|    195|	for (i = 0; i < recordcount; i++) {
  ------------------
  |  Branch (170:14): [True: 109, False: 86]
  ------------------
  171|    109|		if (strncmp(directory, records[i].directory, sizeof(records[i].directory)) == 0 && strncmp(filename, records[i].filename, sizeof(records[i].filename)) == 0) {
  ------------------
  |  Branch (171:7): [True: 71, False: 38]
  |  Branch (171:86): [True: 2, False: 69]
  ------------------
  172|      2|			*fileIdentifier = records[i].fileIdentifier;
  173|      2|			*dataObjectIdentifier = records[i].dataObjectIdentifier;
  174|      2|			sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  175|      2|		"Identifiers of %s %s is fileIdentifier=%x, dataObjectIdentifier=%x\n", directory, filename, *fileIdentifier, *dataObjectIdentifier);
  176|      2|			return 0;
  177|      2|		}
  178|    109|	}
  179|     86|	sc_log(card->ctx, "file %s %s not found\n", directory, filename);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  180|     86|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     86|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  181|     88|}
card-gids.c:gids_get_all_containers:
 1074|    122|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1075|    122|	int r;
 1076|    122|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1077|    122|	r = gids_read_masterfile(card);
 1078|    122|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  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: 41, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     81|	r = gids_read_cmapfile(card);
 1080|     81|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1081|      0|	*recordsnum = (privatedata ->cmapfilesize / sizeof(CONTAINER_MAP_RECORD));
 1082|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1083|     81|}
card-gids.c:gids_read_cmapfile:
  427|     81|static int gids_read_cmapfile(sc_card_t* card) {
  428|     81|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  429|     81|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     81|#define SC_SUCCESS				0
  ------------------
  430|       |
  431|     81|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     81|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     81|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     81|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 81]
  |  |  ------------------
  ------------------
  432|     81|	data->cmapfilesize = sizeof(data->cmapfile);
  433|     81|	r = gids_read_gidsfile(card, "mscp", "cmapfile", data->cmapfile, &data->cmapfilesize);
  434|     81|	if (r<0) {
  ------------------
  |  Branch (434:6): [True: 81, False: 0]
  ------------------
  435|     81|		data->cmapfilesize = sizeof(data->cmapfile);
  436|     81|	}
  437|     81|	LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|      0|	return r;
  439|     81|}
card-gids.c:gids_pin_cmd:
 1022|     10|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1023|     10|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|     10|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1023:6): [True: 10, False: 0]
  ------------------
 1024|     10|		return gids_get_pin_policy(card, data);
 1025|     10|	} else {
 1026|      0|		return iso_ops->pin_cmd(card, data);
 1027|      0|	}
 1028|     10|}
card-gids.c:gids_get_pin_policy:
 1006|     10|static int gids_get_pin_policy(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1007|     10|	int r;
 1008|     10|	if (data->pin_type != SC_AC_CHV) {
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1008:6): [True: 0, False: 10]
  ------------------
 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|     10|	r = gids_get_pin_status(card, data->pin_reference, &(data->pin1.tries_left), &(data->pin1.max_tries));
 1012|     10|	LOG_TEST_RET(card->ctx, r, "gids_get_pin_status 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: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|     10|}
card-gids.c:gids_get_pin_status:
  516|     10|static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_left, int *max_tries) {
  517|     10|	int dataObjectIdentifier, r;
  518|     10|	u8 buffer[100];
  519|     10|	const u8* p;
  520|     10|	size_t buffersize = sizeof(buffer);
  521|     10|	size_t datasize;
  522|       |
  523|     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]
  |  |  ------------------
  ------------------
  524|     10|	if (tries_left) *tries_left = -1;
  ------------------
  |  Branch (524:6): [True: 10, False: 0]
  ------------------
  525|     10|	if (max_tries) *max_tries = -1;
  ------------------
  |  Branch (525:6): [True: 10, False: 0]
  ------------------
  526|     10|	switch(pinreference) {
  527|      0|	case GIDS_PIN_IDENTIFIER:
  ------------------
  |  |  100|      0|#define GIDS_PIN_IDENTIFIER 0x80
  ------------------
  |  Branch (527:2): [True: 0, False: 10]
  ------------------
  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: 10]
  ------------------
  531|      0|		dataObjectIdentifier = GIDS_PUK_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   81|      0|#define GIDS_PUK_STATUS_OBJECT_IDENTIFIER 0x7F73
  ------------------
  532|      0|		break;
  533|     10|	default:
  ------------------
  |  Branch (533:2): [True: 10, False: 0]
  ------------------
  534|     10|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|     10|	}
  536|      0|	r = gids_get_DO(card, GIDS_APPLET_EFID, dataObjectIdentifier, buffer, &buffersize);
  ------------------
  |  |   82|      0|#define GIDS_APPLET_EFID 0x3FFF
  ------------------
  537|      0|	LOG_TEST_RET(card->ctx, r, "unable to update the masterfile");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|       |
  539|      0|	buffersize = buffersize > sizeof(buffer) ? sizeof(buffer) : buffersize;
  ------------------
  |  Branch (539:15): [True: 0, False: 0]
  ------------------
  540|       |
  541|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_OLD_TAG, &datasize);
  ------------------
  |  |  102|      0|#define GIDS_TRY_COUNTER_OLD_TAG 0x9F17
  ------------------
  542|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (542:6): [True: 0, False: 0]
  |  Branch (542:11): [True: 0, False: 0]
  ------------------
  543|      0|		if (tries_left)
  ------------------
  |  Branch (543:7): [True: 0, False: 0]
  ------------------
  544|      0|			*tries_left = p[0];
  545|      0|	}
  546|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_TAG, &datasize);
  ------------------
  |  |  103|      0|#define GIDS_TRY_COUNTER_TAG 0x97
  ------------------
  547|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (547:6): [True: 0, False: 0]
  |  Branch (547:11): [True: 0, False: 0]
  ------------------
  548|      0|		if (tries_left)
  ------------------
  |  Branch (548:7): [True: 0, False: 0]
  ------------------
  549|      0|			*tries_left = p[0];
  550|      0|	}
  551|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize , GIDS_TRY_LIMIT_TAG, &datasize);
  ------------------
  |  |  104|      0|#define GIDS_TRY_LIMIT_TAG 0x93
  ------------------
  552|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (552:6): [True: 0, False: 0]
  |  Branch (552:11): [True: 0, False: 0]
  ------------------
  553|      0|		if (max_tries)
  ------------------
  |  Branch (553:7): [True: 0, False: 0]
  ------------------
  554|      0|			*max_tries = p[0];
  555|      0|	}
  556|       |
  557|      0|	sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  558|      0|		"Pin information for PIN 0x%x: triesleft=%d trieslimit=%d\n", pinreference, (tries_left?*tries_left:-1), (max_tries?*max_tries:-1));
  559|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|      0|}
card-gids.c:gids_card_reader_lock_obtained:
 2125|  3.84k|{
 2126|  3.84k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.84k|#define SC_SUCCESS				0
  ------------------
 2127|       |
 2128|  3.84k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.84k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.84k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.84k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.84k]
  |  |  ------------------
  ------------------
 2129|       |
 2130|  3.84k|	if (was_reset > 0) {
  ------------------
  |  Branch (2130:6): [True: 0, False: 3.84k]
  ------------------
 2131|      0|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2132|      0|		size_t resplen = sizeof(rbuf);
 2133|      0|		r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
 2134|      0|	}
 2135|       |
 2136|  3.84k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.84k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.84k|	int _ret = r; \
  |  |  |  |  155|  3.84k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.84k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.84k|	return _ret; \
  |  |  |  |  163|  3.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2137|  3.84k|}

sc_invalidate_cache:
  164|  3.15k|{
  165|  3.15k|	if (card) {
  ------------------
  |  Branch (165:6): [True: 3.15k, False: 0]
  ------------------
  166|  3.15k|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|  3.15k|		sc_file_free(prv->cache.current_ef);
  168|  3.15k|		sc_file_free(prv->cache.current_df);
  169|  3.15k|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|  3.15k|		prv->cache.valid = 0;
  171|  3.15k|	}
  172|  3.15k|}
iasecc_se_get_info:
 1609|    220|{
 1610|    220|	struct sc_context *ctx = card->ctx;
 1611|    220|	struct sc_apdu apdu;
 1612|    220|	unsigned char rbuf[0x100];
 1613|    220|	unsigned char sbuf_iasecc[10] = {
 1614|    220|		0x4D, 0x08, IASECC_SDO_TEMPLATE_TAG, 0x06,
  ------------------
  |  |   29|    220|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 1615|    220|		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   27|    220|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |  102|    220|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   59|    220|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 1616|    220|		se->reference & 0x3F,
 1617|    220|		0x02, IASECC_SDO_CLASS_SE, 0x80
  ------------------
  |  |  102|    220|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 1618|    220|	};
 1619|    220|	int rv;
 1620|       |
 1621|    220|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    220|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    220|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    220|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    220|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 220]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|    220|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1623:6): [True: 55, False: 165]
  ------------------
 1624|     55|		rv = iasecc_select_mf(card, NULL);
 1625|     55|		LOG_TEST_RET(ctx, rv, "MF invalid");
  ------------------
  |  |  174|     55|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     55|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     55|	int _ret = (r); \
  |  |  |  |  168|     55|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  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|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1626|     55|	}
 1627|       |
 1628|    209|	if (se->reference > IASECC_SE_REF_MAX)
  ------------------
  |  |   66|    209|#define IASECC_SE_REF_MAX	0x0F
  ------------------
  |  Branch (1628:6): [True: 0, False: 209]
  ------------------
 1629|    209|                LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1630|       |
 1631|    209|	rv = iasecc_se_get_info_from_cache(card, se);
 1632|    209|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    209|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1632:6): [True: 206, False: 3]
  ------------------
 1633|    206|		sc_log(ctx, "No SE#%X info in cache, try to use 'GET DATA'", se->reference);
  ------------------
  |  |   71|    206|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1634|       |
 1635|    206|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    206|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1636|    206|		apdu.data = sbuf_iasecc;
 1637|    206|		apdu.datalen = sizeof(sbuf_iasecc);
 1638|    206|		apdu.lc = apdu.datalen;
 1639|    206|		apdu.resp = rbuf;
 1640|    206|		apdu.resplen = sizeof(rbuf);
 1641|    206|		apdu.le = sizeof(rbuf);
 1642|       |
 1643|    206|		rv = sc_transmit_apdu(card, &apdu);
 1644|    206|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    206|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    206|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    206|	int _ret = (r); \
  |  |  |  |  168|    206|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 200]
  |  |  |  |  ------------------
  |  |  |  |  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|    206|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1645|    200|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1646|    200|		LOG_TEST_RET(ctx, rv, "get SE data  error");
  ------------------
  |  |  174|    200|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    200|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    200|	int _ret = (r); \
  |  |  |  |  168|    200|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 167]
  |  |  |  |  ------------------
  |  |  |  |  169|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     33|		return _ret; \
  |  |  |  |  172|     33|	} \
  |  |  |  |  173|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 167]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1647|       |
 1648|    167|		rv = iasecc_se_parse(card, apdu.resp, apdu.resplen, se);
 1649|    167|		LOG_TEST_RET(ctx, rv, "cannot parse SE data");
  ------------------
  |  |  174|    167|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    167|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    167|	int _ret = (r); \
  |  |  |  |  168|    167|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 137, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  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|    167|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|       |
 1651|     30|		rv = iasecc_se_cache_info(card, se);
 1652|     30|		LOG_TEST_RET(ctx, rv, "failed to put SE data into cache");
  ------------------
  |  |  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: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1653|     30|	}
 1654|       |
 1655|     33|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     33|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     33|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     33|	int _ret = r; \
  |  |  |  |  155|     33|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  157|     33|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     33|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     33|	return _ret; \
  |  |  |  |  163|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|     33|}
sc_get_iasecc_driver:
 3638|  16.9k|{
 3639|  16.9k|	return sc_get_driver();
 3640|  16.9k|}
card-iasecc.c:iasecc_is_cpx:
  586|  15.0k|{
  587|  15.0k|	switch(card->type) {
  588|  2.39k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (588:3): [True: 2.39k, False: 12.6k]
  ------------------
  589|  2.57k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (589:3): [True: 177, False: 14.8k]
  ------------------
  590|  2.57k|			return 1;
  591|  12.4k|		default:
  ------------------
  |  Branch (591:3): [True: 12.4k, False: 2.57k]
  ------------------
  592|  12.4k|			return 0;
  593|  15.0k|	}
  594|       |
  595|      0|	return 0;
  596|  15.0k|}
card-iasecc.c:iasecc_select_mf:
  283|  3.06k|{
  284|  3.06k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|  3.06k|	struct sc_context *ctx = card->ctx;
  286|  3.06k|	struct sc_file *mf_file = NULL;
  287|  3.06k|	struct sc_path path;
  288|  3.06k|	int rv;
  289|       |
  290|  3.06k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.06k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.06k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.06k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.06k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.06k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  3.06k|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 1.84k, False: 1.22k]
  ------------------
  293|  1.84k|		*file_out = NULL;
  294|       |
  295|  3.06k|	memset(&path, 0, sizeof(struct sc_path));
  296|  3.06k|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 174, False: 2.88k]
  |  Branch (296:23): [True: 248, False: 2.63k]
  ------------------
  297|    422|		struct sc_apdu apdu;
  298|    422|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|    422|		sc_format_path("3F00", &path);
  302|    422|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    422|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|    422|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    422|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|    422|		apdu.lc = path.len;
  306|    422|		apdu.data = path.value;
  307|    422|		apdu.datalen = path.len;
  308|    422|		apdu.resplen = sizeof(apdu_resp);
  309|    422|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|    422|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 68, False: 354]
  ------------------
  313|     68|			apdu.p2 = 0x04;
  314|       |
  315|    422|		rv = sc_transmit_apdu(card, &apdu);
  316|    422|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    422|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    422|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    422|	int _ret = (r); \
  |  |  |  |  168|    422|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 412]
  |  |  |  |  ------------------
  |  |  |  |  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|    422|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 412]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|    412|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|    412|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|    412|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    412|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    412|	int _ret = (r); \
  |  |  |  |  168|    412|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 180, False: 232]
  |  |  |  |  ------------------
  |  |  |  |  169|    180|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    180|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    180|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    180|		return _ret; \
  |  |  |  |  172|    180|	} \
  |  |  |  |  173|    412|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 232]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|    412|	}
  320|  2.63k|	else   {
  321|  2.63k|		memset(&path, 0, sizeof(path));
  322|  2.63k|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.63k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  323|  2.63k|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  324|  2.63k|		path.len = card->ef_atr->aid.len;
  325|  2.63k|		rv = iasecc_select_file(card, &path, file_out);
  326|  2.63k|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|  2.63k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.63k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.63k|	int _ret = (r); \
  |  |  |  |  168|  2.63k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.13k, False: 504]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.13k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.13k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.13k|		return _ret; \
  |  |  |  |  172|  2.13k|	} \
  |  |  |  |  173|  2.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 504]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|  2.63k|	}
  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|    736|	mf_file = sc_file_new();
  334|    736|	if (mf_file == NULL)
  ------------------
  |  Branch (334:6): [True: 0, False: 736]
  ------------------
  335|    736|		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|    736|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    736|#define SC_FILE_TYPE_DF			0x04
  ------------------
  337|    736|	mf_file->path = path;
  338|       |
  339|    736|	sc_invalidate_cache(card);
  340|    736|	sc_file_dup(&prv->cache.current_df, mf_file);
  341|    736|	prv->cache.valid = 1;
  342|       |
  343|    736|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (343:6): [True: 544, False: 192]
  |  Branch (343:18): [True: 444, False: 100]
  ------------------
  344|    444|		*file_out = mf_file;
  345|    292|	else
  346|    292|		sc_file_free(mf_file);
  347|       |
  348|    736|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    736|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    736|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    736|	int _ret = r; \
  |  |  |  |  155|    736|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 736, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    736|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 736]
  |  |  |  |  ------------------
  |  |  |  |  157|    736|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    736|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    736|	return _ret; \
  |  |  |  |  163|    736|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|    736|}
card-iasecc.c:iasecc_select_file:
  863|  8.35k|{
  864|  8.35k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  865|  8.35k|	struct sc_context *ctx = card->ctx;
  866|  8.35k|	struct sc_path lpath;
  867|  8.35k|	int rv, ii;
  868|       |
  869|  8.35k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  8.35k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.35k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.35k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.35k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  870|  8.35k|	memcpy(&lpath, path, sizeof(struct sc_path));
  871|  8.35k|	if (file_out)
  ------------------
  |  Branch (871:6): [True: 3.95k, False: 4.39k]
  ------------------
  872|  3.95k|		*file_out = NULL;
  873|       |
  874|  8.35k|	sc_log(ctx, "iasecc_select_file(card:%p) path.len %zu; path.type %i; aid_len %zu",
  ------------------
  |  |   71|  8.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  875|  8.35k|			card, path->len, path->type, path->aid.len);
  876|  8.35k|	sc_log(ctx, "iasecc_select_file() path:%s", sc_print_path(path));
  ------------------
  |  |   71|  8.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  877|       |
  878|  8.35k|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (878:6): [True: 7.59k, False: 759]
  ------------------
  879|  7.59k|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (879:6): [True: 7.52k, False: 73]
  ------------------
  880|  7.52k|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  15.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (880:7): [True: 2.99k, False: 4.52k]
  ------------------
  881|  2.99k|			&& lpath.len >= 2
  ------------------
  |  Branch (881:7): [True: 2.99k, False: 0]
  ------------------
  882|  2.99k|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (882:7): [True: 2.93k, False: 62]
  |  Branch (882:33): [True: 2.92k, False: 9]
  ------------------
  883|  2.92k|		sc_log(ctx, "EF.ATR(aid:'%s')", card->ef_atr ? sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len) : "");
  ------------------
  |  |   71|  5.84k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 2.76k, False: 156]
  |  |  ------------------
  ------------------
  884|       |
  885|  2.92k|		rv = iasecc_select_mf(card, file_out);
  886|  2.92k|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|  2.92k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.92k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.92k|	int _ret = (r); \
  |  |  |  |  168|  2.92k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.25k, False: 667]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.25k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.25k|		return _ret; \
  |  |  |  |  172|  2.25k|	} \
  |  |  |  |  173|  2.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 667]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  887|       |
  888|    667|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  889|    667|		lpath.len -=  2;
  890|    667|	}
  891|       |
  892|  6.09k|	if (lpath.aid.len)	{
  ------------------
  |  Branch (892:6): [True: 12, False: 6.08k]
  ------------------
  893|     12|		struct sc_file *file = NULL;
  894|     12|		struct sc_path ppath;
  895|       |
  896|     12|		sc_log(ctx, "iasecc_select_file() select parent AID:%p/%zu", lpath.aid.value, lpath.aid.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__
  |  |  ------------------
  ------------------
  897|     12|		sc_log(ctx, "iasecc_select_file() select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.aid.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__
  |  |  ------------------
  ------------------
  898|     12|		memset(&ppath, 0, sizeof(ppath));
  899|     12|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  900|     12|		ppath.len = lpath.aid.len;
  901|     12|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|     12|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  902|       |
  903|     12|		rv = iasecc_select_file(card, &ppath, &file);
  904|     12|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path failed");
  ------------------
  |  |  184|     12|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     12|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     12|	int _ret = (r); \
  |  |  |  |  178|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  905|       |
  906|      4|		if (file_out) {
  ------------------
  |  Branch (906:7): [True: 4, False: 0]
  ------------------
  907|      4|			sc_file_free(*file_out);
  908|      4|			*file_out = file;
  909|      4|		} else {
  910|      0|			sc_file_free(file);
  911|      0|		}
  912|       |
  913|      4|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      4|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (913:7): [True: 0, False: 4]
  ------------------
  914|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  915|      4|	}
  916|       |
  917|  6.08k|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  6.08k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (917:6): [True: 1.36k, False: 4.72k]
  ------------------
  918|  1.36k|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|  1.36k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  919|       |
  920|  6.08k|	if (!lpath.len) {
  ------------------
  |  Branch (920:6): [True: 8, False: 6.07k]
  ------------------
  921|      8|		if (file_out) {
  ------------------
  |  Branch (921:7): [True: 3, False: 5]
  ------------------
  922|      3|			sc_file_free(*file_out);
  923|      3|			*file_out = NULL;
  924|      3|		}
  925|      8|		LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|      8|	}
  927|       |
  928|  6.07k|	do   {
  929|  6.07k|		struct sc_apdu apdu;
  930|  6.07k|		struct sc_file *file = NULL;
  931|  6.07k|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  932|  6.07k|		size_t pathlen = lpath.len;
  933|       |
  934|  6.07k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  6.07k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  935|       |
  936|  6.07k|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (936:7): [True: 6.00k, False: 73]
  ------------------
  937|  6.00k|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (937:8): [True: 5.85k, False: 149]
  ------------------
  938|  5.85k|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (938:8): [True: 5.76k, False: 88]
  ------------------
  939|  5.76k|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (939:8): [True: 5.71k, False: 59]
  ------------------
  940|  5.71k|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (940:8): [True: 820, False: 4.89k]
  ------------------
  941|    820|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (941:8): [True: 755, False: 65]
  ------------------
  942|    755|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (942:8): [True: 0, False: 755]
  ------------------
  943|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  944|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Unsupported card");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  945|      0|		}
  946|       |
  947|  6.07k|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  6.07k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (947:7): [True: 4, False: 6.07k]
  ------------------
  948|      4|			apdu.p1 = 0x02;
  949|      4|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (949:8): [True: 0, False: 4]
  ------------------
  950|      0|				apdu.p1 = 0x01;
  951|      4|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (951:8): [True: 0, False: 4]
  ------------------
  952|      4|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (952:8): [True: 0, False: 4]
  ------------------
  953|      4|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (953:8): [True: 0, False: 4]
  ------------------
  954|      4|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (954:8): [True: 0, False: 4]
  ------------------
  955|      4|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (955:8): [True: 0, False: 4]
  ------------------
  956|      4|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (956:8): [True: 4, False: 0]
  ------------------
  957|      4|			    )   {
  958|      4|				apdu.p2 = 0x04;
  959|      4|			}
  960|      4|		}
  961|  6.07k|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|  6.07k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (961:12): [True: 1.36k, False: 4.71k]
  ------------------
  962|  1.36k|			apdu.p1 = 0x09;
  963|  1.36k|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (963:8): [True: 64, False: 1.29k]
  ------------------
  964|  1.29k|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (964:8): [True: 39, False: 1.25k]
  ------------------
  965|  1.25k|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (965:8): [True: 533, False: 726]
  ------------------
  966|    726|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (966:8): [True: 35, False: 691]
  ------------------
  967|    691|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (967:8): [True: 67, False: 624]
  ------------------
  968|  1.30k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (968:8): [True: 569, False: 55]
  ------------------
  969|  1.30k|				apdu.p2 = 0x04;
  970|  1.30k|			}
  971|  1.36k|		}
  972|  4.71k|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|  4.71k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (972:12): [True: 0, False: 4.71k]
  ------------------
  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|  4.71k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  4.71k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (977:12): [True: 4.71k, False: 0]
  ------------------
  978|  4.71k|			apdu.p1 = 0x04;
  979|  4.71k|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (979:8): [True: 20, False: 4.69k]
  ------------------
  980|  4.69k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (980:8): [True: 30, False: 4.66k]
  ------------------
  981|  4.66k|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (981:8): [True: 85, False: 4.57k]
  ------------------
  982|  4.57k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (982:8): [True: 6, False: 4.57k]
  ------------------
  983|  4.57k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (983:8): [True: 182, False: 4.39k]
  ------------------
  984|    323|				apdu.p2 = 0x04;
  985|    323|			}
  986|  4.71k|		}
  987|      0|		else   {
  988|      0|			sc_log(ctx, "Invalid PATH type: 0x%X", lpath.type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  989|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  990|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() invalid PATH type");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  991|      0|		}
  992|       |
  993|  6.18k|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (993:14): [True: 6.18k, False: 0]
  ------------------
  994|  6.18k|			apdu.lc = pathlen;
  995|  6.18k|			apdu.data = lpath.value;
  996|  6.18k|			apdu.datalen = pathlen;
  997|       |
  998|  6.18k|			apdu.resp = rbuf;
  999|  6.18k|			apdu.resplen = sizeof(rbuf);
 1000|  6.18k|			apdu.le = 256;
 1001|       |
 1002|  6.18k|			rv = sc_transmit_apdu(card, &apdu);
 1003|  6.18k|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|  6.18k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.18k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.18k|	int _ret = (r); \
  |  |  |  |  178|  6.18k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 23, False: 6.15k]
  |  |  |  |  ------------------
  |  |  |  |  179|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     23|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     23|		goto err; \
  |  |  |  |  182|     23|	} \
  |  |  |  |  183|  6.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 6.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1004|  6.15k|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  6.15k|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|  12.3k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1005:8): [True: 158, False: 6.00k]
  ------------------
 1006|    158|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|  6.31k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1006:6): [True: 128, False: 30]
  |  Branch (1006:44): [True: 103, False: 25]
  ------------------
 1007|    103|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   71|    103|#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|    103|				apdu.p2 = 0x0C;
 1009|    103|				continue;
 1010|    103|			}
 1011|       |
 1012|  6.05k|			if (ii)   {
  ------------------
  |  Branch (1012:8): [True: 103, False: 5.95k]
  ------------------
 1013|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1014|    103|				apdu.resplen = sizeof(rbuf);
 1015|    103|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1016|    103|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  184|    103|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    103|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    103|	int _ret = (r); \
  |  |  |  |  178|    103|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 103]
  |  |  |  |  ------------------
  |  |  |  |  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|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 103]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1017|    103|			}
 1018|       |
 1019|  6.05k|			break;
 1020|  6.05k|		}
 1021|       |
 1022|  6.05k|		LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() check SW failed");
  ------------------
  |  |  184|  6.05k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.05k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.05k|	int _ret = (r); \
  |  |  |  |  178|  6.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.50k, False: 2.55k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.50k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.50k|		goto err; \
  |  |  |  |  182|  3.50k|	} \
  |  |  |  |  183|  6.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.55k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1023|       |
 1024|  2.55k|		sc_log(ctx, "iasecc_select_file() apdu.resp %zu", apdu.resplen);
  ------------------
  |  |   71|  2.55k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1025|  2.55k|		if (apdu.resplen)   {
  ------------------
  |  Branch (1025:7): [True: 1.02k, False: 1.53k]
  ------------------
 1026|  1.02k|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   71|  1.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1027|       |
 1028|  1.02k|			switch (apdu.resp[0]) {
 1029|    115|			case 0x62:
  ------------------
  |  Branch (1029:4): [True: 115, False: 907]
  ------------------
 1030|    952|			case 0x6F:
  ------------------
  |  Branch (1030:4): [True: 837, False: 185]
  ------------------
 1031|    952|				file = sc_file_new();
 1032|    952|				if (file == NULL) {
  ------------------
  |  Branch (1032:9): [True: 0, False: 952]
  ------------------
 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|    952|				file->path = lpath;
 1040|       |
 1041|    952|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1042|    952|				if (rv) {
  ------------------
  |  Branch (1042:9): [True: 74, False: 878]
  ------------------
 1043|     74|					sc_file_free(file);
 1044|     74|					if (file_out) {
  ------------------
  |  Branch (1044:10): [True: 46, False: 28]
  ------------------
 1045|     46|						sc_file_free(*file_out);
 1046|     46|						*file_out = NULL;
 1047|     46|					}
 1048|     74|					LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|     74|				}
 1050|    878|				break;
 1051|    878|			default:
  ------------------
  |  Branch (1051:4): [True: 70, False: 952]
  ------------------
 1052|     70|				if (file_out) {
  ------------------
  |  Branch (1052:9): [True: 38, False: 32]
  ------------------
 1053|     38|					sc_file_free(*file_out);
 1054|     38|					*file_out = NULL;
 1055|     38|				}
 1056|     70|				LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     70|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     70|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     70|	return _ret; \
  |  |  |  |  163|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|  1.02k|			}
 1058|       |
 1059|    878|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   71|    878|#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|    878|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    878|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1060:8): [True: 110, False: 768]
  ------------------
 1061|    110|				sc_invalidate_cache(card);
 1062|    110|				sc_file_dup(&prv->cache.current_df, file);
 1063|    110|				prv->cache.valid = 1;
 1064|    110|			}
 1065|    768|			else   {
 1066|    768|				sc_file_free(prv->cache.current_ef);
 1067|    768|				sc_file_dup(&prv->cache.current_ef, file);
 1068|    768|				prv->cache.valid = 1;
 1069|    768|			}
 1070|       |
 1071|    878|			if (file_out)   {
  ------------------
  |  Branch (1071:8): [True: 724, False: 154]
  ------------------
 1072|    724|				sc_file_free(*file_out);
 1073|    724|				*file_out = file;
 1074|    724|			}
 1075|    154|			else   {
 1076|    154|				sc_file_free(file);
 1077|    154|			}
 1078|    878|		}
 1079|  1.53k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.53k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1079:12): [True: 1.37k, False: 160]
  ------------------
 1080|  1.37k|			sc_invalidate_cache(card);
 1081|  1.37k|			prv->cache.valid = 1;
 1082|  1.37k|		}
 1083|  2.55k|	} while(0);
  ------------------
  |  Branch (1083:10): [Folded, False: 2.41k]
  ------------------
 1084|       |
 1085|  2.41k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.41k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.41k|	int _ret = r; \
  |  |  |  |  155|  2.41k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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: 2.41k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.41k|	return _ret; \
  |  |  |  |  163|  2.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1086|  3.53k|err:
 1087|  3.53k|	if (file_out) {
  ------------------
  |  Branch (1087:6): [True: 1.45k, False: 2.07k]
  ------------------
 1088|  1.45k|		sc_file_free(*file_out);
 1089|       |		*file_out = NULL;
 1090|  1.45k|	}
 1091|  3.53k|	return rv;
 1092|  2.41k|}
card-iasecc.c:iasecc_emulate_fcp:
  828|    103|{
  829|    103|	unsigned char dummy_df_fcp[] = {
  830|    103|		0x62,0xFF,
  831|    103|			0x82,0x01,0x38,
  832|    103|			0x8A,0x01,0x05,
  833|    103|			0xA1,0x04,0x8C,0x02,0x02,0x00,
  834|    103|			0x84,0xFF,
  835|    103|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  836|    103|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  837|    103|	};
  838|       |
  839|    103|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    103|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    103|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    103|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    103|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 103]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|       |
  841|    103|	if (apdu->p1 != 0x04)
  ------------------
  |  Branch (841:6): [True: 0, False: 103]
  ------------------
  842|    103|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "FCP emulation supported only for the DF-NAME selection type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|    103|	if (apdu->datalen > 16)
  ------------------
  |  Branch (843:6): [True: 0, False: 103]
  ------------------
  844|    103|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid DF-NAME length");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|    103|	if (apdu->resplen < apdu->datalen + 16)
  ------------------
  |  Branch (845:6): [True: 0, False: 103]
  ------------------
  846|    103|		LOG_TEST_RET(ctx, SC_ERROR_BUFFER_TOO_SMALL, "not enough space for FCP data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  847|       |
  848|    103|	memcpy(dummy_df_fcp + 16, apdu->data, apdu->datalen);
  849|    103|	dummy_df_fcp[15] = apdu->datalen;
  850|    103|	dummy_df_fcp[1] = apdu->datalen + 14;
  851|    103|	apdu->resplen = apdu->datalen + 16;
  852|    103|	memcpy(apdu->resp, dummy_df_fcp, apdu->resplen);
  853|       |
  854|    103|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    103|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    103|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    103|	int _ret = r; \
  |  |  |  |  155|    103|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 103]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    103|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    103|	return _ret; \
  |  |  |  |  163|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  855|    103|}
card-iasecc.c:iasecc_process_fci:
 1098|    952|{
 1099|    952|	struct sc_context *ctx = card->ctx;
 1100|    952|	size_t taglen, offs, ii;
 1101|    952|	int rv;
 1102|    952|	const unsigned char *acls = NULL, *tag = NULL;
 1103|    952|	unsigned char mask;
 1104|    952|	unsigned char ops_DF[7] = {
 1105|    952|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|    952|#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|    952|#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|    952|#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|    952|#define SC_AC_OP_CREATE			3
  ------------------
 1106|    952|	};
 1107|    952|	unsigned char ops_EF[7] = {
 1108|    952|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|    952|#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|    952|#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|    952|#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|    952|#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|    952|#define SC_AC_OP_READ			22
  ------------------
 1109|    952|	};
 1110|       |
 1111|    952|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    952|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    952|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    952|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    952|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|       |
 1113|    952|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1114|    952|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1115|    952|	if (tag != NULL) {
  ------------------
  |  Branch (1115:6): [True: 812, False: 140]
  ------------------
 1116|    812|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    812|#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|    812|		buf = tag;
 1118|    812|		buflen = taglen;
 1119|    812|	}
 1120|       |
 1121|    952|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1122|    952|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1123|    952|	if (tag != NULL) {
  ------------------
  |  Branch (1123:6): [True: 108, False: 844]
  ------------------
 1124|    108|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1125|    108|		buf = tag;
 1126|    108|		buflen = taglen;
 1127|    108|	}
 1128|       |
 1129|    952|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1130|    952|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    952|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    952|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    952|	int _ret = (r); \
  |  |  |  |  168|    952|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 952]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    952|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 952]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    952|	sc_log(ctx, "iasecc_process_fci() type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   71|    952|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1138|    952|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|    952|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1139|    952|	if (tag)
  ------------------
  |  Branch (1139:6): [True: 104, False: 848]
  ------------------
 1140|    104|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    104|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1141|    848|	else
 1142|    848|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    848|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1143|       |
 1144|    952|	if (!acls)   {
  ------------------
  |  Branch (1144:6): [True: 74, False: 878]
  ------------------
 1145|     74|		sc_log(ctx, "ACLs not found in data(%zu) %s", buflen, sc_dump_hex(buf, buflen));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1146|     74|		LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     74|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     74|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     74|	int _ret = (r); \
  |  |  |  |  168|     74|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 74, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     74|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     74|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     74|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     74|		return _ret; \
  |  |  |  |  172|     74|	} \
  |  |  |  |  173|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|     74|	}
 1148|       |
 1149|    878|	sc_log(ctx, "ACLs(%zu) '%s'", taglen, sc_dump_hex(acls, taglen));
  ------------------
  |  |   71|    878|#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|    878|	mask = 0x40, offs = 1;
 1151|  5.36k|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1151:15): [True: 4.85k, False: 509]
  ------------------
 1152|  4.85k|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|  4.85k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1152:22): [True: 755, False: 4.10k]
  ------------------
 1153|       |
 1154|       |		/* avoid any access to acls[offs] beyond the taglen */
 1155|  4.85k|		if (offs >= taglen) {
  ------------------
  |  Branch (1155:7): [True: 369, False: 4.48k]
  ------------------
 1156|    369|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   71|    369|#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|    369|			break;
 1158|    369|		}
 1159|  4.48k|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1159:7): [True: 1.84k, False: 2.64k]
  ------------------
 1160|  1.84k|			continue;
 1161|       |
 1162|  2.64k|		sc_log(ctx, "ACLs mask 0x%X, offs %zu, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|  2.64k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1163|  2.64k|		if (op == 0xFF)   {
  ------------------
  |  Branch (1163:7): [True: 711, False: 1.93k]
  ------------------
 1164|    711|			;
 1165|    711|		}
 1166|  1.93k|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1166:12): [True: 478, False: 1.45k]
  ------------------
 1167|    478|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    478|#define SC_AC_NONE			0x00000000
  ------------------
 1168|    478|		}
 1169|  1.45k|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1169:12): [True: 167, False: 1.29k]
  ------------------
 1170|    167|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    167|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1171|    167|		}
 1172|  1.29k|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|  1.29k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|  1.29k|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1172:12): [True: 146, False: 1.14k]
  ------------------
 1173|    146|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|    146|#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|    146|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1174|    146|		}
 1175|  1.14k|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|  1.14k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1175:12): [True: 810, False: 335]
  ------------------
 1176|    810|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|    810|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1177|    810|		}
 1178|    335|		else   {
 1179|    335|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   71|    335|#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|    335|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    335|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1181|    335|		}
 1182|       |
 1183|  2.64k|		offs++;
 1184|  2.64k|	}
 1185|       |
 1186|    878|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    878|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    878|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    878|	int _ret = r; \
  |  |  |  |  155|    878|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 878, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    878|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 878]
  |  |  |  |  ------------------
  |  |  |  |  157|    878|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    878|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    878|	return _ret; \
  |  |  |  |  163|    878|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1187|    878|}
card-iasecc.c:iasecc_se_get_info_from_cache:
 1568|    209|{
 1569|    209|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1570|    209|	struct sc_context *ctx = card->ctx;
 1571|    209|	struct iasecc_se_info *si = NULL;
 1572|    209|	int rv;
 1573|       |
 1574|    209|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    209|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    209|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    209|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    209|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 209]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1575|       |
 1576|    231|	for(si = prv->se_info; si; si = si->next)   {
  ------------------
  |  Branch (1576:25): [True: 25, False: 206]
  ------------------
 1577|     25|		if (si->reference != se->reference)
  ------------------
  |  Branch (1577:7): [True: 20, False: 5]
  ------------------
 1578|     20|			continue;
 1579|      5|		if (!(prv->cache.valid && prv->cache.current_df) && si->df)
  ------------------
  |  Branch (1579:9): [True: 5, False: 0]
  |  Branch (1579:29): [True: 3, False: 2]
  |  Branch (1579:55): [True: 2, False: 0]
  ------------------
 1580|      2|			continue;
 1581|      3|		if (prv->cache.valid && prv->cache.current_df && !si->df)
  ------------------
  |  Branch (1581:7): [True: 3, False: 0]
  |  Branch (1581:27): [True: 3, False: 0]
  |  Branch (1581:52): [True: 0, False: 3]
  ------------------
 1582|      0|			continue;
 1583|      3|		if (prv->cache.valid && prv->cache.current_df && si->df)
  ------------------
  |  Branch (1583:7): [True: 3, False: 0]
  |  Branch (1583:27): [True: 3, False: 0]
  |  Branch (1583:52): [True: 3, False: 0]
  ------------------
 1584|      3|			if (memcmp(&prv->cache.current_df->path, &si->df->path, sizeof(struct sc_path)))
  ------------------
  |  Branch (1584:8): [True: 0, False: 3]
  ------------------
 1585|      0|				continue;
 1586|      3|		break;
 1587|      3|	}
 1588|       |
 1589|    209|	if (!si)
  ------------------
  |  Branch (1589:6): [True: 206, False: 3]
  ------------------
 1590|    206|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    206|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1591|       |
 1592|      3|	memcpy(se, si, sizeof(struct iasecc_se_info));
 1593|       |
 1594|      3|	if (si->df)   {
  ------------------
  |  Branch (1594:6): [True: 3, False: 0]
  ------------------
 1595|      3|		sc_file_dup(&se->df, si->df);
 1596|      3|		if (se->df == NULL)
  ------------------
  |  Branch (1596:7): [True: 0, False: 3]
  ------------------
 1597|      3|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot duplicate current DF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1598|      3|	}
 1599|       |
 1600|      3|	rv = iasecc_docp_copy(ctx, &si->docp, &se->docp);
 1601|      3|	LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1602|       |
 1603|      3|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1604|      3|}
card-iasecc.c:iasecc_se_cache_info:
 1525|     30|{
 1526|     30|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1527|     30|	struct sc_context *ctx = card->ctx;
 1528|     30|	struct iasecc_se_info *se_info = NULL, *si = NULL;
 1529|     30|	int rv;
 1530|       |
 1531|     30|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1532|       |
 1533|     30|	se_info = calloc(1, sizeof(struct iasecc_se_info));
 1534|     30|	if (!se_info)
  ------------------
  |  Branch (1534:6): [True: 0, False: 30]
  ------------------
 1535|     30|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "SE info allocation error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1536|     30|	memcpy(se_info, se, sizeof(struct iasecc_se_info));
 1537|       |
 1538|     30|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (1538:6): [True: 30, False: 0]
  |  Branch (1538:26): [True: 28, False: 2]
  ------------------
 1539|     28|		sc_file_dup(&se_info->df, prv->cache.current_df);
 1540|     28|		if (se_info->df == NULL)   {
  ------------------
  |  Branch (1540:7): [True: 0, False: 28]
  ------------------
 1541|      0|			free(se_info);
 1542|      0|			LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot duplicate current DF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1543|      0|		}
 1544|     28|	}
 1545|       |
 1546|     30|	rv = iasecc_docp_copy(ctx, &se->docp, &se_info->docp);
 1547|     30|	if (rv < 0)   {
  ------------------
  |  Branch (1547:6): [True: 0, False: 30]
  ------------------
 1548|      0|		free(se_info->df);
 1549|      0|		free(se_info);
 1550|      0|		LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1551|      0|	}
 1552|       |
 1553|     30|	if (!prv->se_info)   {
  ------------------
  |  Branch (1553:6): [True: 22, False: 8]
  ------------------
 1554|     22|		prv->se_info = se_info;
 1555|     22|	}
 1556|      8|	else    {
 1557|     12|		for (si = prv->se_info; si->next; si = si->next)
  ------------------
  |  Branch (1557:27): [True: 4, False: 8]
  ------------------
 1558|      4|			;
 1559|      8|		si->next = se_info;
 1560|      8|	}
 1561|       |
 1562|     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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1563|     30|}
card-iasecc.c:sc_get_driver:
 3591|  16.9k|{
 3592|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3593|       |
 3594|  16.9k|	if (!iso_ops)
  ------------------
  |  Branch (3594:6): [True: 1, False: 16.9k]
  ------------------
 3595|      1|		iso_ops = iso_drv->ops;
 3596|       |
 3597|  16.9k|	iasecc_ops = *iso_ops;
 3598|       |
 3599|  16.9k|	iasecc_ops.match_card = iasecc_match_card;
 3600|  16.9k|	iasecc_ops.init = iasecc_init;
 3601|  16.9k|	iasecc_ops.finish = iasecc_finish;
 3602|  16.9k|	iasecc_ops.read_binary = iasecc_read_binary;
 3603|       |	/*	write_binary: ISO7816 implementation works	*/
 3604|       |	/*	update_binary: ISO7816 implementation works	*/
 3605|  16.9k|	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|  16.9k|	iasecc_ops.select_file = iasecc_select_file;
 3612|       |	/*	get_response: Untested	*/
 3613|  16.9k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3614|  16.9k|	iasecc_ops.logout = iasecc_logout;
 3615|       |	/*	restore_security_env	*/
 3616|  16.9k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3617|  16.9k|	iasecc_ops.decipher = iasecc_decipher;
 3618|  16.9k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3619|  16.9k|	iasecc_ops.create_file = iasecc_create_file;
 3620|  16.9k|	iasecc_ops.delete_file = iasecc_delete_file;
 3621|       |	/*	list_files	*/
 3622|  16.9k|	iasecc_ops.check_sw = iasecc_check_sw;
 3623|  16.9k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3624|  16.9k|	iasecc_ops.process_fci = iasecc_process_fci;
 3625|       |	/*	construct_fci: Not needed	*/
 3626|  16.9k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3627|       |	/*	get_data: Not implemented	*/
 3628|       |	/*	put_data: Not implemented	*/
 3629|       |	/*	delete_record: Not implemented	*/
 3630|       |
 3631|  16.9k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3632|       |
 3633|  16.9k|	return &iasecc_drv;
 3634|  16.9k|}
card-iasecc.c:iasecc_match_card:
  353|  11.2k|{
  354|  11.2k|	struct sc_context *ctx = card->ctx;
  355|  11.2k|	int i;
  356|       |
  357|  11.2k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  358|  11.2k|	if (i < 0)   {
  ------------------
  |  Branch (358:6): [True: 10.3k, False: 933]
  ------------------
  359|  10.3k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  10.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  360|  10.3k|		return 0;
  361|  10.3k|	}
  362|       |
  363|    933|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|    933|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  364|    933|	return 1;
  365|  11.2k|}
card-iasecc.c:iasecc_init:
  624|    933|{
  625|    933|	struct sc_context *ctx = card->ctx;
  626|    933|	struct iasecc_private_data *private_data = NULL;
  627|    933|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    933|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  628|    933|	void *old_drv_data = card->drv_data;
  629|       |
  630|    933|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    933|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    933|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    933|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    933|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 933]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|    933|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  632|    933|	if (private_data == NULL)
  ------------------
  |  Branch (632:6): [True: 0, False: 933]
  ------------------
  633|    933|		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|    933|	card->cla  = 0x00;
  636|    933|	card->drv_data = private_data;
  637|       |
  638|    933|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (638:6): [True: 25, False: 908]
  ------------------
  639|     25|		rv = iasecc_init_gemalto(card);
  640|    908|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (640:11): [True: 64, False: 844]
  ------------------
  641|     64|		rv = iasecc_init_oberthur(card);
  642|    844|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (642:11): [True: 44, False: 800]
  ------------------
  643|     44|		rv = iasecc_init_amos_or_sagem(card);
  644|    800|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (644:11): [True: 14, False: 786]
  ------------------
  645|     14|		rv = iasecc_init_amos_or_sagem(card);
  646|    786|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (646:11): [True: 547, False: 239]
  ------------------
  647|    547|		rv = iasecc_init_amos_or_sagem(card);
  648|    239|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (648:11): [True: 239, False: 0]
  ------------------
  649|    239|		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|    933|	if (!rv)   {
  ------------------
  |  Branch (655:6): [True: 645, False: 288]
  ------------------
  656|    645|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (656:7): [True: 645, False: 0]
  |  Branch (656:23): [True: 529, False: 116]
  ------------------
  657|    529|			struct sc_path path;
  658|       |
  659|    529|			memset(&path, 0, sizeof(struct sc_path));
  660|    529|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    529|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  661|    529|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  662|    529|			path.len = card->ef_atr->aid.len;
  663|       |
  664|    529|			rv = iasecc_select_file(card, &path, NULL);
  665|    529|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", rv);
  ------------------
  |  |   71|    529|#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|    529|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID failed");
  ------------------
  |  |  184|    529|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    529|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    529|	int _ret = (r); \
  |  |  |  |  178|    529|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7, False: 522]
  |  |  |  |  ------------------
  |  |  |  |  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|    529|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 522]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|    529|		}
  668|       |
  669|    638|		iasecc_get_serialnr(card, NULL);
  670|    638|	}
  671|       |
  672|    926|#ifdef ENABLE_SM
  673|    926|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  674|    926|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  675|    926|#endif
  676|       |
  677|    926|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (677:6): [True: 638, False: 288]
  |  Branch (677:13): [True: 638, False: 0]
  |  Branch (677:29): [True: 522, False: 116]
  ------------------
  678|    522|		sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|    522|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  679|    522|	}
  680|       |
  681|    933|err:
  682|    933|	if (rv < 0) {
  ------------------
  |  Branch (682:6): [True: 295, False: 638]
  ------------------
  683|    295|		sc_invalidate_cache(card);
  684|    295|		free(private_data);
  685|    295|		card->drv_data = old_drv_data;
  686|    638|	} else {
  687|    638|		free(old_drv_data);
  688|    638|	}
  689|       |
  690|    933|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    933|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    933|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    933|	int _ret = r; \
  |  |  |  |  155|    933|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 933, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    933|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    295|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 295, False: 638]
  |  |  |  |  ------------------
  |  |  |  |  157|    933|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    933|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    933|	return _ret; \
  |  |  |  |  163|    933|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|    933|}
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: 21, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  450|       |
  451|      3|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  452|      3|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  453|       |
  454|      3|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|      3|}
card-iasecc.c:iasecc_parse_ef_atr:
  369|    434|{
  370|    434|	struct sc_context *ctx = card->ctx;
  371|    434|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  372|    434|	struct iasecc_version *version = &pdata->version;
  373|    434|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  374|    434|	int rv;
  375|       |
  376|    434|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    434|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    434|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    434|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    434|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 434]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    434|	rv = sc_parse_ef_atr(card);
  378|    434|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    434|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    434|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    434|	int _ret = (r); \
  |  |  |  |  168|    434|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 210, False: 224]
  |  |  |  |  ------------------
  |  |  |  |  169|    210|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    210|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    210|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    210|		return _ret; \
  |  |  |  |  172|    210|	} \
  |  |  |  |  173|    434|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 224]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|    224|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (380:6): [True: 97, False: 127]
  ------------------
  381|    224|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  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: 97, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    127|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  384|    127|	version->ic_type =		card->ef_atr->pre_issuing[1];
  385|    127|	version->os_version =		card->ef_atr->pre_issuing[2];
  386|    127|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  387|    127|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  388|    127|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  389|       |
  390|    127|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (390:6): [True: 6, False: 121]
  ------------------
  391|    127|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |
  393|    121|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  394|    121|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  395|    121|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  396|    121|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  397|       |
  398|    121|	sc_log(ctx, "EF.ATR: IO Buffer Size send/sc %zd/%zd recv/sc %zd/%zd",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  399|    121|			sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  400|       |
  401|    121|	card->max_send_size = sizes->send;
  402|    121|	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|    121|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (408:6): [True: 103, False: 18]
  ------------------
  409|    103|		card->max_send_size -= 5;
  410|       |
  411|    121|	sc_log(ctx, "EF.ATR: max send/recv sizes %zX/%zX", card->max_send_size, card->max_recv_size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  412|       |
  413|    121|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    121|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    121|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    121|	int _ret = r; \
  |  |  |  |  155|    121|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 121, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 121]
  |  |  |  |  ------------------
  |  |  |  |  157|    121|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    121|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    121|	return _ret; \
  |  |  |  |  163|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|    121|}
card-iasecc.c:iasecc_init_oberthur:
  488|     64|{
  489|     64|	struct sc_context *ctx = card->ctx;
  490|     64|	unsigned int flags;
  491|     64|	int rv = 0;
  492|       |
  493|     64|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     64|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     64|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     64|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     64|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|       |
  495|     64|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     64|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     64|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     64|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     64|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     64|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     64|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     64|#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|     64|#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|     64|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     64|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     64|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     64|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     64|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     64|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     64|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  496|       |
  497|     64|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  498|     64|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  499|       |
  500|     64|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     64|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     64|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     64|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     64|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     64|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     64|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     64|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     64|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     64|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  501|       |
  502|     64|	iasecc_parse_ef_atr(card);
  503|       |
  504|       |	/* if we fail to select CM, */
  505|     64|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (505:6): [True: 46, False: 18]
  ------------------
  506|     46|		gp_select_isd_rid(card);
  507|     46|	}
  508|       |
  509|     64|	rv = iasecc_oberthur_match(card);
  510|     64|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|       |
  512|     64|	rv = iasecc_select_mf(card, NULL);
  513|     64|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 51, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  169|     51|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     51|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     51|		return _ret; \
  |  |  |  |  172|     51|	} \
  |  |  |  |  173|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|       |
  515|     13|	rv = iasecc_parse_ef_atr(card);
  516|     13|	LOG_TEST_RET(ctx, rv, "EF.ATR read or parse error");
  ------------------
  |  |  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: 8, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|       |
  518|      5|	sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.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__
  |  |  ------------------
  ------------------
  519|      5|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      5|}
card-iasecc.c:iasecc_oberthur_match:
  460|     64|{
  461|     64|	struct sc_context *ctx = card->ctx;
  462|     64|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  463|       |
  464|     64|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     64|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     64|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     64|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     64|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|       |
  466|     64|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (466:6): [True: 0, False: 64]
  |  Branch (466:23): [True: 0, False: 64]
  ------------------
  467|     64|		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|     64|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|     64|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     64|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|       |
  471|     64|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (471:6): [True: 0, False: 64]
  ------------------
  472|     64|		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|     64|	if (!card->ef_atr)
  ------------------
  |  Branch (474:6): [True: 38, False: 26]
  ------------------
  475|     38|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  476|     64|	if (!card->ef_atr)
  ------------------
  |  Branch (476:6): [True: 0, False: 64]
  ------------------
  477|     64|		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|     64|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  480|     64|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  481|       |
  482|     64|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  483|     64|}
card-iasecc.c:iasecc_init_amos_or_sagem:
  550|    605|{
  551|    605|	struct sc_context *ctx = card->ctx;
  552|    605|	unsigned int flags;
  553|    605|	int rv = 0;
  554|       |
  555|    605|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    605|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    605|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    605|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    605|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 605]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|       |
  557|    605|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    605|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    605|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    605|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    605|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    605|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    605|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    605|#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|    605|#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|    605|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    605|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    605|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    605|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    605|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    605|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    605|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  558|       |
  559|    605|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  560|    605|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  561|       |
  562|    605|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    605|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    605|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    605|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    605|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    605|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    605|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    605|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    605|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    605|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  563|       |
  564|    605|	if (card->type == SC_CARD_TYPE_IASECC_MI)   {
  ------------------
  |  Branch (564:6): [True: 547, False: 58]
  ------------------
  565|    547|		rv = iasecc_mi_match(card);
  566|    547|		if (rv)
  ------------------
  |  Branch (566:7): [True: 23, False: 524]
  ------------------
  567|     23|			card->type = SC_CARD_TYPE_IASECC_MI2;
  568|    524|		else
  569|    547|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    524|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    524|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    524|	int _ret = r; \
  |  |  |  |  155|    524|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    524|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    524|	return _ret; \
  |  |  |  |  163|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|    547|	}
  571|       |
  572|     81|	rv = iasecc_parse_ef_atr(card);
  573|     81|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     81|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (573:6): [True: 16, False: 65]
  ------------------
  574|     16|		rv = iasecc_select_mf(card, NULL);
  575|     16|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  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: 5, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  576|       |
  577|     11|		rv = iasecc_parse_ef_atr(card);
  578|     11|	}
  579|     76|	LOG_TEST_RET(ctx, rv, "IASECC: ATR parse failed");
  ------------------
  |  |  174|     76|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     76|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     76|	int _ret = (r); \
  |  |  |  |  168|     76|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  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|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|     36|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     36|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     36|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     36|	int _ret = r; \
  |  |  |  |  155|     36|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  157|     36|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     36|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     36|	return _ret; \
  |  |  |  |  163|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|     36|}
card-iasecc.c:iasecc_mi_match:
  525|    547|{
  526|    547|	struct sc_context *ctx = card->ctx;
  527|    547|	unsigned char resp[0x100];
  528|    547|	size_t resp_len = sizeof(resp);
  529|    547|	int rv = 0;
  530|       |
  531|    547|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    547|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    547|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    547|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    547|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 547]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  532|       |
  533|    547|	rv = iso7816_select_aid(card, MIIASECC_AID.value, MIIASECC_AID.len, resp, &resp_len);
  534|    547|	LOG_TEST_RET(ctx, rv, "IASECC: failed to select MI IAS/ECC applet");
  ------------------
  |  |  174|    547|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    547|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    547|	int _ret = (r); \
  |  |  |  |  168|    547|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  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|    547|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 524]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|       |
  536|    524|	if (!card->ef_atr)
  ------------------
  |  Branch (536:6): [True: 524, False: 0]
  ------------------
  537|    524|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  538|    524|	if (!card->ef_atr)
  ------------------
  |  Branch (538:6): [True: 0, False: 524]
  ------------------
  539|    524|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|       |
  541|    524|	memcpy(card->ef_atr->aid.value, MIIASECC_AID.value, MIIASECC_AID.len);
  542|    524|	card->ef_atr->aid.len = MIIASECC_AID.len;
  543|       |
  544|    524|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    524|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    524|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    524|	int _ret = r; \
  |  |  |  |  155|    524|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    524|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    524|	return _ret; \
  |  |  |  |  163|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  545|    524|}
card-iasecc.c:iasecc_init_cpx:
  600|    239|{
  601|    239|	struct sc_context *ctx = card->ctx;
  602|    239|	unsigned int flags;
  603|    239|	int rv = 0;
  604|       |
  605|    239|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    239|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    239|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    239|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    239|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 239]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  606|       |
  607|    239|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    239|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    239|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    239|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    239|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    239|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    239|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    239|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    239|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    239|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  608|       |
  609|    239|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    239|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    239|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    239|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    239|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    239|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    239|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    239|#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|    239|#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|    239|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    239|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    239|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    239|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    239|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    239|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    239|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  610|       |
  611|    239|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  612|    239|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  613|    239|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  614|       |
  615|    239|	rv = iasecc_parse_ef_atr(card);
  616|    239|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  174|    239|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    239|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    239|	int _ret = (r); \
  |  |  |  |  168|    239|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 162, False: 77]
  |  |  |  |  ------------------
  |  |  |  |  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|    239|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 77]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|       |
  618|     77|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     77|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     77|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     77|	int _ret = r; \
  |  |  |  |  155|     77|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 77, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     77|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 77]
  |  |  |  |  ------------------
  |  |  |  |  157|     77|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     77|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     77|	return _ret; \
  |  |  |  |  163|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|     77|}
card-iasecc.c:iasecc_get_serialnr:
 2464|    895|{
 2465|    895|	struct sc_context *ctx = card->ctx;
 2466|    895|	struct sc_iin *iin = &card->serialnr.iin;
 2467|    895|	struct sc_apdu apdu;
 2468|    895|	unsigned char rbuf[0xC0];
 2469|    895|	size_t ii, offs, len;
 2470|    895|	int rv;
 2471|       |
 2472|    895|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    895|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    895|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    895|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    895|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 895]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2473|    895|	if (card->serialnr.len)
  ------------------
  |  Branch (2473:6): [True: 1, False: 894]
  ------------------
 2474|      1|		goto end;
 2475|       |
 2476|    894|	memset(&card->serialnr, 0, sizeof(card->serialnr));
 2477|       |
 2478|    894|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |  292|    894|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
              	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |   73|    894|#define IASECC_SFI_EF_SN	0x1C
  ------------------
 2479|    894|	apdu.le = sizeof(rbuf);
 2480|    894|	apdu.resp = rbuf;
 2481|    894|	apdu.resplen = sizeof(rbuf);
 2482|       |
 2483|    894|	rv = sc_transmit_apdu(card, &apdu);
 2484|    894|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    894|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    894|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    894|	int _ret = (r); \
  |  |  |  |  168|    894|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 878]
  |  |  |  |  ------------------
  |  |  |  |  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|    894|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 878]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|    878|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2486|    878|	LOG_TEST_RET(ctx, rv, "Get 'serial number' data failed");
  ------------------
  |  |  174|    878|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    878|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    878|	int _ret = (r); \
  |  |  |  |  168|    878|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 580, False: 298]
  |  |  |  |  ------------------
  |  |  |  |  169|    580|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    580|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    580|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    580|		return _ret; \
  |  |  |  |  172|    580|	} \
  |  |  |  |  173|    878|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 298]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2487|       |
 2488|    298|	if (apdu.resplen < 2 || rbuf[0] != ISO7812_PAN_SN_TAG || rbuf[1] > (apdu.resplen-2))
  ------------------
  |  |   29|    329|#define ISO7812_PAN_SN_TAG	0x5A
  ------------------
  |  Branch (2488:6): [True: 267, False: 31]
  |  Branch (2488:26): [True: 12, False: 19]
  |  Branch (2488:59): [True: 4, False: 15]
  ------------------
 2489|    298|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "serial number parse error");
  ------------------
  |  |  174|    283|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    283|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    283|	int _ret = (r); \
  |  |  |  |  168|    283|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 283, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    283|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    283|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    283|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    283|		return _ret; \
  |  |  |  |  172|    283|	} \
  |  |  |  |  173|    283|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2490|     15|	len = rbuf[1];
 2491|       |
 2492|     15|	iin->mii = (rbuf[2] >> 4) & 0x0F;
 2493|       |
 2494|     15|	iin->country = 0;
 2495|     60|	for (ii=5; ii<8; ii++)   {
  ------------------
  |  Branch (2495:13): [True: 45, False: 15]
  ------------------
 2496|     45|		iin->country *= 10;
 2497|     45|		iin->country += (rbuf[ii/2] >> ((ii & 0x01) ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2497:35): [True: 30, False: 15]
  ------------------
 2498|     45|	}
 2499|       |
 2500|     15|	iin->issuer_id = 0;
 2501|     45|	for (ii=8; ii<10; ii++)   {
  ------------------
  |  Branch (2501:13): [True: 30, False: 15]
  ------------------
 2502|     30|		iin->issuer_id *= 10;
 2503|     30|		iin->issuer_id += (rbuf[ii/2] >> (ii & 0x01 ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2503:37): [True: 15, False: 15]
  ------------------
 2504|     30|	}
 2505|       |
 2506|       |	/* Copy the serial number from the last 8 bytes (at most) */
 2507|     15|	offs = len > 8 ? len - 8 : 0;
  ------------------
  |  Branch (2507:9): [True: 3, False: 12]
  ------------------
 2508|     15|	if (card->type == SC_CARD_TYPE_IASECC_SAGEM)   {
  ------------------
  |  Branch (2508:6): [True: 7, False: 8]
  ------------------
 2509|       |		/* 5A 0A 92 50 00 20 10 10 25 00 01 3F */
 2510|       |		/*            00 02 01 01 02 50 00 13  */
 2511|     34|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2511:14): [True: 27, False: 7]
  ------------------
 2512|     27|			*(card->serialnr.value + ii) = ((rbuf[ii + offs + 1] & 0x0F) << 4)
 2513|     27|				+ ((rbuf[ii + offs + 2] & 0xF0) >> 4) ;
 2514|      7|		card->serialnr.len = ii;
 2515|      7|	}
 2516|      8|	else   {
 2517|     27|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2517:14): [True: 19, False: 8]
  ------------------
 2518|     19|			*(card->serialnr.value + ii) = rbuf[ii + offs + 2];
 2519|      8|		card->serialnr.len = ii;
 2520|      8|	}
 2521|       |
 2522|     15|	do  {
 2523|     15|		char txt[0x200];
 2524|       |
 2525|     61|		for (ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (2525:13): [True: 46, False: 15]
  ------------------
 2526|     46|			sprintf(txt + ii*2, "%02X", *(card->serialnr.value + ii));
 2527|       |
 2528|     15|		sc_log(ctx, "serial number '%s'; mii %i; country %i; issuer_id %li", txt, iin->mii, iin->country, iin->issuer_id);
  ------------------
  |  |   71|     15|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2529|     15|	} while(0);
  ------------------
  |  Branch (2529:10): [Folded, False: 15]
  ------------------
 2530|       |
 2531|     16|end:
 2532|     16|	if (serial)
  ------------------
  |  Branch (2532:6): [True: 2, False: 14]
  ------------------
 2533|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 2534|       |
 2535|     16|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2536|     16|}
card-iasecc.c:_iasecc_sm_read_binary:
  760|    293|{
  761|    293|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  762|    293|	struct sc_context *ctx = card->ctx;
  763|    293|	const struct sc_acl_entry *entry = NULL;
  764|    293|	int rv;
  765|       |
  766|    293|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    293|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    293|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    293|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    293|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 293]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|    293|	sc_log(ctx, "iasecc_sm_read_binary() card:%p offs:%i count:%zu ", card, offs, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  768|    293|	if (offs > 0x7fff)
  ------------------
  |  Branch (768:6): [True: 0, False: 293]
  ------------------
  769|    293|		LOG_TEST_RET(ctx, SC_ERROR_OFFSET_TOO_LARGE, "Invalid arguments");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  770|       |
  771|    293|	if (count == 0)
  ------------------
  |  Branch (771:6): [True: 0, False: 293]
  ------------------
  772|      0|		return 0;
  773|       |
  774|    293|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (774:6): [True: 293, False: 0]
  |  Branch (774:26): [True: 278, False: 15]
  ------------------
  775|    278|		entry = sc_file_get_acl_entry(prv->cache.current_ef, SC_AC_OP_READ);
  ------------------
  |  |  188|    278|#define SC_AC_OP_READ			22
  ------------------
  776|    278|		if (!entry)
  ------------------
  |  Branch (776:7): [True: 16, False: 262]
  ------------------
  777|    278|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "iasecc_sm_read() 'READ' ACL not present");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|       |
  779|    262|		sc_log(ctx, "READ method/reference %X/%X", entry->method, entry->key_ref);
  ------------------
  |  |   71|    262|#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|    262|		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |  157|    262|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
              		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |   91|    233|#define IASECC_SCB_METHOD_SM		0x40
  ------------------
  |  Branch (780:7): [True: 233, False: 29]
  |  Branch (780:39): [True: 220, False: 13]
  ------------------
  781|    220|			unsigned char se_num = entry->key_ref & IASECC_SCB_METHOD_MASK_REF;
  ------------------
  |  |   90|    220|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
  782|       |
  783|    220|			rv = iasecc_sm_read_binary(card, se_num, offs, buff, count);
  784|    220|			LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    220|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|    220|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 220, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    220|		}
  786|    262|	}
  787|       |
  788|     57|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|     57|}
card-iasecc.c:iasecc_finish:
 1414|    638|{
 1415|    638|	struct sc_context *ctx = card->ctx;
 1416|    638|	struct iasecc_private_data *private_data = (struct iasecc_private_data *)card->drv_data;
 1417|    638|	struct iasecc_se_info *se_info = private_data->se_info, *next;
 1418|       |
 1419|    638|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    638|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    638|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    638|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    638|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 638]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1420|       |
 1421|    638|	sc_invalidate_cache(card);
 1422|       |
 1423|    668|	while (se_info)   {
  ------------------
  |  Branch (1423:9): [True: 30, False: 638]
  ------------------
 1424|     30|		sc_file_free(se_info->df);
 1425|     30|		next = se_info->next;
 1426|     30|		free(se_info);
 1427|     30|		se_info = next;
 1428|     30|	}
 1429|       |
 1430|    638|	free(card->drv_data);
 1431|    638|	card->drv_data = NULL;
 1432|       |
 1433|    638|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    638|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    638|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    638|	int _ret = r; \
  |  |  |  |  155|    638|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 638, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    638|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 638]
  |  |  |  |  ------------------
  |  |  |  |  157|    638|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    638|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    638|	return _ret; \
  |  |  |  |  163|    638|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1434|    638|}
card-iasecc.c:iasecc_read_binary:
  697|  1.32k|{
  698|  1.32k|	struct sc_context *ctx = card->ctx;
  699|  1.32k|	struct sc_apdu apdu;
  700|  1.32k|	int rv;
  701|       |
  702|  1.32k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.32k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.32k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.32k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.32k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.32k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  703|  1.32k|	sc_log(ctx, "iasecc_read_binary(card:%p) offs %i; count %zu", card, offs, count);
  ------------------
  |  |   71|  1.32k|#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|  1.32k|	if (offs > 0x7fff) {
  ------------------
  |  Branch (704:6): [True: 3, False: 1.32k]
  ------------------
  705|      3|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", offs);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  706|      3|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      3|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  707|      3|	}
  708|       |
  709|  1.32k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|  1.32k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  710|  1.32k|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (710:12): [True: 87, False: 1.23k]
  ------------------
  711|  1.32k|	apdu.resplen = count;
  712|  1.32k|	apdu.resp = buf;
  713|       |
  714|  1.32k|	rv = sc_transmit_apdu(card, &apdu);
  715|  1.32k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.32k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.32k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.32k|	int _ret = (r); \
  |  |  |  |  168|  1.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 1.30k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  1.30k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  717|  1.30k|	LOG_TEST_RET(ctx, rv, "iasecc_read_binary() failed");
  ------------------
  |  |  174|  1.30k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.30k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.30k|	int _ret = (r); \
  |  |  |  |  168|  1.30k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 309, False: 997]
  |  |  |  |  ------------------
  |  |  |  |  169|    309|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    309|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    309|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    309|		return _ret; \
  |  |  |  |  172|    309|	} \
  |  |  |  |  173|  1.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 997]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  718|    997|	sc_log(ctx, "iasecc_read_binary() apdu.resplen %zu", apdu.resplen);
  ------------------
  |  |   71|    997|#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|    997|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  1.99k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (720:6): [True: 264, False: 733]
  |  Branch (720:55): [True: 263, False: 1]
  ------------------
  721|    263|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  722|    263|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|    263|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (722:7): [True: 262, False: 1]
  ------------------
  723|    262|			LOG_TEST_RET(ctx, rv, "iasecc_read_binary() read tail failed");
  ------------------
  |  |  174|    262|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    262|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    262|	int _ret = (r); \
  |  |  |  |  168|    262|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 174, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  169|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    174|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    174|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    174|		return _ret; \
  |  |  |  |  172|    174|	} \
  |  |  |  |  173|    262|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|     88|			apdu.resplen += rv;
  725|     88|		}
  726|    263|	}
  727|       |
  728|    823|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    823|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    823|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    823|	int _ret = r; \
  |  |  |  |  155|    823|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 791]
  |  |  |  |  ------------------
  |  |  |  |  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|    791|	} else { \
  |  |  |  |  159|    791|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    791|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    791|	} \
  |  |  |  |  162|    823|	return _ret; \
  |  |  |  |  163|    823|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  729|    823|}
card-iasecc.c:iasecc_sdo_get_data:
 2848|    240|{
 2849|    240|	struct sc_context *ctx = card->ctx;
 2850|    240|	int rv, sdo_tag;
 2851|       |
 2852|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2853|       |
 2854|    240|	sdo_tag = iasecc_sdo_tag_from_class(sdo->sdo_class);
 2855|       |
 2856|    240|	rv = iasecc_sdo_get_tagged_data(card, sdo_tag, sdo);
 2857|       |	/* When there is no public data 'GET DATA' returns error */
 2858|    240|	if (rv != SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    240|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (2858:6): [True: 236, False: 4]
  ------------------
 2859|    240|		LOG_TEST_RET(ctx, rv, "cannot parse ECC SDO data");
  ------------------
  |  |  174|    236|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    236|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    236|	int _ret = (r); \
  |  |  |  |  168|    236|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    232|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    232|		return _ret; \
  |  |  |  |  172|    232|	} \
  |  |  |  |  173|    236|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2860|       |
 2861|      8|	rv = iasecc_sdo_get_tagged_data(card, IASECC_DOCP_TAG, sdo);
  ------------------
  |  |   31|      8|#define IASECC_DOCP_TAG				0xA0
  ------------------
 2862|      8|	LOG_TEST_RET(ctx, rv, "cannot parse ECC DOCP data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2863|       |
 2864|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2865|      0|}
card-iasecc.c:iasecc_sdo_tag_from_class:
 2749|    240|{
 2750|    240|	switch (sdo_class & ~IASECC_OBJECT_REF_LOCAL)   {
  ------------------
  |  |   59|    240|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2750:10): [True: 240, False: 0]
  ------------------
 2751|    240|	case IASECC_SDO_CLASS_CHV:
  ------------------
  |  |   98|    240|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (2751:2): [True: 240, False: 0]
  ------------------
 2752|    240|		return IASECC_SDO_CHV_TAG;
  ------------------
  |  |   63|    240|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
 2753|      0|	case IASECC_SDO_CLASS_RSA_PRIVATE:
  ------------------
  |  |  100|      0|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (2753:2): [True: 0, False: 240]
  ------------------
 2754|      0|		return IASECC_SDO_PRVKEY_TAG;
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
 2755|      0|	case IASECC_SDO_CLASS_RSA_PUBLIC:
  ------------------
  |  |  101|      0|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (2755:2): [True: 0, False: 240]
  ------------------
 2756|      0|		return IASECC_SDO_PUBKEY_TAG;
  ------------------
  |  |   76|      0|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
 2757|      0|	case IASECC_SDO_CLASS_SE:
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (2757:2): [True: 0, False: 240]
  ------------------
 2758|      0|		return IASECC_SDO_CLASS_SE;
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 2759|      0|	case IASECC_SDO_CLASS_KEYSET:
  ------------------
  |  |   99|      0|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (2759:2): [True: 0, False: 240]
  ------------------
 2760|      0|		return IASECC_SDO_KEYSET_TAG;
  ------------------
  |  |   83|      0|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
 2761|    240|	}
 2762|       |
 2763|      0|	return -1;
 2764|    240|}
card-iasecc.c:iasecc_sdo_get_tagged_data:
 2769|    248|{
 2770|    248|	struct sc_context *ctx = card->ctx;
 2771|    248|	struct sc_apdu apdu;
 2772|    248|	unsigned char sbuf[0x100];
 2773|    248|	size_t offs = sizeof(sbuf) - 1;
 2774|    248|	unsigned char rbuf[0x400];
 2775|    248|	int rv;
 2776|       |
 2777|    248|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    248|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    248|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    248|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    248|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 248]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2778|       |
 2779|    248|	sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag,
  ------------------
  |  |   71|    248|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2780|    248|			sdo->sdo_ref, sdo->sdo_class);
 2781|       |
 2782|       |	/* XXX: for the CPx, the SDO are available from some specific path */
 2783|    248|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (2783:6): [True: 9, False: 239]
  ------------------
 2784|      9|		struct sc_path path;
 2785|      9|		char *path_str = NULL;
 2786|      9|		switch(sdo_tag) {
 2787|      0|			case IASECC_SDO_PRVKEY_TAG:
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (2787:4): [True: 0, False: 9]
  ------------------
 2788|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 90 02 03 7F 48 80 */
 2789|      0|			path_str = "3F00:0001";
 2790|      0|			break;
 2791|      7|			case IASECC_SDO_CHV_TAG:
  ------------------
  |  |   63|      7|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (2791:4): [True: 7, False: 2]
  ------------------
 2792|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */
 2793|      7|			path_str = "3F00";
 2794|      7|			break;
 2795|      2|			default:
  ------------------
  |  Branch (2795:4): [True: 2, False: 7]
  ------------------
 2796|      2|			path_str = NULL;
 2797|      2|			break;
 2798|      9|		}
 2799|      9|		if (path_str) {
  ------------------
  |  Branch (2799:7): [True: 7, False: 2]
  ------------------
 2800|      7|			sc_log(ctx, "Warning: Enforce the path=%s", path_str);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2801|      7|			sc_format_path(path_str, &path);
 2802|      7|			rv = iasecc_select_file(card, &path, NULL);
 2803|      7|			LOG_TEST_RET(ctx, rv, "path error");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2804|      7|		}
 2805|      9|	}
 2806|       |
 2807|    243|	sbuf[offs--] = 0x80;
 2808|    243|	sbuf[offs--] = sdo_tag & 0xFF;
 2809|    243|	if ((sdo_tag >> 8) & 0xFF)
  ------------------
  |  Branch (2809:6): [True: 235, False: 8]
  ------------------
 2810|    235|		sbuf[offs--] = (sdo_tag >> 8) & 0xFF;
 2811|    243|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2812|    243|	offs--;
 2813|       |
 2814|    243|	sbuf[offs--] = sdo->sdo_ref & 0x9F;
 2815|    243|	sbuf[offs--] = sdo->sdo_class | IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    243|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2816|    243|	sbuf[offs--] = IASECC_SDO_TAG_HEADER;
  ------------------
  |  |   27|    243|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
 2817|       |
 2818|    243|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2819|    243|	offs--;
 2820|    243|	sbuf[offs--] = IASECC_SDO_TEMPLATE_TAG;
  ------------------
  |  |   29|    243|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 2821|       |
 2822|    243|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2823|    243|	offs--;
 2824|    243|	sbuf[offs] = 0x4D;
 2825|       |
 2826|    243|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    243|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 2827|    243|	apdu.data = sbuf + offs;
 2828|    243|	apdu.datalen = sizeof(sbuf) - offs;
 2829|    243|	apdu.lc = sizeof(sbuf) - offs;
 2830|    243|	apdu.resp = rbuf;
 2831|    243|	apdu.resplen = sizeof(rbuf);
 2832|    243|	apdu.le = 0x100;
 2833|       |
 2834|    243|	rv = sc_transmit_apdu(card, &apdu);
 2835|    243|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    243|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    243|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    243|	int _ret = (r); \
  |  |  |  |  168|    243|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 240]
  |  |  |  |  ------------------
  |  |  |  |  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|    243|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 240]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2836|    240|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2837|    240|	LOG_TEST_RET(ctx, rv, "SDO get data 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: 20, False: 220]
  |  |  |  |  ------------------
  |  |  |  |  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|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 220]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2838|       |
 2839|    220|	rv = iasecc_sdo_parse(card, apdu.resp, apdu.resplen, sdo);
 2840|    220|	LOG_TEST_RET(ctx, rv, "cannot parse SDO data");
  ------------------
  |  |  174|    220|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    220|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    220|	int _ret = (r); \
  |  |  |  |  168|    220|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 216, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|    216|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    216|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    216|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    216|		return _ret; \
  |  |  |  |  172|    216|	} \
  |  |  |  |  173|    220|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|       |
 2842|      4|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2843|      4|}
card-iasecc.c:iasecc_check_sw:
 1487|  10.2k|{
 1488|  10.2k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1488:6): [True: 173, False: 10.1k]
  |  Branch (1488:21): [True: 152, False: 21]
  ------------------
 1489|    152|		return SC_SUCCESS;
  ------------------
  |  |   28|    152|#define SC_SUCCESS				0
  ------------------
 1490|       |
 1491|  10.1k|	return iso_ops->check_sw(card, sw1, sw2);
 1492|  10.2k|}
card-iasecc.c:iasecc_card_ctl:
 2973|    257|{
 2974|    257|	struct sc_context *ctx = card->ctx;
 2975|    257|	struct iasecc_sdo *sdo = (struct iasecc_sdo *) ptr;
 2976|       |
 2977|    257|	switch (cmd) {
  ------------------
  |  Branch (2977:10): [True: 257, False: 0]
  ------------------
 2978|    257|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2978:2): [True: 257, False: 0]
  ------------------
 2979|    257|		return iasecc_get_serialnr(card, (struct sc_serial_number *)ptr);
 2980|      0|	case SC_CARDCTL_IASECC_SDO_CREATE:
  ------------------
  |  Branch (2980:2): [True: 0, False: 257]
  ------------------
 2981|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_CREATE: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2982|      0|		return iasecc_sdo_create(card, (struct iasecc_sdo *) ptr);
 2983|      0|	case SC_CARDCTL_IASECC_SDO_DELETE:
  ------------------
  |  Branch (2983:2): [True: 0, False: 257]
  ------------------
 2984|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_DELETE: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2985|      0|		return iasecc_sdo_delete(card, (struct iasecc_sdo *) ptr);
 2986|      0|	case SC_CARDCTL_IASECC_SDO_PUT_DATA:
  ------------------
  |  Branch (2986:2): [True: 0, False: 257]
  ------------------
 2987|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_PUT_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2988|      0|		return iasecc_sdo_put_data(card, (struct iasecc_sdo_update *) ptr);
 2989|      0|	case SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA:
  ------------------
  |  Branch (2989:2): [True: 0, False: 257]
  ------------------
 2990|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2991|      0|		return iasecc_sdo_key_rsa_put_data(card, (struct iasecc_sdo_rsa_update *) ptr);
 2992|      0|	case SC_CARDCTL_IASECC_SDO_GET_DATA:
  ------------------
  |  Branch (2992:2): [True: 0, False: 257]
  ------------------
 2993|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_GET_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2994|      0|		return iasecc_sdo_get_data(card, (struct iasecc_sdo *) ptr);
 2995|      0|	case SC_CARDCTL_IASECC_SDO_GENERATE:
  ------------------
  |  Branch (2995:2): [True: 0, False: 257]
  ------------------
 2996|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_SDO_GET_DATA: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2997|      0|		return iasecc_sdo_generate(card, (struct iasecc_sdo *) ptr);
 2998|      0|	case SC_CARDCTL_GET_SE_INFO:
  ------------------
  |  Branch (2998:2): [True: 0, False: 257]
  ------------------
 2999|      0|		sc_log(ctx, "CMD SC_CARDCTL_GET_SE_INFO: sdo_class %X", sdo->sdo_class);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3000|      0|		return iasecc_se_get_info(card, (struct iasecc_se_info *) ptr);
 3001|      0|	case SC_CARDCTL_GET_CHV_REFERENCE_IN_SE:
  ------------------
  |  Branch (3001:2): [True: 0, False: 257]
  ------------------
 3002|      0|		sc_log(ctx, "CMD SC_CARDCTL_GET_CHV_REFERENCE_IN_SE");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3003|      0|		return iasecc_get_chv_reference_from_se(card, (int *)ptr);
 3004|      0|	case SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE:
  ------------------
  |  Branch (3004:2): [True: 0, False: 257]
  ------------------
 3005|      0|		sc_log(ctx, "CMD SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3006|      0|		return iasecc_get_free_reference(card, (struct iasecc_ctl_get_free_reference *)ptr);
 3007|    257|	}
 3008|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3009|    257|}
card-iasecc.c:iasecc_pin_cmd:
 2428|    257|{
 2429|    257|	struct sc_context *ctx = card->ctx;
 2430|    257|	int rv;
 2431|       |
 2432|    257|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2433|    257|	sc_log(ctx, "iasecc_pin_cmd() cmd 0x%X, PIN type 0x%X, PIN reference %i, PIN-1 %p:%zu, PIN-2 %p:%zu",
  ------------------
  |  |   71|    257|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2434|    257|			data->cmd, data->pin_type, data->pin_reference,
 2435|    257|			data->pin1.data, data->pin1.len, data->pin2.data, data->pin2.len);
 2436|       |
 2437|    257|	switch (data->cmd)   {
 2438|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2438:2): [True: 0, False: 257]
  ------------------
 2439|      0|		rv = iasecc_pin_verify(card, data);
 2440|      0|		break;
 2441|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2441:2): [True: 0, False: 257]
  ------------------
 2442|      0|		if (data->pin_type == SC_AC_AUT)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2442:7): [True: 0, False: 0]
  ------------------
 2443|      0|			rv = iasecc_keyset_change(card, data);
 2444|      0|		else
 2445|      0|			rv = iasecc_pin_change(card, data);
 2446|      0|		break;
 2447|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2447:2): [True: 0, False: 257]
  ------------------
 2448|      0|		rv = iasecc_pin_reset(card, data);
 2449|      0|		break;
 2450|    257|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    257|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2450:2): [True: 257, False: 0]
  ------------------
 2451|    257|		rv = iasecc_pin_get_info(card, data);
 2452|    257|		break;
 2453|      0|	default:
  ------------------
  |  Branch (2453:2): [True: 0, False: 257]
  ------------------
 2454|      0|		sc_log(ctx, "Other pin commands not supported yet: 0x%X", data->cmd);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2455|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2456|    257|	}
 2457|       |
 2458|    257|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    257|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    257|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    257|	int _ret = r; \
  |  |  |  |  155|    257|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 257, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    257|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 257, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    257|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    257|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    257|	return _ret; \
  |  |  |  |  163|    257|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|    257|}
card-iasecc.c:iasecc_pin_get_status:
 1895|    257|{
 1896|    257|	struct sc_context *ctx = card->ctx;
 1897|    257|	struct sc_pin_cmd_data info;
 1898|    257|	int rv;
 1899|       |
 1900|    257|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1901|       |
 1902|    257|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    257|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1902:6): [True: 0, False: 257]
  ------------------
 1903|    257|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "PIN type is not supported for status");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1904|       |
 1905|    257|	memset(&info, 0, sizeof(info));
 1906|    257|	info.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    257|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1907|    257|	info.pin_type = data->pin_type;
 1908|    257|	info.pin_reference = data->pin_reference;
 1909|       |
 1910|    257|	rv = iso_ops->pin_cmd(card, &info);
 1911|    257|	LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
  ------------------
  |  |  174|    257|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    257|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    257|	int _ret = (r); \
  |  |  |  |  168|    257|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 244]
  |  |  |  |  ------------------
  |  |  |  |  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|    257|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 244]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1912|       |
 1913|    244|	data->pin1.max_tries = info.pin1.max_tries;
 1914|    244|	data->pin1.tries_left = info.pin1.tries_left;
 1915|    244|	data->pin1.logged_in = info.pin1.logged_in;
 1916|       |
 1917|    244|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    244|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    244|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    244|	int _ret = r; \
  |  |  |  |  155|    244|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 244, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    244|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 244]
  |  |  |  |  ------------------
  |  |  |  |  157|    244|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    244|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    244|	return _ret; \
  |  |  |  |  163|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1918|    244|}
card-iasecc.c:iasecc_pin_get_policy:
 2014|    244|{
 2015|    244|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 2016|    244|	struct sc_context *ctx = card->ctx;
 2017|    244|	struct sc_file *save_current_df = NULL, *save_current_ef = NULL;
 2018|    244|	struct iasecc_sdo sdo;
 2019|    244|	struct sc_path path;
 2020|    244|	int rv;
 2021|       |
 2022|    244|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    244|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    244|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    244|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    244|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 244]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|    244|	sc_log(ctx, "iasecc_pin_get_policy(card:%p)", card);
  ------------------
  |  |   71|    244|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2024|       |
 2025|    244|	if (data->pin_type != SC_AC_CHV)   {
  ------------------
  |  |  151|    244|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2025:6): [True: 0, False: 244]
  ------------------
 2026|      0|		sc_log(ctx, "PIN policy only available for CHV type");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2027|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2028|      0|	}
 2029|       |
 2030|    244|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (2030:6): [True: 244, False: 0]
  |  Branch (2030:26): [True: 7, False: 237]
  ------------------
 2031|      7|		sc_file_dup(&save_current_df, prv->cache.current_df);
 2032|      7|		if (save_current_df == NULL) {
  ------------------
  |  Branch (2032:7): [True: 0, False: 7]
  ------------------
 2033|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2034|      0|			sc_log(ctx, "Cannot duplicate current DF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2035|      0|			goto err;
 2036|      0|		}
 2037|      7|	}
 2038|       |
 2039|    244|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (2039:6): [True: 244, False: 0]
  |  Branch (2039:26): [True: 3, False: 241]
  ------------------
 2040|      3|		sc_file_dup(&save_current_ef, prv->cache.current_ef);
 2041|      3|		if (save_current_ef == NULL) {
  ------------------
  |  Branch (2041:7): [True: 0, False: 3]
  ------------------
 2042|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2043|      0|			sc_log(ctx, "Cannot duplicate current EF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2044|      0|			goto err;
 2045|      0|		}
 2046|      3|	}
 2047|       |
 2048|    244|	if (!(data->pin_reference & IASECC_OBJECT_REF_LOCAL) && prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  |   59|    244|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2048:6): [True: 244, False: 0]
  |  Branch (2048:58): [True: 244, False: 0]
  |  Branch (2048:78): [True: 7, False: 237]
  ------------------
 2049|      7|		sc_format_path("3F00", &path);
 2050|      7|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      7|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2051|      7|		rv = iasecc_select_file(card, &path, NULL);
 2052|      7|		LOG_TEST_GOTO_ERR(ctx, rv, "Unable to select MF");
  ------------------
  |  |  184|      7|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      7|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      7|	int _ret = (r); \
  |  |  |  |  178|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2053|      7|	}
 2054|       |
 2055|    240|	memset(&sdo, 0, sizeof(sdo));
 2056|    240|	sdo.sdo_class = IASECC_SDO_CLASS_CHV;
  ------------------
  |  |   98|    240|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
 2057|       |
 2058|    240|	sdo.sdo_ref = data->pin_reference & ~IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    240|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2059|       |
 2060|    240|	sc_log(ctx, "iasecc_pin_get_policy() reference %i", sdo.sdo_ref);
  ------------------
  |  |   71|    240|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2061|       |
 2062|    240|	rv = iasecc_sdo_get_data(card, &sdo);
 2063|    240|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot get SDO PIN data");
  ------------------
  |  |  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: 240, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    240|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    240|		goto err; \
  |  |  |  |  182|    240|	} \
  |  |  |  |  183|    240|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2064|       |
 2065|      0|	if (sdo.docp.acls_contact.size == 0) {
  ------------------
  |  Branch (2065:6): [True: 0, False: 0]
  ------------------
 2066|      0|		rv = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2067|      0|		sc_log(ctx, "Extremely strange ... there is no ACLs");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2068|      0|		goto err;
 2069|      0|	}
 2070|       |
 2071|      0|	sc_log(ctx, "iasecc_pin_get_policy() sdo.docp.size.size %zu", sdo.docp.size.size);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2072|       |
 2073|      0|	memcpy(pin->scbs, sdo.docp.scbs, sizeof(pin->scbs));
 2074|       |
 2075|      0|	pin->min_length = (sdo.data.chv.size_min.value ? *sdo.data.chv.size_min.value : -1);
  ------------------
  |  Branch (2075:21): [True: 0, False: 0]
  ------------------
 2076|      0|	pin->max_length = (sdo.data.chv.size_max.value ? *sdo.data.chv.size_max.value : -1);
  ------------------
  |  Branch (2076:21): [True: 0, False: 0]
  ------------------
 2077|      0|	pin->tries_maximum = (sdo.docp.tries_maximum.value ? *sdo.docp.tries_maximum.value : -1);
  ------------------
  |  Branch (2077:24): [True: 0, False: 0]
  ------------------
 2078|      0|	pin->tries_remaining = (sdo.docp.tries_remaining.value ? *sdo.docp.tries_remaining.value : -1);
  ------------------
  |  Branch (2078:26): [True: 0, False: 0]
  ------------------
 2079|      0|	if (sdo.docp.size.value && sdo.docp.size.size <= sizeof(int)) {
  ------------------
  |  Branch (2079:6): [True: 0, False: 0]
  |  Branch (2079:29): [True: 0, False: 0]
  ------------------
 2080|      0|		unsigned int n = 0;
 2081|      0|		unsigned int i;
 2082|      0|		for (i=0; i<sdo.docp.size.size; i++)
  ------------------
  |  Branch (2082:13): [True: 0, False: 0]
  ------------------
 2083|      0|			n = (n << 8) + *(sdo.docp.size.value + i);
 2084|      0|		pin->stored_length = n;
 2085|      0|	} else {
 2086|      0|		pin->stored_length = -1;
 2087|      0|	}
 2088|       |
 2089|      0|	sc_log(ctx, "PIN policy: size max/min %i/%i, tries max/left %i/%i",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2090|      0|	       pin->max_length, pin->min_length, pin->tries_maximum, pin->tries_remaining);
 2091|      0|	iasecc_sdo_free_fields(card, &sdo);
 2092|       |
 2093|      0|	if (save_current_df)   {
  ------------------
  |  Branch (2093:6): [True: 0, False: 0]
  ------------------
 2094|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current DF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2095|      0|		rv = iasecc_select_file(card, &save_current_df->path, NULL);
 2096|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Cannot return to saved DF");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2097|      0|	}
 2098|       |
 2099|      0|	if (save_current_ef)   {
  ------------------
  |  Branch (2099:6): [True: 0, False: 0]
  ------------------
 2100|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current EF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2101|      0|		rv = iasecc_select_file(card, &save_current_ef->path, NULL);
 2102|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Cannot return to saved EF");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2103|      0|	}
 2104|       |
 2105|    244|err:
 2106|    244|	sc_file_free(save_current_df);
 2107|    244|	sc_file_free(save_current_ef);
 2108|       |
 2109|    244|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    244|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    244|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    244|	int _ret = r; \
  |  |  |  |  155|    244|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 244, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    244|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    244|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 244, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    244|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    244|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    244|	return _ret; \
  |  |  |  |  163|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2110|    244|}
card-iasecc.c:iasecc_pin_get_info:
 2115|    257|{
 2116|    257|	struct sc_context *ctx = card->ctx;
 2117|    257|	struct iasecc_pin_policy policy;
 2118|    257|	int rv;
 2119|       |
 2120|    257|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|    257|	sc_log(ctx, "iasecc_pin_get_info(card:%p)", card);
  ------------------
  |  |   71|    257|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2122|       |
 2123|       |	/*
 2124|       |	 * Get PIN status first and thereafter update with info from PIN policy, when available.
 2125|       |	 * The first one is typically used for the PIN verification status and number of remaining
 2126|       |	 * tries, and the second one for the maximum tries. If a field is present in both, the
 2127|       |	 * policy takes precedence.
 2128|       |	 */
 2129|    257|	rv = iasecc_pin_get_status(card, data);
 2130|    257|	LOG_TEST_RET(ctx, rv, "Failed to get PIN status");
  ------------------
  |  |  174|    257|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    257|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    257|	int _ret = (r); \
  |  |  |  |  168|    257|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 244]
  |  |  |  |  ------------------
  |  |  |  |  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|    257|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 244]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2131|       |
 2132|    244|	rv = iasecc_pin_get_policy(card, data, &policy);
 2133|    244|	LOG_TEST_RET(ctx, rv, "Failed to get PIN policy");
  ------------------
  |  |  174|    244|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    244|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    244|	int _ret = (r); \
  |  |  |  |  168|    244|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 244, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    244|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    244|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    244|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    244|		return _ret; \
  |  |  |  |  172|    244|	} \
  |  |  |  |  173|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|       |	/*
 2136|       |	 * We only care about the tries_xxx fields in the PIN policy, since the other ones are not
 2137|       |	 * commonly expected or used in a SC_PIN_CMD_GET_INFO response.	Note that max_tries is
 2138|       |	 * always taken from the policy, since it is never expected to be available in status (it
 2139|       |	 * is set to -1 when not available in policy).
 2140|       |	 */
 2141|      0|	data->pin1.max_tries = policy.tries_maximum;
 2142|      0|	if (policy.tries_remaining >= 0)
  ------------------
  |  Branch (2142:6): [True: 0, False: 0]
  ------------------
 2143|      0|		data->pin1.tries_left = policy.tries_remaining;
 2144|       |
 2145|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2146|      0|}

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

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

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

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

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

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

sc_get_mcrd_driver:
 1066|  16.9k|{
 1067|  16.9k|	return sc_get_driver();
 1068|  16.9k|}
card-mcrd.c:sc_get_driver:
 1047|  16.9k|{
 1048|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1049|  16.9k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1049:6): [True: 1, False: 16.9k]
  ------------------
 1050|      1|		iso_ops = iso_drv->ops;
 1051|       |
 1052|  16.9k|	mcrd_ops = *iso_drv->ops;
 1053|  16.9k|	mcrd_ops.match_card = mcrd_match_card;
 1054|  16.9k|	mcrd_ops.init = mcrd_init;
 1055|  16.9k|	mcrd_ops.finish = mcrd_finish;
 1056|  16.9k|	mcrd_ops.select_file = mcrd_select_file;
 1057|  16.9k|	mcrd_ops.set_security_env = mcrd_set_security_env;
 1058|  16.9k|	mcrd_ops.compute_signature = mcrd_compute_signature;
 1059|  16.9k|	mcrd_ops.pin_cmd = mcrd_pin_cmd;
 1060|  16.9k|	mcrd_ops.logout = mcrd_logout;
 1061|       |
 1062|  16.9k|	return &mcrd_drv;
 1063|  16.9k|}
card-mcrd.c:mcrd_match_card:
  191|  16.4k|{
  192|  16.4k|	int i = 0;
  193|       |
  194|  16.4k|	i = _sc_match_atr(card, mcrd_atrs, &card->type);
  195|  16.4k|	if (i >= 0) {
  ------------------
  |  Branch (195:6): [True: 483, False: 15.9k]
  ------------------
  196|    483|		card->name = mcrd_atrs[i].name;
  197|    483|		return 1;
  198|    483|	}
  199|       |
  200|  15.9k|	return 0;
  201|  16.4k|}
card-mcrd.c:mcrd_init:
  204|    483|{
  205|    483|	unsigned long flags;
  206|    483|	struct mcrd_priv_data *priv = calloc(1, sizeof *priv);
  207|    483|	if (!priv)
  ------------------
  |  Branch (207:6): [True: 0, False: 483]
  ------------------
  208|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  209|    483|	priv->curpath[0] = MFID;
  ------------------
  |  |   67|    483|#define MFID 0x3F00
  ------------------
  210|    483|	priv->curpathlen = 1;
  211|    483|	card->drv_data = priv;
  212|    483|	card->cla = 0x00;
  213|    483|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    483|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  214|       |
  215|    483|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    483|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|    483|#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|    483|#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|    483|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    483|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  216|    483|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  217|    483|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  218|    483|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  219|       |
  220|    483|	if (SC_SUCCESS != sc_select_file (card, sc_get_mf_path(), NULL))
  ------------------
  |  |   28|    483|#define SC_SUCCESS				0
  ------------------
  |  Branch (220:6): [True: 122, False: 361]
  ------------------
  221|    122|		sc_log(card->ctx, "Warning: select MF failed");
  ------------------
  |  |   71|    122|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  222|       |
  223|    483|	load_special_files(card);
  224|       |
  225|    483|	return SC_SUCCESS;
  ------------------
  |  |   28|    483|#define SC_SUCCESS				0
  ------------------
  226|    483|}
card-mcrd.c:load_special_files:
  248|    573|{
  249|    573|	sc_context_t *ctx = card->ctx;
  250|    573|	int r;
  251|    573|	unsigned int recno;
  252|    573|	struct df_info_s *dfi;
  253|    573|	struct rule_record_s *rule;
  254|    573|	struct keyd_record_s *keyd;
  255|       |
  256|       |	/* First check whether we already cached it. */
  257|    573|	dfi = get_df_info(card);
  258|    573|	if (dfi && dfi->rule_file)
  ------------------
  |  Branch (258:6): [True: 451, False: 122]
  |  Branch (258:13): [True: 1, False: 450]
  ------------------
  259|      1|		return 0;	/* yes. */
  260|    572|	clear_special_files(dfi);
  261|    572|	if (!dfi)
  ------------------
  |  Branch (261:6): [True: 122, False: 450]
  ------------------
  262|    572|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|    122|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    122|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    122|	int _ret = r; \
  |  |  |  |  155|    122|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 122, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    122|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    122|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    122|	return _ret; \
  |  |  |  |  163|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|       |
  264|       |	/* Read rule file. Note that we bypass our cache here. */
  265|    450|	r = select_part(card, MCRD_SEL_EF, EF_Rule, NULL);
  ------------------
  |  |   69|    450|#define EF_Rule 0x0030		/* Default ACL file. */
  ------------------
  266|    450|	LOG_TEST_RET(ctx, r, "selecting EF_Rule failed");
  ------------------
  |  |  174|    450|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    450|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    450|	int _ret = (r); \
  |  |  |  |  168|    450|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 222, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  169|    222|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    222|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    222|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    222|		return _ret; \
  |  |  |  |  172|    222|	} \
  |  |  |  |  173|    450|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  267|       |
  268|  1.51k|	for (recno = 1;; recno++) {
  269|  1.51k|		u8 recbuf[256];
  270|  1.51k|		r = sc_read_record(card, recno, 0, recbuf, sizeof(recbuf),
  271|  1.51k|					SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  1.51k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  272|       |
  273|  1.51k|		if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.51k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (273:7): [True: 49, False: 1.46k]
  ------------------
  274|     49|			break;
  275|  1.46k|		if (r < 0) {
  ------------------
  |  Branch (275:7): [True: 179, False: 1.28k]
  ------------------
  276|    179|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  277|  1.28k|		} else {
  278|  1.28k|			rule = malloc(sizeof *rule + (size_t)r);
  279|  1.28k|			if (!rule)
  ------------------
  |  Branch (279:8): [True: 0, False: 1.28k]
  ------------------
  280|  1.28k|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|  1.28k|			rule->recno = recno;
  282|  1.28k|			rule->datalen = (size_t)r;
  283|  1.28k|			memcpy(rule->data, recbuf, r);
  284|  1.28k|			rule->next = dfi->rule_file;
  285|  1.28k|			dfi->rule_file = rule;
  286|  1.28k|		}
  287|  1.46k|	}
  288|       |
  289|     49|	sc_log(ctx, "new EF_Rule file loaded (%d records)\n", recno - 1);
  ------------------
  |  |   71|     49|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  290|       |
  291|       |	/* Read the KeyD file. Note that we bypass our cache here. */
  292|     49|	r = select_part(card, MCRD_SEL_EF, EF_KeyD, NULL);
  ------------------
  |  |   68|     49|#define EF_KeyD 0x0013		/* File with extra key information. */
  ------------------
  293|     49|	if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|     49|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (293:6): [True: 3, False: 46]
  ------------------
  294|      3|		sc_log(ctx, "no EF_KeyD file available\n");
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  295|      3|		return 0;	/* That is okay. */
  296|      3|	}
  297|     46|	LOG_TEST_RET(ctx, r, "selecting EF_KeyD failed");
  ------------------
  |  |  174|     46|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     46|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     46|	int _ret = (r); \
  |  |  |  |  168|     46|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  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|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|       |
  299|    238|	for (recno = 1;; recno++) {
  300|    238|		u8 recbuf[256];
  301|    238|		r = sc_read_record(card, recno, 0, recbuf, sizeof(recbuf),
  302|    238|					SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|    238|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  303|       |
  304|    238|		if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|    238|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (304:7): [True: 8, False: 230]
  ------------------
  305|      8|			break;
  306|    230|		if (r < 0) {
  ------------------
  |  Branch (306:7): [True: 28, False: 202]
  ------------------
  307|     28|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  308|    202|		} else {
  309|    202|			keyd = malloc(sizeof *keyd + (size_t)r);
  310|    202|			if (!keyd)
  ------------------
  |  Branch (310:8): [True: 0, False: 202]
  ------------------
  311|    202|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|    202|			keyd->recno = recno;
  313|    202|			keyd->datalen = (size_t) r;
  314|    202|			memcpy(keyd->data, recbuf, r);
  315|    202|			keyd->next = dfi->keyd_file;
  316|    202|			dfi->keyd_file = keyd;
  317|    202|		}
  318|    230|	}
  319|       |
  320|      8|	sc_log(ctx, "new EF_KeyD file loaded (%d records)\n", recno - 1);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  321|       |	/* FIXME: Do we need to restore the current DF?  I guess it is
  322|       |	   not required, but we could try to do so by selecting 3fff?  */
  323|      8|	return 0;
  324|     36|}
card-mcrd.c:get_df_info:
  111|    705|{
  112|    705|	sc_context_t *ctx = card->ctx;
  113|    705|	struct mcrd_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  103|    705|#define DRVDATA(card) ((struct mcrd_priv_data *) ((card)->drv_data))
  ------------------
  114|    705|	struct df_info_s *dfi;
  115|       |
  116|    705|	if (priv->is_ef)
  ------------------
  |  Branch (116:6): [True: 1, False: 704]
  ------------------
  117|      1|		return NULL;
  118|       |
  119|    704|	if (!priv->curpathlen) {
  ------------------
  |  Branch (119:6): [True: 124, False: 580]
  ------------------
  120|    124|		sc_log(ctx, "no current path to find the df_info\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  121|    124|		return NULL;
  122|    124|	}
  123|       |
  124|    714|	for (dfi = priv->df_infos; dfi; dfi = dfi->next) {
  ------------------
  |  Branch (124:29): [True: 261, False: 453]
  ------------------
  125|    261|		if (dfi->pathlen == priv->curpathlen
  ------------------
  |  Branch (125:7): [True: 155, False: 106]
  ------------------
  126|    155|			&& !memcmp(dfi->path, priv->curpath,
  ------------------
  |  Branch (126:7): [True: 127, False: 28]
  ------------------
  127|    155|					dfi->pathlen * sizeof *dfi->path))
  128|    127|			return dfi;
  129|    261|	}
  130|       |	/* Not found, create it. */
  131|    453|	dfi = calloc(1, sizeof *dfi);
  132|    453|	if (!dfi) {
  ------------------
  |  Branch (132:6): [True: 0, False: 453]
  ------------------
  133|      0|		sc_log(ctx, "out of memory while allocating df_info\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__
  |  |  ------------------
  ------------------
  134|      0|		return NULL;
  135|      0|	}
  136|    453|	dfi->pathlen = priv->curpathlen;
  137|    453|	memcpy(dfi->path, priv->curpath, dfi->pathlen * sizeof *dfi->path);
  138|    453|	dfi->next = priv->df_infos;
  139|    453|	priv->df_infos = dfi;
  140|    453|	return dfi;
  141|    453|}
card-mcrd.c:clear_special_files:
  144|  1.02k|{
  145|  1.02k|	if (dfi) {
  ------------------
  |  Branch (145:6): [True: 903, False: 122]
  ------------------
  146|  2.19k|		while (dfi->rule_file) {
  ------------------
  |  Branch (146:10): [True: 1.28k, False: 903]
  ------------------
  147|  1.28k|			struct rule_record_s *tmp = dfi->rule_file->next;
  148|  1.28k|			free(dfi->rule_file);
  149|  1.28k|			dfi->rule_file = tmp;
  150|  1.28k|		}
  151|  1.10k|		while (dfi->keyd_file) {
  ------------------
  |  Branch (151:10): [True: 202, False: 903]
  ------------------
  152|    202|			struct keyd_record_s *tmp = dfi->keyd_file->next;
  153|    202|			free(dfi->keyd_file);
  154|    202|			dfi->keyd_file = tmp;
  155|    202|		}
  156|    903|	}
  157|  1.02k|}
card-mcrd.c:select_part:
  615|  3.27k|{
  616|  3.27k|	u8 fbuf[2];
  617|  3.27k|	unsigned int len;
  618|  3.27k|	int r;
  619|       |
  620|  3.27k|	sc_log(card->ctx,
  ------------------
  |  |   71|  3.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  621|  3.27k|		"select_part (0x%04X, kind=%u)\n", fid, kind);
  622|       |
  623|  3.27k|	if (fid == MFID) {
  ------------------
  |  |   67|  3.27k|#define MFID 0x3F00
  ------------------
  |  Branch (623:6): [True: 1.23k, False: 2.03k]
  ------------------
  624|  1.23k|		kind = MCRD_SEL_MF;	/* force this kind. */
  625|  1.23k|		len = 0;
  626|  2.03k|	} else {
  627|  2.03k|		fbuf[0] = fid >> 8;
  628|  2.03k|		fbuf[1] = fid & 0xff;
  629|  2.03k|		len = 2;
  630|  2.03k|	}
  631|  3.27k|	r = do_select(card, kind, fbuf, len, file);
  632|       |
  633|  3.27k|	return r;
  634|  3.27k|}
card-mcrd.c:do_select:
  556|  4.16k|{
  557|  4.16k|	sc_apdu_t apdu;
  558|  4.16k|	u8 resbuf[SC_MAX_APDU_BUFFER_SIZE];
  559|  4.16k|	int r;
  560|       |
  561|  4.16k|	u8 p2 = 0x00;
  562|  4.16k|	if (kind == MCRD_SEL_EF) p2 = 0x04;
  ------------------
  |  Branch (562:6): [True: 1.43k, False: 2.73k]
  ------------------
  563|  4.16k|	if (kind == MCRD_SEL_DF) p2 = 0x0C;
  ------------------
  |  Branch (563:6): [True: 548, False: 3.61k]
  ------------------
  564|       |
  565|  4.16k|	sc_format_apdu_ex(&apdu, 0x00, 0xA4, kind, p2, buf, buflen, resbuf, 256);
  566|  4.16k|	r = sc_transmit_apdu(card, &apdu);
  567|  4.16k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  4.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.16k|	int _ret = (r); \
  |  |  |  |  168|  4.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 4.13k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.13k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  568|  4.13k|	if (!file) {
  ------------------
  |  Branch (568:6): [True: 3.03k, False: 1.10k]
  ------------------
  569|  3.03k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (569:7): [True: 0, False: 3.03k]
  ------------------
  570|      0|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 0);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  571|  3.03k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  572|  3.03k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  3.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.03k|	int _ret = r; \
  |  |  155|  3.03k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.03k, False: 0]
  |  |  ------------------
  |  |  156|  3.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|  2.00k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.00k, False: 1.03k]
  |  |  ------------------
  |  |  157|  3.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.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|  3.03k|	return _ret; \
  |  |  163|  3.03k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  573|  3.03k|	}
  574|  1.10k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  575|  1.10k|	if (r)
  ------------------
  |  Branch (575:6): [True: 516, False: 588]
  ------------------
  576|    516|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    516|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    516|	int _ret = r; \
  |  |  155|    516|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 516, False: 0]
  |  |  ------------------
  |  |  156|    516|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    516|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 516, False: 0]
  |  |  ------------------
  |  |  157|    516|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    516|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    516|	return _ret; \
  |  |  163|    516|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  577|       |
  578|    588|	if (p2 == 0x0C) {
  ------------------
  |  Branch (578:6): [True: 67, False: 521]
  ------------------
  579|     67|		if (file) {
  ------------------
  |  Branch (579:7): [True: 67, False: 0]
  ------------------
  580|     67|			*file = sc_file_new();
  581|     67|			if (!*file)
  ------------------
  |  Branch (581:8): [True: 0, False: 67]
  ------------------
  582|     67|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  583|     67|			(*file)->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     67|#define SC_FILE_TYPE_DF			0x04
  ------------------
  584|     67|			return SC_SUCCESS;
  ------------------
  |  |   28|     67|#define SC_SUCCESS				0
  ------------------
  585|     67|		}
  586|     67|	}
  587|       |
  588|    521|	if (p2 == 0x04 && apdu.resplen > 2 && apdu.resp[0] == 0x62) {
  ------------------
  |  Branch (588:6): [True: 471, False: 50]
  |  Branch (588:20): [True: 438, False: 33]
  |  Branch (588:40): [True: 36, False: 402]
  ------------------
  589|     36|		if (apdu.resp[1] > apdu.resplen - 2)
  ------------------
  |  Branch (589:7): [True: 14, False: 22]
  ------------------
  590|     36|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|     22|		*file = sc_file_new();
  592|     22|		if (!*file)
  ------------------
  |  Branch (592:7): [True: 0, False: 22]
  ------------------
  593|     22|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  594|     22|		process_fcp(card, *file, apdu.resp + 2, apdu.resp[1]);
  595|     22|		return SC_SUCCESS;
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  596|     22|	}
  597|       |
  598|    485|	if (p2 != 0x0C && apdu.resplen > 2 && apdu.resp[0] == 0x6F) {
  ------------------
  |  Branch (598:6): [True: 485, False: 0]
  |  Branch (598:20): [True: 435, False: 50]
  |  Branch (598:40): [True: 414, False: 21]
  ------------------
  599|    414|		if (apdu.resp[1] > apdu.resplen - 2)
  ------------------
  |  Branch (599:7): [True: 18, False: 396]
  ------------------
  600|    414|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  601|    396|		*file = sc_file_new();
  602|    396|		if (!*file)
  ------------------
  |  Branch (602:7): [True: 0, False: 396]
  ------------------
  603|    396|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  604|    396|		process_fcp(card, *file, apdu.resp + 2, apdu.resp[1]);
  605|    396|		return SC_SUCCESS;
  ------------------
  |  |   28|    396|#define SC_SUCCESS				0
  ------------------
  606|    396|	}
  607|     71|	return SC_SUCCESS;
  ------------------
  |  |   28|     71|#define SC_SUCCESS				0
  ------------------
  608|    485|}
card-mcrd.c:process_fcp:
  420|    418|{
  421|    418|	sc_context_t *ctx = card->ctx;
  422|    418|	size_t taglen, len = buflen;
  423|    418|	const u8 *tag = NULL, *p = buf;
  424|    418|	int bad_fde = 0;
  425|       |
  426|    418|	sc_log(ctx, "processing FCI bytes\n");
  ------------------
  |  |   71|    418|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  427|       |
  428|       |	/* File identifier. */
  429|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
  430|    418|	if (tag != NULL && taglen == 2) {
  ------------------
  |  Branch (430:6): [True: 53, False: 365]
  |  Branch (430:21): [True: 43, False: 10]
  ------------------
  431|     43|		file->id = (tag[0] << 8) | tag[1];
  432|     43|		sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  433|     43|			"  file identifier: 0x%02X%02X\n", tag[0], tag[1]);
  434|     43|	}
  435|       |	/* Number of data bytes in the file including structural information. */
  436|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
  437|    418|	if (!tag) {
  ------------------
  |  Branch (437:6): [True: 390, False: 28]
  ------------------
  438|       |		/* My card does not encode the filelength in 0x81 but
  439|       |		   in 0x85 which is the file descriptor extension in TCOS.
  440|       |		   Assume that this is the case when the regular file
  441|       |		   size tag is not encoded. */
  442|    390|		tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
  443|    390|		bad_fde = !!tag;
  444|    390|	}
  445|    418|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (445:6): [True: 67, False: 351]
  |  Branch (445:21): [True: 53, False: 14]
  ------------------
  446|     53|		int bytes = (tag[0] << 8) + tag[1];
  447|     53|		sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  448|     53|			"  bytes in file: %d\n", bytes);
  449|     53|		file->size = (size_t)bytes;
  450|     53|	}
  451|    418|	if (tag == NULL) {
  ------------------
  |  Branch (451:6): [True: 351, False: 67]
  ------------------
  452|    351|		tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  453|    351|		if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (453:7): [True: 39, False: 312]
  |  Branch (453:22): [True: 17, False: 22]
  ------------------
  454|     17|			int bytes = (tag[0] << 8) + tag[1];
  455|     17|			sc_log(ctx,
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  456|     17|				"  bytes in file: %d\n", bytes);
  457|     17|			file->size = (size_t)bytes;
  458|     17|		}
  459|    351|	}
  460|       |
  461|       |	/* File descriptor byte(s). */
  462|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  463|    418|	if (tag != NULL) {
  ------------------
  |  Branch (463:6): [True: 148, False: 270]
  ------------------
  464|       |		/* Fixme, this might actual be up to 6 bytes. */
  465|    148|		if (taglen > 0) {
  ------------------
  |  Branch (465:7): [True: 138, False: 10]
  ------------------
  466|    138|			unsigned char byte = tag[0];
  467|    138|			const char *type;
  468|       |
  469|    138|			file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (469:22): [True: 25, False: 113]
  ------------------
  470|    138|			sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 25, False: 113]
  |  |  ------------------
  ------------------
  471|    138|				"  shareable: %s\n",
  472|    138|				 (byte & 0x40) ? "yes" : "no");
  473|    138|			file->ef_structure = byte & 0x07;
  474|    138|			switch ((byte >> 3) & 7) {
  475|     87|			case 0:
  ------------------
  |  Branch (475:4): [True: 87, False: 51]
  ------------------
  476|     87|				type = "working EF";
  477|     87|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     87|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  478|     87|				break;
  479|      9|			case 1:
  ------------------
  |  Branch (479:4): [True: 9, False: 129]
  ------------------
  480|      9|				type = "internal EF";
  481|      9|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      9|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  482|      9|				break;
  483|     18|			case 7:
  ------------------
  |  Branch (483:4): [True: 18, False: 120]
  ------------------
  484|     18|				type = "DF";
  485|     18|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     18|#define SC_FILE_TYPE_DF			0x04
  ------------------
  486|     18|				break;
  487|     24|			default:
  ------------------
  |  Branch (487:4): [True: 24, False: 114]
  ------------------
  488|     24|				type = "unknown";
  489|     24|				break;
  490|    138|			}
  491|    138|			sc_log(ctx,
  ------------------
  |  |   71|    138|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  492|    138|				"  type: %s\n", type);
  493|    138|			sc_log(ctx,
  ------------------
  |  |   71|    138|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  494|    138|				"  EF structure: %d\n", byte & 0x07);
  495|    138|		}
  496|    148|	}
  497|       |
  498|       |	/* DF name. */
  499|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
  500|    418|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (500:6): [True: 64, False: 354]
  |  Branch (500:21): [True: 48, False: 16]
  |  Branch (500:35): [True: 42, False: 6]
  ------------------
  501|     42|		char name[17];
  502|     42|		size_t i;
  503|       |
  504|     42|		memcpy(file->name, tag, taglen);
  505|     42|		file->namelen = taglen;
  506|       |
  507|    392|		for (i = 0; i < taglen; i++) {
  ------------------
  |  Branch (507:15): [True: 350, False: 42]
  ------------------
  508|    350|			if (isalnum(tag[i]) || ispunct(tag[i]) || isspace(tag[i]))
  ------------------
  |  Branch (508:8): [True: 68, False: 282]
  |  Branch (508:27): [True: 55, False: 227]
  |  Branch (508:46): [True: 44, False: 183]
  ------------------
  509|    167|				name[i] = (const char)tag[i];
  510|    183|			else
  511|    183|				name[i] = '?';
  512|    350|		}
  513|     42|		name[taglen] = 0;
  514|     42|		sc_log(ctx, "  file name: %s\n", name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  515|     42|	}
  516|       |
  517|       |	/* Proprietary information. */
  518|    418|	tag = bad_fde ? NULL : sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
  ------------------
  |  Branch (518:8): [True: 39, False: 379]
  ------------------
  519|    418|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (519:6): [True: 21, False: 397]
  |  Branch (519:21): [True: 10, False: 11]
  ------------------
  520|     10|		sc_file_set_prop_attr(file, tag, taglen);
  521|     10|	} else
  522|    408|		file->prop_attr_len = 0;
  523|       |
  524|       |	/* Proprietary information, constructed. */
  525|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0xA5, &taglen);
  526|    418|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (526:6): [True: 10, False: 408]
  |  Branch (526:21): [True: 3, False: 7]
  ------------------
  527|      3|		sc_file_set_prop_attr(file, tag, taglen);
  528|      3|	}
  529|       |
  530|       |	/* Security attributes, proprietary format. */
  531|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x86, &taglen);
  532|    418|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (532:6): [True: 22, False: 396]
  |  Branch (532:21): [True: 16, False: 6]
  ------------------
  533|     16|		sc_file_set_sec_attr(file, tag, taglen);
  534|     16|	}
  535|       |
  536|       |	/* Security attributes, reference to expanded format. */
  537|    418|	tag = sc_asn1_find_tag(ctx, p, len, 0x8B, &taglen);
  538|    418|	if (tag && taglen) {
  ------------------
  |  Branch (538:6): [True: 142, False: 276]
  |  Branch (538:13): [True: 139, False: 3]
  ------------------
  539|    139|		process_arr(card, tag, taglen);
  540|    279|	} else if ((tag = sc_asn1_find_tag(ctx, p, len, 0xA1, &taglen))
  ------------------
  |  Branch (540:13): [True: 25, False: 254]
  ------------------
  541|     25|			&& taglen) {
  ------------------
  |  Branch (541:7): [True: 15, False: 10]
  ------------------
  542|       |		/* Not found, but there is a Security Attribute
  543|       |		   Template for interface mode. */
  544|     15|		tag = sc_asn1_find_tag(ctx, tag, taglen, 0x8B, &taglen);
  545|     15|		if (tag && taglen)
  ------------------
  |  Branch (545:7): [True: 2, False: 13]
  |  Branch (545:14): [True: 1, False: 1]
  ------------------
  546|      1|			process_arr(card, tag, taglen);
  547|     15|	}
  548|       |
  549|    418|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    418|#define SC_FILE_MAGIC			0x14426950
  ------------------
  550|    418|}
card-mcrd.c:process_arr:
  328|    140|{
  329|    140|	sc_context_t *ctx = card->ctx;
  330|    140|	struct df_info_s *dfi;
  331|    140|	struct rule_record_s *rule;
  332|    140|	size_t left, taglen;
  333|    140|	unsigned int cla, tag;
  334|    140|	const u8 *p;
  335|    140|	int skip;
  336|    140|	char dbgbuf[2048];
  337|       |
  338|       |	/* Currently we support only the short for. */
  339|    140|	if (buflen != 1) {
  ------------------
  |  Branch (339:6): [True: 8, False: 132]
  ------------------
  340|      8|		sc_log(ctx, "can't handle long ARRs\n");
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  341|      8|		return;
  342|      8|	}
  343|       |
  344|    132|	dfi = get_df_info(card);
  345|    337|	for (rule = dfi ? dfi->rule_file : NULL; rule && rule->recno != *buf;
  ------------------
  |  Branch (345:14): [True: 129, False: 3]
  |  Branch (345:43): [True: 313, False: 24]
  |  Branch (345:51): [True: 205, False: 108]
  ------------------
  346|    205|		rule = rule->next) ;
  347|    132|	if (!rule) {
  ------------------
  |  Branch (347:6): [True: 24, False: 108]
  ------------------
  348|     24|		sc_log(ctx, "referenced EF_rule record %d not found\n", *buf);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  349|     24|		return;
  350|     24|	}
  351|       |
  352|    108|	sc_hex_dump(rule->data, rule->datalen, dbgbuf, sizeof dbgbuf);
  353|    108|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  354|    108|		"rule for record %d:\n%s", *buf, dbgbuf);
  355|       |
  356|    108|	p = rule->data;
  357|    108|	left = rule->datalen;
  358|    108|	skip = 1;		/* Skip over initial unknown SC DOs. */
  359|  1.62k|	for (;;) {
  360|  1.62k|		buf = p;
  361|  1.62k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|  3.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (361:7): [True: 69, False: 1.56k]
  ------------------
  362|  1.56k|				|| p == NULL)
  ------------------
  |  Branch (362:8): [True: 39, False: 1.52k]
  ------------------
  363|    108|			break;
  364|  1.52k|		left -= (size_t)(p - buf);
  365|  1.52k|		tag |= cla;
  366|       |
  367|  1.52k|		if (tag == 0x80 && taglen != 1) {
  ------------------
  |  Branch (367:7): [True: 132, False: 1.38k]
  |  Branch (367:22): [True: 87, False: 45]
  ------------------
  368|     87|			skip = 1;
  369|  1.43k|		} else if (tag == 0x80) {	/* AM byte. */
  ------------------
  |  Branch (369:14): [True: 45, False: 1.38k]
  ------------------
  370|     45|			sc_log(ctx, "  AM_DO: %02x\n", *p);
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  371|     45|			skip = 0;
  372|  1.38k|		} else if (tag >= 0x81 && tag <= 0x8f) {	/* Cmd description */
  ------------------
  |  Branch (372:14): [True: 846, False: 543]
  |  Branch (372:29): [True: 166, False: 680]
  ------------------
  373|    166|			sc_hex_dump(p, taglen, dbgbuf, sizeof dbgbuf);
  374|    166|			sc_log(ctx, "  AM_DO: cmd[%s%s%s%s] %s",
  ------------------
  |  |   71|  1.32k|#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: 84, False: 82]
  |  |  |  Branch (71:122): [True: 73, False: 93]
  |  |  |  Branch (71:122): [True: 65, False: 101]
  |  |  |  Branch (71:122): [True: 67, False: 99]
  |  |  ------------------
  ------------------
  375|    166|				 (tag & 8) ? "C" : "",
  376|    166|				 (tag & 4) ? "I" : "",
  377|    166|				 (tag & 2) ? "1" : "",
  378|    166|				 (tag & 1) ? "2" : "", dbgbuf);
  379|    166|			skip = 0;
  380|  1.22k|		} else if (tag == 0x9C) {	/* Proprietary state machine descrip. */
  ------------------
  |  Branch (380:14): [True: 21, False: 1.20k]
  ------------------
  381|     21|			skip = 1;
  382|  1.20k|		} else if (!skip) {
  ------------------
  |  Branch (382:14): [True: 730, False: 472]
  ------------------
  383|    730|			switch (tag) {
  ------------------
  |  Branch (383:12): [True: 385, False: 345]
  ------------------
  384|    131|			case 0x90:	/* Always */
  ------------------
  |  Branch (384:4): [True: 131, False: 599]
  ------------------
  385|    131|				sc_log(ctx, "     SC: always\n");
  ------------------
  |  |   71|    131|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  386|    131|				break;
  387|     10|			case 0x97:	/* Never */
  ------------------
  |  Branch (387:4): [True: 10, False: 720]
  ------------------
  388|     10|				sc_log(ctx, "     SC: never\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__
  |  |  ------------------
  ------------------
  389|     10|				break;
  390|     23|			case 0xA4:	/* Authentication, value is a CRT. */
  ------------------
  |  Branch (390:4): [True: 23, False: 707]
  ------------------
  391|     23|				sc_log_hex(ctx, "     SC: auth", p, taglen);
  ------------------
  |  |  129|     23|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     23|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|     23|				break;
  393|       |
  394|     18|			case 0xB4:
  ------------------
  |  Branch (394:4): [True: 18, False: 712]
  ------------------
  395|     36|			case 0xB6:
  ------------------
  |  Branch (395:4): [True: 18, False: 712]
  ------------------
  396|    121|			case 0xB8:	/* Cmd or resp with SM, value is a CRT. */
  ------------------
  |  Branch (396:4): [True: 85, False: 645]
  ------------------
  397|    121|				sc_log_hex(ctx, "     SC: cmd/resp", p, taglen);
  ------------------
  |  |  129|    121|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    121|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|    121|				break;
  399|       |
  400|     38|			case 0x9E:	/* Security Condition byte. */
  ------------------
  |  Branch (400:4): [True: 38, False: 692]
  ------------------
  401|     38|				sc_log_hex(ctx, "     SC: condition", p, taglen);
  ------------------
  |  |  129|     38|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     38|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|     38|				break;
  403|       |
  404|     18|			case 0xA0:	/* OR template. */
  ------------------
  |  Branch (404:4): [True: 18, False: 712]
  ------------------
  405|     18|				sc_log(ctx, "     SC: OR\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  406|     18|				break;
  407|     44|			case 0xAF:	/* AND template. */
  ------------------
  |  Branch (407:4): [True: 44, False: 686]
  ------------------
  408|     44|				sc_log(ctx, "     SC: AND\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  409|     44|				break;
  410|    730|			}
  411|    730|		}
  412|  1.52k|		left -= taglen;
  413|  1.52k|		p += taglen;
  414|  1.52k|	}
  415|       |
  416|    108|}
card-mcrd.c:mcrd_finish:
  229|    483|{
  230|    483|	struct mcrd_priv_data *priv;
  231|       |
  232|    483|	if (card == NULL)
  ------------------
  |  Branch (232:6): [True: 0, False: 483]
  ------------------
  233|      0|		return 0;
  234|    483|	priv = DRVDATA(card);
  ------------------
  |  |  103|    483|#define DRVDATA(card) ((struct mcrd_priv_data *) ((card)->drv_data))
  ------------------
  235|    936|	while (priv->df_infos) {
  ------------------
  |  Branch (235:9): [True: 453, False: 483]
  ------------------
  236|    453|		struct df_info_s *tmp = priv->df_infos->next;
  237|    453|		clear_special_files(priv->df_infos);
  238|    453|		free(priv->df_infos);
  239|    453|		priv->df_infos = tmp;
  240|    453|	}
  241|    483|	free(priv);
  242|    483|	return 0;
  243|    483|}
card-mcrd.c:mcrd_select_file:
  849|  2.90k|{
  850|  2.90k|	struct mcrd_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  103|  2.90k|#define DRVDATA(card) ((struct mcrd_priv_data *) ((card)->drv_data))
  ------------------
  851|  2.90k|	int r = 0;
  852|       |
  853|  2.90k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.90k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.90k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.90k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.90k]
  |  |  ------------------
  ------------------
  854|       |
  855|  2.90k|	if (path->type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  2.90k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (855:6): [True: 893, False: 2.01k]
  ------------------
  856|    893|		if (path->len > 16)
  ------------------
  |  Branch (856:7): [True: 0, False: 893]
  ------------------
  857|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  858|    893|		r = do_select(card, MCRD_SEL_AID, path->value, path->len, file);
  859|    893|		priv->curpathlen = 0;
  860|  2.01k|	} else {
  861|  2.01k|		unsigned short int pathtmp[SC_MAX_PATH_SIZE / 2];
  862|  2.01k|		unsigned short int *pathptr;
  863|  2.01k|		int samepath = 1;
  864|  2.01k|		size_t pathlen, n;
  865|       |
  866|  2.01k|		if ((path->len & 1) || path->len > sizeof(pathtmp))
  ------------------
  |  Branch (866:7): [True: 0, False: 2.01k]
  |  Branch (866:26): [True: 0, False: 2.01k]
  ------------------
  867|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  868|       |
  869|  2.01k|		memset(pathtmp, 0, sizeof pathtmp);
  870|  2.01k|		pathptr = pathtmp;
  871|  5.69k|		for (n = 0; n < path->len; n += 2)
  ------------------
  |  Branch (871:15): [True: 3.68k, False: 2.01k]
  ------------------
  872|  3.68k|			pathptr[n >> 1] =
  873|  3.68k|				(unsigned short)((path->value[n] << 8) | path->value[n + 1]);
  874|  2.01k|		pathlen = path->len >> 1;
  875|       |
  876|  2.01k|		if (pathlen == priv->curpathlen && priv->is_ef != 2) {
  ------------------
  |  Branch (876:7): [True: 858, False: 1.15k]
  |  Branch (876:38): [True: 858, False: 0]
  ------------------
  877|  1.71k|			for (n = 0; n < pathlen; n++) {
  ------------------
  |  Branch (877:16): [True: 1.23k, False: 486]
  ------------------
  878|  1.23k|				if (priv->curpath[n] != pathptr[n]) {
  ------------------
  |  Branch (878:9): [True: 372, False: 859]
  ------------------
  879|    372|					samepath = 0;
  880|    372|					break;
  881|    372|				}
  882|  1.23k|			}
  883|  1.15k|		} else if (priv->curpathlen < pathlen && priv->is_ef != 2) {
  ------------------
  |  Branch (883:14): [True: 1.14k, False: 10]
  |  Branch (883:44): [True: 1.14k, False: 0]
  ------------------
  884|  1.89k|			for (n = 0; n < priv->curpathlen; n++) {
  ------------------
  |  Branch (884:16): [True: 781, False: 1.11k]
  ------------------
  885|    781|				if (priv->curpath[n] != pathptr[n]) {
  ------------------
  |  Branch (885:9): [True: 37, False: 744]
  ------------------
  886|     37|					samepath = 0;
  887|     37|					break;
  888|     37|				}
  889|    781|			}
  890|  1.14k|			pathptr = pathptr + n;
  891|  1.14k|			pathlen = pathlen - n;
  892|  1.14k|		}
  893|       |
  894|  2.01k|		if (samepath != 1 || priv->is_ef == 0 || priv->is_ef == 1) {
  ------------------
  |  Branch (894:7): [True: 409, False: 1.60k]
  |  Branch (894:24): [True: 1.51k, False: 90]
  |  Branch (894:44): [True: 90, False: 0]
  ------------------
  895|  2.01k|			if (path->type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  2.01k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (895:8): [True: 2.01k, False: 0]
  ------------------
  896|  2.01k|				r = select_file_by_path(card, pathptr, pathlen, file);
  897|      0|			else {	/* SC_PATH_TYPE_FILEID */
  898|      0|				r = select_file_by_fid(card, pathptr, pathlen, file);
  899|      0|			}
  900|  2.01k|		}
  901|  2.01k|	}
  902|       |
  903|  2.90k|	return r;
  904|  2.90k|}
card-mcrd.c:select_file_by_path:
  688|  2.01k|{
  689|  2.01k|	struct mcrd_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  103|  2.01k|#define DRVDATA(card) ((struct mcrd_priv_data *) ((card)->drv_data))
  ------------------
  690|  2.01k|	int r;
  691|  2.01k|	size_t i;
  692|       |
  693|  2.01k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.01k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.01k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.01k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.01k]
  |  |  ------------------
  ------------------
  694|       |
  695|  2.01k|	if (!(!priv->curpathlen || priv->curpath[0] == MFID))
  ------------------
  |  |   67|  1.54k|#define MFID 0x3F00
  ------------------
  |  Branch (695:8): [True: 468, False: 1.54k]
  |  Branch (695:29): [True: 1.54k, False: 2]
  ------------------
  696|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  697|       |
  698|  2.01k|	if (pathlen && *pathptr == 0x3FFF) {
  ------------------
  |  Branch (698:6): [True: 2.01k, False: 0]
  |  Branch (698:17): [True: 17, False: 1.99k]
  ------------------
  699|     17|		pathlen--;
  700|     17|		pathptr++;
  701|     17|	}
  702|       |
  703|  2.01k|	if (!pathlen || pathlen >= MAX_CURPATH)
  ------------------
  |  |   71|  2.01k|#define MAX_CURPATH 10
  ------------------
  |  Branch (703:6): [True: 1, False: 2.01k]
  |  Branch (703:18): [True: 0, False: 2.01k]
  ------------------
  704|      1|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  705|  2.01k|	else if (pathlen == 1 && pathptr[0] == MFID) {
  ------------------
  |  |   67|  1.20k|#define MFID 0x3F00
  ------------------
  |  Branch (705:11): [True: 1.20k, False: 813]
  |  Branch (705:27): [True: 484, False: 716]
  ------------------
  706|       |		/* MF requested: clear the cache and select it. */
  707|    484|		priv->curpathlen = 0;
  708|    484|		r = select_part(card, MCRD_SEL_MF, pathptr[0], file);
  709|    484|		LOG_TEST_RET(card->ctx, r, "unable to select MF");
  ------------------
  |  |  174|    484|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    484|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    484|	int _ret = (r); \
  |  |  |  |  168|    484|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 122, False: 362]
  |  |  |  |  ------------------
  |  |  |  |  169|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    122|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    122|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    122|		return _ret; \
  |  |  |  |  172|    122|	} \
  |  |  |  |  173|    484|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 362]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  710|    362|		priv->curpath[0] = pathptr[0];
  711|    362|		priv->curpathlen = 1;
  712|    362|		priv->is_ef = 0;
  713|  1.52k|	} else if (pathlen > 1 && pathptr[0] == MFID) {
  ------------------
  |  |   67|    813|#define MFID 0x3F00
  ------------------
  |  Branch (713:13): [True: 813, False: 716]
  |  Branch (713:28): [True: 754, False: 59]
  ------------------
  714|       |		/* Absolute addressing, check cache to avoid
  715|       |		   unnecessary selects. */
  716|  1.13k|		for (i = 0; (i < pathlen && i < priv->curpathlen
  ------------------
  |  Branch (716:16): [True: 1.12k, False: 3]
  |  Branch (716:31): [True: 719, False: 408]
  ------------------
  717|    719|				&& pathptr[i] == priv->curpath[i]); i++) ;
  ------------------
  |  Branch (717:8): [True: 376, False: 343]
  ------------------
  718|    754|		if (!priv->curpathlen) {
  ------------------
  |  Branch (718:7): [True: 408, False: 346]
  ------------------
  719|       |			/* Need to do all selects starting at the root. */
  720|    408|			priv->curpathlen = 0;
  721|    408|			priv->is_ef = 0;
  722|    408|			r = select_down(card, pathptr, pathlen, 0, file);
  723|    408|		} else if (i == pathlen && i < priv->curpathlen) {
  ------------------
  |  Branch (723:14): [True: 3, False: 343]
  |  Branch (723:30): [True: 0, False: 3]
  ------------------
  724|       |			/* Go upwards; we do it the easy way and start
  725|       |			   at the root.  However we know that the target is a DF. */
  726|      0|			priv->curpathlen = 0;
  727|      0|			priv->is_ef = 0;
  728|      0|			r = select_down(card, pathptr, pathlen, 1, file);
  729|    346|		} else if (i == pathlen && i == priv->curpathlen) {
  ------------------
  |  Branch (729:14): [True: 3, False: 343]
  |  Branch (729:30): [True: 3, False: 0]
  ------------------
  730|       |			/* Already selected. */
  731|      3|			if (!file)
  ------------------
  |  Branch (731:8): [True: 3, False: 0]
  ------------------
  732|      3|				r = 0;	/* The caller did not request the fci. */
  733|      0|			else {
  734|       |				/* This EF or DF was already selected, but
  735|       |				   we need to get the FCI, so we have
  736|       |				   to select again. */
  737|      0|				if (!(priv->curpathlen > 1))
  ------------------
  |  Branch (737:9): [True: 0, False: 0]
  ------------------
  738|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  739|      0|				priv->curpathlen--;
  740|      0|				priv->is_ef = 0;
  741|      0|				r = select_down(card, pathptr + pathlen - 1, 1,
  742|      0|						0, file);
  743|      0|			}
  744|    343|		} else {
  745|       |			/* We have to append something.  For now we
  746|       |			   simply start at the root. (fixme) */
  747|    343|			priv->curpathlen = 0;
  748|    343|			priv->is_ef = 0;
  749|    343|			r = select_down(card, pathptr, pathlen, 0, file);
  750|    343|		}
  751|    775|	} else {
  752|       |		/* Relative addressing. */
  753|    775|		if (!priv->curpathlen) {
  ------------------
  |  Branch (753:7): [True: 60, False: 715]
  ------------------
  754|       |			/* Relative addressing without a current path. So we
  755|       |			   select the MF first. */
  756|     60|			r = select_part(card, MCRD_SEL_MF, pathptr[0], file);
  757|     60|			LOG_TEST_RET(card->ctx, r, "unable to select MF");
  ------------------
  |  |  174|     60|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     60|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     60|	int _ret = (r); \
  |  |  |  |  168|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|     48|			priv->curpath[0] = pathptr[0];
  759|     48|			priv->curpathlen = 1;
  760|     48|			priv->is_ef = 0;
  761|     48|		}
  762|    763|		if (priv->is_ef) {
  ------------------
  |  Branch (762:7): [True: 104, False: 659]
  ------------------
  763|    104|			if(!(priv->curpathlen > 1))
  ------------------
  |  Branch (763:7): [True: 0, False: 104]
  ------------------
  764|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  765|    104|			priv->curpathlen--;
  766|    104|			priv->is_ef = 0;
  767|    104|		}
  768|       |		/* Free the previously allocated file so we do not leak memory here */
  769|    763|		if (file) {
  ------------------
  |  Branch (769:7): [True: 612, False: 151]
  ------------------
  770|    612|			sc_file_free(*file);
  771|    612|			*file = NULL;
  772|    612|		}
  773|    763|		r = select_down(card, pathptr, pathlen, 0, file);
  774|    763|	}
  775|  1.88k|	return r;
  776|  2.01k|}
card-mcrd.c:select_down:
  644|  1.51k|{
  645|  1.51k|	struct mcrd_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  103|  1.51k|#define DRVDATA(card) ((struct mcrd_priv_data *) ((card)->drv_data))
  ------------------
  646|  1.51k|	int r;
  647|  1.51k|	int found_ef = 0;
  648|       |
  649|  1.51k|	if (!pathlen)
  ------------------
  |  Branch (649:6): [True: 0, False: 1.51k]
  ------------------
  650|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  651|       |
  652|  2.36k|	for (; pathlen; pathlen--, pathptr++) {
  ------------------
  |  Branch (652:9): [True: 1.78k, False: 575]
  ------------------
  653|  1.78k|		if (priv->curpathlen == MAX_CURPATH)
  ------------------
  |  |   71|  1.78k|#define MAX_CURPATH 10
  ------------------
  |  Branch (653:7): [True: 1, False: 1.78k]
  ------------------
  654|  1.78k|			LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|  1.78k|					"path too long for cache");
  656|  1.78k|		r = -1;		/* force DF select. */
  657|  1.78k|		if (pathlen == 1 && !df_only) {
  ------------------
  |  Branch (657:7): [True: 931, False: 853]
  |  Branch (657:23): [True: 931, False: 0]
  ------------------
  658|       |			/* first try to select an EF and retry an DF
  659|       |			   on error. */
  660|    931|			r = select_part(card, MCRD_SEL_EF, *pathptr, file);
  661|    931|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|    931|#define SC_SUCCESS				0
  ------------------
  |  Branch (661:8): [True: 485, False: 446]
  ------------------
  662|    485|				found_ef = 1;
  663|    931|		}
  664|  1.78k|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.78k|#define SC_SUCCESS				0
  ------------------
  |  Branch (664:7): [True: 1.29k, False: 485]
  ------------------
  665|  1.29k|			r = select_part(card, MCRD_SEL_DF, *pathptr,
  666|  1.29k|					pathlen == 1 ? file : NULL);
  ------------------
  |  Branch (666:6): [True: 446, False: 853]
  ------------------
  667|  1.78k|		LOG_TEST_RET(card->ctx, r, "unable to select DF");
  ------------------
  |  |  174|  1.78k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.78k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.78k|	int _ret = (r); \
  |  |  |  |  168|  1.78k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 938, False: 846]
  |  |  |  |  ------------------
  |  |  |  |  169|    938|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    938|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    938|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    938|		return _ret; \
  |  |  |  |  172|    938|	} \
  |  |  |  |  173|  1.78k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 846]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  668|    846|		priv->curpath[priv->curpathlen] = *pathptr;
  669|    846|		priv->curpathlen++;
  670|    846|	}
  671|    575|	priv->is_ef = found_ef;
  672|    575|	if (!found_ef)
  ------------------
  |  Branch (672:6): [True: 90, False: 485]
  ------------------
  673|     90|		load_special_files(card);
  674|       |
  675|    575|	return 0;
  676|  1.51k|}
card-mcrd.c:mcrd_pin_cmd:
 1027|      1|{
 1028|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1029|      1|	data->pin1.offset = 5;
 1030|      1|	data->pin2.offset = 5;
 1031|       |
 1032|      1|	if (card->type == SC_CARD_TYPE_MCRD_GENERIC) {
  ------------------
  |  Branch (1032:6): [True: 1, False: 0]
  ------------------
 1033|      1|		sc_log(card->ctx, "modify pin reference for D-Trust\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__
  |  |  ------------------
  ------------------
 1034|      1|		if (data->pin_reference == 0x02)
  ------------------
  |  Branch (1034:7): [True: 1, False: 0]
  ------------------
 1035|      1|			data->pin_reference = data->pin_reference | 0x80;
 1036|      1|	}
 1037|      1|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, iso_ops->pin_cmd(card, data));
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1038|      1|}

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

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

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

nqapplet_set_security_env:
  259|    639|{
  260|       |	/* Note: the NQ-Applet does not have APDU for SET SECURITY ENV,
  261|       |	this function checks the intended parameters and sets card_data.key_reference */
  262|    639|	nqapplet_driver_data_ptr data;
  263|    639|	u8 key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    639|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
  264|       |
  265|    639|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    639|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    639|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    639|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    639|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 639]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|       |
  267|    639|	data = (nqapplet_driver_data_ptr)card->drv_data;
  268|    639|	data->key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    639|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
  269|       |
  270|    639|	if (se_num != 0) {
  ------------------
  |  Branch (270:6): [True: 0, False: 639]
  ------------------
  271|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      0|		             "Storing of security environment is not supported");
  273|      0|	}
  274|    639|	if (env->key_ref_len == 1) {
  ------------------
  |  Branch (274:6): [True: 639, False: 0]
  ------------------
  275|    639|		key_reference = env->key_ref[0];
  276|    639|	}
  277|       |
  278|    639|	switch (env->operation) {
  279|    475|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    475|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (279:2): [True: 475, False: 164]
  ------------------
  280|    475|		if (key_reference != KEY_REFERENCE_AUTH_KEY && key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   48|    950|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
              		if (key_reference != KEY_REFERENCE_AUTH_KEY && key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   49|    145|#define KEY_REFERENCE_ENCR_KEY 0x02
  ------------------
  |  Branch (280:7): [True: 145, False: 330]
  |  Branch (280:50): [True: 0, False: 145]
  ------------------
  281|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_INCOMPATIBLE_KEY,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  282|      0|			             "Decipher operation is only supported with AUTH and ENCR keys.");
  283|      0|		}
  284|    475|		data->key_reference = key_reference;
  285|    475|		break;
  286|    164|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    164|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (286:2): [True: 164, False: 475]
  ------------------
  287|    164|		if (key_reference != KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    164|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (287:7): [True: 0, False: 164]
  ------------------
  288|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_INCOMPATIBLE_KEY,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  289|      0|			             "Sign operation is only supported with AUTH key.");
  290|      0|		}
  291|    164|		data->key_reference = key_reference;
  292|    164|		break;
  293|      0|	default:
  ------------------
  |  Branch (293:2): [True: 0, False: 639]
  ------------------
  294|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported sec. operation.");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|    639|	}
  296|       |
  297|    639|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    639|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    639|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    639|	int _ret = r; \
  |  |  |  |  155|    639|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 639, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    639|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 639]
  |  |  |  |  ------------------
  |  |  |  |  157|    639|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    639|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    639|	return _ret; \
  |  |  |  |  163|    639|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|    639|}
sc_get_nqApplet_driver:
  471|  16.9k|{
  472|  16.9k|	sc_card_driver_t *iso_driver = sc_get_iso7816_driver();
  473|       |
  474|  16.9k|	if (iso_operations == NULL) {
  ------------------
  |  Branch (474:6): [True: 1, False: 16.9k]
  ------------------
  475|      1|		iso_operations = iso_driver->ops;
  476|      1|	}
  477|       |
  478|  16.9k|	nqapplet_operations = *iso_driver->ops;
  479|       |
  480|       |	/* supported operations */
  481|  16.9k|	nqapplet_operations.match_card = nqapplet_match_card;
  482|  16.9k|	nqapplet_operations.init = nqapplet_init;
  483|  16.9k|	nqapplet_operations.finish = nqapplet_finish;
  484|  16.9k|	nqapplet_operations.get_response = nqapplet_get_response;
  485|  16.9k|	nqapplet_operations.get_challenge = nqapplet_get_challenge;
  486|  16.9k|	nqapplet_operations.logout = nqapplet_logout;
  487|  16.9k|	nqapplet_operations.set_security_env = nqapplet_set_security_env;
  488|  16.9k|	nqapplet_operations.decipher = nqapplet_decipher;
  489|  16.9k|	nqapplet_operations.compute_signature = nqapplet_compute_signature;
  490|  16.9k|	nqapplet_operations.check_sw = nqapplet_check_sw;
  491|  16.9k|	nqapplet_operations.get_data = nqapplet_get_data;
  492|  16.9k|	nqapplet_operations.select_file = nqapplet_select_file;
  493|  16.9k|	nqapplet_operations.card_ctl = nqapplet_card_ctl;
  494|  16.9k|	nqapplet_operations.pin_cmd = nqapplet_pin_cmd;
  495|       |
  496|       |	/* unsupported operations */
  497|  16.9k|	nqapplet_operations.read_binary = NULL;
  498|  16.9k|	nqapplet_operations.write_binary = NULL;
  499|  16.9k|	nqapplet_operations.update_binary = NULL;
  500|  16.9k|	nqapplet_operations.erase_binary = NULL;
  501|  16.9k|	nqapplet_operations.read_record = NULL;
  502|  16.9k|	nqapplet_operations.write_record = NULL;
  503|  16.9k|	nqapplet_operations.append_record = NULL;
  504|  16.9k|	nqapplet_operations.update_record = NULL;
  505|       |
  506|  16.9k|	nqapplet_operations.verify = NULL;
  507|  16.9k|	nqapplet_operations.restore_security_env = NULL;
  508|  16.9k|	nqapplet_operations.change_reference_data = NULL;
  509|  16.9k|	nqapplet_operations.reset_retry_counter = NULL;
  510|  16.9k|	nqapplet_operations.create_file = NULL;
  511|  16.9k|	nqapplet_operations.delete_file = NULL;
  512|  16.9k|	nqapplet_operations.list_files = NULL;
  513|  16.9k|	nqapplet_operations.process_fci = NULL;
  514|  16.9k|	nqapplet_operations.construct_fci = NULL;
  515|  16.9k|	nqapplet_operations.put_data = NULL;
  516|  16.9k|	nqapplet_operations.delete_record = NULL;
  517|  16.9k|	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|  16.9k|	return &nqapplet_driver;
  526|  16.9k|}
card-nqApplet.c:nqapplet_match_card:
  143|  2.60k|{
  144|  2.60k|	int rv = _sc_match_atr(card, nqapplet_atrs, &card->type);
  145|  2.60k|	return (rv >= 0);
  146|  2.60k|}
card-nqApplet.c:nqapplet_init:
  149|    246|{
  150|    246|	u8 version_major;
  151|    246|	u8 version_minor;
  152|    246|	u8 serial_nr[APPLET_SERIALNR_LEN];
  153|    246|	size_t cb_serial_nr = sizeof(serial_nr);
  154|    246|	unsigned long rsa_flags = 0;
  155|       |
  156|    246|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    246|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    246|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    246|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    246|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 246]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|    246|	int rv =
  158|    246|		select_nqapplet(card, &version_major, &version_minor, serial_nr, cb_serial_nr, &cb_serial_nr);
  159|    246|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    246|#define SC_SUCCESS				0
  ------------------
  |  Branch (159:6): [True: 61, False: 185]
  ------------------
  160|     61|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "Cannot select NQ-Applet.");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|     61|	}
  162|       |
  163|    185|	rv = init_driver_data(card, version_major, version_minor);
  164|    185|	LOG_TEST_RET(card->ctx, rv, "Failed to initialize driver data.");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|       |
  166|    185|	card->max_send_size = 255;
  167|    185|	card->max_recv_size = 256;
  168|    185|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    185|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    185|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  169|    185|	rsa_flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    185|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  170|    185|	_sc_card_add_rsa_alg(card, 3072, rsa_flags, 0);
  171|       |
  172|    185|	card->serialnr.len = MIN(sizeof(card->serialnr.value), cb_serial_nr);
  ------------------
  |  |   69|    185|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 185]
  |  |  ------------------
  ------------------
  173|    185|	memcpy(card->serialnr.value, serial_nr, card->serialnr.len);
  174|       |
  175|    185|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    185|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    185|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    185|	int _ret = r; \
  |  |  |  |  155|    185|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 185, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    185|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  157|    185|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    185|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    185|	return _ret; \
  |  |  |  |  163|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|    185|}
card-nqApplet.c:select_nqapplet:
  110|    276|{
  111|    276|	int rv;
  112|    276|	sc_context_t *ctx = card->ctx;
  113|    276|	u8 buffer[APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN + 2];
  114|    276|	size_t cb_buffer = sizeof(buffer);
  115|    276|	size_t cb_aid = sizeof(nqapplet_aid);
  116|       |
  117|    276|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    276|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  118|       |
  119|    276|	rv = iso7816_select_aid(card, nqapplet_aid, cb_aid, buffer, &cb_buffer);
  120|    276|	LOG_TEST_RET(card->ctx, rv, "Failed to select NQ-Applet.");
  ------------------
  |  |  174|    276|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    276|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    276|	int _ret = (r); \
  |  |  |  |  168|    276|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 58, False: 218]
  |  |  |  |  ------------------
  |  |  |  |  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|    276|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 218]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|    218|	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   30|    218|#define APPLET_VERSION_LEN  2
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   31|    218|#define APPLET_MEMTYPE_LEN  1
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   32|    218|#define APPLET_SERIALNR_LEN 8
  ------------------
  |  Branch (122:6): [True: 28, False: 190]
  ------------------
  123|     28|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  124|     28|	}
  125|       |
  126|    190|	if (version_major != NULL) {
  ------------------
  |  Branch (126:6): [True: 185, False: 5]
  ------------------
  127|    185|		*version_major = buffer[0];
  128|    185|	}
  129|    190|	if (version_minor != NULL) {
  ------------------
  |  Branch (129:6): [True: 185, False: 5]
  ------------------
  130|    185|		*version_minor = buffer[1];
  131|    185|	}
  132|    190|	if (serial_nr != NULL && cb_serial_nr > 0 && serial_nr_len != NULL) {
  ------------------
  |  Branch (132:6): [True: 185, False: 5]
  |  Branch (132:27): [True: 185, False: 0]
  |  Branch (132:47): [True: 185, False: 0]
  ------------------
  133|    185|		size_t cb = MIN(APPLET_SERIALNR_LEN, cb_serial_nr);
  ------------------
  |  |   69|    185|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 185]
  |  |  ------------------
  ------------------
  134|    185|		memcpy(serial_nr, buffer + 3, cb);
  135|    185|		*serial_nr_len = cb;
  136|    185|	}
  137|       |
  138|    190|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 190]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  139|    190|}
card-nqApplet.c:init_driver_data:
   82|    185|{
   83|    185|	nqapplet_driver_data_ptr data = calloc(1, sizeof(struct nqapplet_driver_data));
   84|    185|	if (data == NULL) {
  ------------------
  |  Branch (84:6): [True: 0, False: 185]
  ------------------
   85|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   86|      0|	}
   87|       |
   88|    185|	data->version_major = version_major;
   89|    185|	data->version_minor = version_minor;
   90|    185|	data->key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    185|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
   91|    185|	card->drv_data = (void *)data;
   92|    185|	return SC_SUCCESS;
  ------------------
  |  |   28|    185|#define SC_SUCCESS				0
  ------------------
   93|    185|}
card-nqApplet.c:nqapplet_finish:
  179|    185|{
  180|    185|	nqapplet_driver_data_ptr data = (nqapplet_driver_data_ptr)card->drv_data;
  181|       |
  182|    185|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    185|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    185|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    185|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    185|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|    185|	if (data != NULL) {
  ------------------
  |  Branch (183:6): [True: 185, False: 0]
  ------------------
  184|    185|		free(data);
  185|    185|		card->drv_data = NULL;
  186|    185|	}
  187|    185|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    185|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    185|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    185|	int _ret = r; \
  |  |  |  |  155|    185|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 185, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    185|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  157|    185|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    185|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    185|	return _ret; \
  |  |  |  |  163|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|    185|}
card-nqApplet.c:nqapplet_get_response:
  192|  1.19k|{
  193|  1.19k|	struct sc_apdu apdu = {0};
  194|  1.19k|	int rv;
  195|  1.19k|	size_t resplen;
  196|       |
  197|  1.19k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.19k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.19k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|  1.19k|	resplen = MIN(sc_get_max_recv_size(card), *cb_resp);
  ------------------
  |  |   69|  1.19k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 1.19k]
  |  |  ------------------
  ------------------
  199|       |
  200|  1.19k|	sc_format_apdu_ex(&apdu, 0x80, 0xC0, 0x00, 0x00, NULL, 0, resp, resplen);
  201|  1.19k|	apdu.flags |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  1.19k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  202|       |
  203|  1.19k|	rv = sc_transmit_apdu(card, &apdu);
  204|  1.19k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.19k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.19k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.19k|	int _ret = (r); \
  |  |  |  |  168|  1.19k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 1.18k]
  |  |  |  |  ------------------
  |  |  |  |  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.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.18k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|       |
  206|  1.18k|	*cb_resp = apdu.resplen;
  207|       |
  208|  1.18k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (208:6): [True: 72, False: 1.10k]
  ------------------
  209|     72|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 40, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|     72|	}
  211|  1.10k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (211:6): [True: 48, False: 1.06k]
  |  Branch (211:26): [True: 27, False: 21]
  ------------------
  212|     27|		rv = SC_SUCCESS;
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
  213|  1.08k|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (213:13): [True: 954, False: 127]
  ------------------
  214|    954|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (214:8): [True: 785, False: 169]
  ------------------
  215|    954|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (215:13): [True: 27, False: 100]
  |  Branch (215:33): [True: 14, False: 13]
  ------------------
  216|     14|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  217|     14|	}
  218|       |
  219|  1.10k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  1.10k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.10k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.10k|	int _ret = r; \
  |  |  |  |  155|  1.10k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 154, False: 954]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 140]
  |  |  |  |  ------------------
  |  |  |  |  157|    154|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    954|	} else { \
  |  |  |  |  159|    954|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    954|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    954|	} \
  |  |  |  |  162|  1.10k|	return _ret; \
  |  |  |  |  163|  1.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|  1.10k|}
card-nqApplet.c:nqapplet_decipher:
  301|    425|{
  302|    425|	int rv;
  303|    425|	struct sc_apdu apdu;
  304|    425|	u8 p1 = 0x80;
  305|    425|	u8 p2 = 0x86;
  306|    425|	nqapplet_driver_data_ptr drv_data;
  307|       |
  308|    425|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    425|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    425|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    425|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    425|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 425]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|       |
  310|    425|	drv_data = (nqapplet_driver_data_ptr)card->drv_data;
  311|       |
  312|    425|	if (drv_data->key_reference == KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    425|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (312:6): [True: 290, False: 135]
  ------------------
  313|    290|		p1 = 0x9E;
  314|    290|		p2 = 0x9A;
  315|    290|	} else if (drv_data->key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   49|    135|#define KEY_REFERENCE_ENCR_KEY 0x02
  ------------------
  |  Branch (315:13): [True: 0, False: 135]
  ------------------
  316|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INCOMPATIBLE_KEY,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|      0|		             "Decipher operation is only supported with AUTH and ENCR keys.");
  318|      0|	}
  319|       |
  320|       |	/* the applet supports only 3072 RAW RSA, input buffer size must be 384 octets,
  321|       |	output buffer size must be at least 384 octets */
  322|    425|	sc_format_apdu_ex(&apdu, 0x80, 0x2A, p1, p2, data, cb_data, out, outlen);
  323|    425|	apdu.le = 256;
  324|    425|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    425|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  325|    425|	rv = sc_transmit_apdu(card, &apdu);
  326|    425|	LOG_TEST_RET(card->ctx, rv, "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: 129, False: 296]
  |  |  |  |  ------------------
  |  |  |  |  169|    129|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    129|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    129|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    129|		return _ret; \
  |  |  |  |  172|    129|	} \
  |  |  |  |  173|    425|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 296]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|       |
  328|    296|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (328:6): [True: 74, False: 222]
  |  Branch (328:26): [True: 61, False: 13]
  ------------------
  329|     61|		rv = (int)apdu.resplen;
  330|    235|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (330:13): [True: 0, False: 235]
  ------------------
  331|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (331:8): [True: 0, False: 0]
  ------------------
  332|    235|	} else {
  333|    235|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  334|    235|	}
  335|       |
  336|    296|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    296|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    296|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    296|	int _ret = r; \
  |  |  |  |  155|    296|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 242, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  156|    242|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    235|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 235, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|    242|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    242|	} else { \
  |  |  |  |  159|     54|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     54|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     54|	} \
  |  |  |  |  162|    296|	return _ret; \
  |  |  |  |  163|    296|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|    296|}
card-nqApplet.c:nqapplet_compute_signature:
  341|    164|{
  342|    164|	int rv;
  343|    164|	struct sc_apdu apdu;
  344|    164|	nqapplet_driver_data_ptr drv_data;
  345|       |
  346|    164|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    164|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    164|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    164|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    164|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 164]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|    164|	drv_data = (nqapplet_driver_data_ptr)card->drv_data;
  348|       |
  349|    164|	if (drv_data->key_reference != KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    164|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (349:6): [True: 0, False: 164]
  ------------------
  350|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INCOMPATIBLE_KEY,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		             "Sign operation is only supported with AUTH key.");
  352|      0|	}
  353|       |
  354|       |	/* the applet supports only 3072 RAW RSA, input buffer size must be 384 octets,
  355|       |	output buffer size must be at least 384 octets */
  356|    164|	sc_format_apdu_ex(&apdu, 0x80, 0x2A, 0x9E, 0x9A, data, cb_data, out, outlen);
  357|    164|	apdu.le = 256;
  358|    164|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    164|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  359|    164|	rv = sc_transmit_apdu(card, &apdu);
  360|    164|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    164|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    164|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    164|	int _ret = (r); \
  |  |  |  |  168|    164|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 141, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  169|    141|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    141|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    141|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    141|		return _ret; \
  |  |  |  |  172|    141|	} \
  |  |  |  |  173|    164|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|     23|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (362:6): [True: 17, False: 6]
  |  Branch (362:26): [True: 16, False: 1]
  ------------------
  363|     16|		rv = (int)apdu.resplen;
  364|     16|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (364:13): [True: 0, False: 7]
  ------------------
  365|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (365:8): [True: 0, False: 0]
  ------------------
  366|      7|	} else {
  367|      7|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  368|      7|	}
  369|       |
  370|     23|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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: 7, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     16|	} else { \
  |  |  |  |  159|     16|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     16|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     16|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  371|     23|}
card-nqApplet.c:nqapplet_check_sw:
  374|  1.52k|{
  375|  1.52k|	const int nqapplet_error_count = sizeof(nqapplet_errors) / sizeof(struct sc_card_error);
  376|  1.52k|	int i;
  377|       |
  378|  1.52k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.52k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.52k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.52k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.52k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.52k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|  1.52k|	sc_log(card->ctx, "Checking sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
  380|       |
  381|  15.7k|	for (i = 0; i < nqapplet_error_count; i++) {
  ------------------
  |  Branch (381:14): [True: 14.8k, False: 894]
  ------------------
  382|  14.8k|		if (nqapplet_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (382:7): [True: 632, False: 14.2k]
  ------------------
  383|    632|			LOG_TEST_RET(card->ctx, nqapplet_errors[i].errorno, nqapplet_errors[i].errorstr);
  ------------------
  |  |  174|    632|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    632|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    632|	int _ret = (r); \
  |  |  |  |  168|    632|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 632, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    632|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    632|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    632|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    632|		return _ret; \
  |  |  |  |  172|    632|	} \
  |  |  |  |  173|    632|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|    632|		}
  385|  14.8k|	}
  386|       |
  387|    894|	return iso_operations->check_sw(card, sw1, sw2);
  388|  1.52k|}
card-nqApplet.c:nqapplet_get_data:
  391|    344|{
  392|    344|	struct sc_apdu apdu;
  393|    344|	int rv;
  394|       |
  395|    344|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    344|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    344|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    344|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    344|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 344]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|    344|	sc_format_apdu_ex(&apdu, 0x80, 0xB0, 0x00, (u8)id, NULL, 0, resp, cb_resp);
  398|    344|	apdu.le = 256;
  399|       |
  400|    344|	rv = sc_transmit_apdu(card, &apdu);
  401|    344|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    344|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    344|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    344|	int _ret = (r); \
  |  |  |  |  168|    344|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 331]
  |  |  |  |  ------------------
  |  |  |  |  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|    344|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 331]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|       |
  403|    331|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (403:6): [True: 232, False: 99]
  |  Branch (403:26): [True: 231, False: 1]
  ------------------
  404|    231|		rv = (int)apdu.resplen;
  405|    231|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (405:13): [True: 0, False: 100]
  ------------------
  406|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (406:8): [True: 0, False: 0]
  ------------------
  407|    100|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (407:13): [True: 23, False: 77]
  |  Branch (407:33): [True: 1, False: 22]
  ------------------
  408|      1|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  409|      1|	}
  410|       |
  411|    331|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    331|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    331|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    331|	int _ret = r; \
  |  |  |  |  155|    331|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    228|	} else { \
  |  |  |  |  159|    228|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    228|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    228|	} \
  |  |  |  |  162|    331|	return _ret; \
  |  |  |  |  163|    331|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|    331|}
card-nqApplet.c:nqapplet_select_file:
  416|    448|{
  417|    448|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    448|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    448|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    448|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    448|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 448]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  418|       |
  419|       |	/* the applet does not support SELECT EF/DF except for SELECT APPLET.
  420|       |	In order to enable opensc-explorer add support for virtually selecting MF only */
  421|    448|	if (in_path->type == SC_PATH_TYPE_PATH && in_path->len == 2 &&
  ------------------
  |  |  119|    896|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (421:6): [True: 78, False: 370]
  |  Branch (421:44): [True: 0, False: 78]
  ------------------
  422|      0|	    memcmp(in_path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (422:6): [True: 0, False: 0]
  ------------------
  423|      0|		if (file_out != NULL) {
  ------------------
  |  Branch (423:7): [True: 0, False: 0]
  ------------------
  424|      0|			struct sc_file *file = sc_file_new();
  425|      0|			if (file == NULL) {
  ------------------
  |  Branch (425:8): [True: 0, False: 0]
  ------------------
  426|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|      0|			}
  428|      0|			file->path = *in_path;
  429|      0|			*file_out = file;
  430|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|      0|		}
  432|      0|	}
  433|       |	// TODO allow selecting Applet AID
  434|       |
  435|    448|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    448|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    448|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    448|	int _ret = r; \
  |  |  |  |  155|    448|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 448, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    448|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    448|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 448, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    448|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    448|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    448|	return _ret; \
  |  |  |  |  163|    448|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|    448|}
card-nqApplet.c:nqapplet_pin_cmd:
  455|    291|{
  456|    291|	int r;
  457|       |
  458|    291|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    291|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    291|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    291|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    291|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 291]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|    291|	r = iso_operations->pin_cmd(card, data);
  460|    291|	if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|    291|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (460:6): [True: 30, False: 261]
  ------------------
  461|       |		/* it is possible that the NQ-Applet is not active, try to activate it */
  462|     30|		r = select_nqapplet(card, NULL, NULL, NULL, 0, NULL);
  463|     30|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (463:7): [True: 5, False: 25]
  ------------------
  464|      5|			r = iso_operations->pin_cmd(card, data);
  465|      5|		}
  466|     30|	}
  467|    291|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    291|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    291|	int _ret = r; \
  |  |  155|    291|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 291, False: 0]
  |  |  ------------------
  |  |  156|    291|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    211|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 211, False: 80]
  |  |  ------------------
  |  |  157|    291|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    291|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    291|	return _ret; \
  |  |  163|    291|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  468|    291|}

sc_get_oberthur_driver:
 2319|  16.9k|{
 2320|  16.9k|	return sc_get_driver();
 2321|  16.9k|}
card-oberthur.c:sc_get_driver:
 2288|  16.9k|{
 2289|  16.9k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2289:6): [True: 1, False: 16.9k]
  ------------------
 2290|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2291|       |
 2292|  16.9k|	auth_ops = *iso_ops;
 2293|  16.9k|	auth_ops.match_card = auth_match_card;
 2294|  16.9k|	auth_ops.init = auth_init;
 2295|  16.9k|	auth_ops.finish = auth_finish;
 2296|  16.9k|	auth_ops.select_file = auth_select_file;
 2297|  16.9k|	auth_ops.list_files = auth_list_files;
 2298|  16.9k|	auth_ops.delete_file = auth_delete_file;
 2299|  16.9k|	auth_ops.create_file = auth_create_file;
 2300|  16.9k|	auth_ops.read_binary = auth_read_binary;
 2301|  16.9k|	auth_ops.update_binary = auth_update_binary;
 2302|  16.9k|	auth_ops.read_record = auth_read_record;
 2303|  16.9k|	auth_ops.delete_record = auth_delete_record;
 2304|  16.9k|	auth_ops.card_ctl = auth_card_ctl;
 2305|  16.9k|	auth_ops.set_security_env = auth_set_security_env;
 2306|  16.9k|	auth_ops.restore_security_env = auth_restore_security_env;
 2307|  16.9k|	auth_ops.compute_signature = auth_compute_signature;
 2308|  16.9k|	auth_ops.decipher = auth_decipher;
 2309|  16.9k|	auth_ops.process_fci = auth_process_fci;
 2310|  16.9k|	auth_ops.pin_cmd = auth_pin_cmd;
 2311|  16.9k|	auth_ops.logout = auth_logout;
 2312|  16.9k|	auth_ops.check_sw = auth_check_sw;
 2313|  16.9k|	return &auth_drv;
 2314|  16.9k|}
card-oberthur.c:auth_match_card:
  204|  12.4k|{
  205|  12.4k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 11.4k, False: 981]
  ------------------
  206|  11.4k|		return 0;
  207|    981|	else
  208|    981|		return 1;
  209|  12.4k|}
card-oberthur.c:auth_init:
  214|    981|{
  215|    981|	struct auth_private_data *data;
  216|    981|	struct sc_path path;
  217|    981|	unsigned long flags;
  218|    981|	int rv = 0;
  219|       |
  220|    981|	data = calloc(1, sizeof(struct auth_private_data));
  221|    981|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 981]
  ------------------
  222|    981|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  223|       |
  224|    981|	card->cla = 0x00;
  225|    981|	card->drv_data = data;
  226|       |
  227|    981|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    981|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    981|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    981|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    981|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 61, False: 920]
  ------------------
  231|     61|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     61|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     61|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     61|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to initialize");
  ------------------
  |  |  184|     61|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     61|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     61|	int _ret = (r); \
  |  |  |  |  178|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     61|		goto err; \
  |  |  |  |  182|     61|	} \
  |  |  |  |  183|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     61|	}
  235|       |
  236|    920|	sc_format_path("3F00", &path);
  237|    920|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    981|err:
  240|    981|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    981|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 920, False: 61]
  ------------------
  241|    920|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    920|#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|    920|#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|    920|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  106|    920|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    920|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    920|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    920|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    920|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    920|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    920|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    920|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    920|	} else {
  249|     61|		free(card->drv_data);
  250|     61|		card->drv_data = NULL;
  251|     61|	}
  252|       |
  253|    981|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    981|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    981|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    981|	int _ret = r; \
  |  |  |  |  155|    981|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 981, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    981|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 61, False: 920]
  |  |  |  |  ------------------
  |  |  |  |  157|    981|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    981|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    981|	return _ret; \
  |  |  |  |  163|    981|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    981|}
card-oberthur.c:auth_select_aid:
  145|    981|{
  146|    981|	struct sc_apdu apdu;
  147|    981|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    981|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    981|	int rv, ii;
  150|    981|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    981|	rv = gp_select_card_manager(card);
  154|    981|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    981|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    981|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    981|	int _ret = (r); \
  |  |  |  |  168|    981|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 939]
  |  |  |  |  ------------------
  |  |  |  |  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|    981|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 939]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    939|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    939|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    939|	apdu.cla = 0x80;
  159|    939|	apdu.le = 0x2D;
  160|    939|	apdu.resplen = 0x30;
  161|    939|	apdu.resp = apdu_resp;
  162|       |
  163|    939|	rv = sc_transmit_apdu(card, &apdu);
  164|    939|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    939|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    939|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    939|	int _ret = (r); \
  |  |  |  |  168|    939|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 938]
  |  |  |  |  ------------------
  |  |  |  |  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|    939|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 938]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    938|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 9, False: 929]
  ------------------
  166|      9|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect length");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      9|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      9|		return _ret; \
  |  |  |  |  172|      9|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      9|	}
  168|    929|	card->serialnr.len = 4;
  169|    929|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  4.64k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 3.71k, False: 929]
  ------------------
  172|  3.71k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    929|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   71|    929|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|       |
  176|    929|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    929|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    929|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    929|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    929|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    929|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    929|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    929|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    929|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    929|	int _ret = (r); \
  |  |  |  |  168|    929|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 922]
  |  |  |  |  ------------------
  |  |  |  |  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|    929|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 922]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    922|	sc_format_path("3F00", &tmp_path);
  185|    922|	sc_file_free(auth_current_df);
  186|    922|	auth_current_df = NULL;
  187|    922|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    922|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    922|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    922|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    922|	int _ret = (r); \
  |  |  |  |  168|    922|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 920]
  |  |  |  |  ------------------
  |  |  |  |  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|    922|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 920]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    920|	sc_file_free(auth_current_ef);
  191|    920|	auth_current_ef = NULL;
  192|    920|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    920|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    920|	data->aid_len = lenAidAuthentIC_V5;
  196|    920|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    920|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    920|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    920|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    920|	int _ret = r; \
  |  |  |  |  155|    920|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 920, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    920|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 920]
  |  |  |  |  ------------------
  |  |  |  |  157|    920|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    920|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    920|	return _ret; \
  |  |  |  |  163|    920|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    920|}
card-oberthur.c:auth_finish:
  137|    920|{
  138|    920|	free(card->drv_data);
  139|    920|	return SC_SUCCESS;
  ------------------
  |  |   28|    920|#define SC_SUCCESS				0
  ------------------
  140|    920|}
card-oberthur.c:auth_select_file:
  443|  19.4k|{
  444|  19.4k|	struct sc_path path;
  445|  19.4k|	struct sc_file *tmp_file = NULL;
  446|  19.4k|	size_t offs, ii;
  447|  19.4k|	int rv;
  448|       |
  449|  19.4k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (449:6): [True: 0, False: 19.4k]
  |  Branch (449:22): [True: 0, False: 19.4k]
  ------------------
  450|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  451|       |
  452|  19.4k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  19.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  19.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  19.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  19.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|       |
  454|  19.4k|	memcpy(&path, in_path, sizeof(struct sc_path));
  455|       |
  456|  19.4k|	if (!auth_current_df)
  ------------------
  |  Branch (456:6): [True: 0, False: 19.4k]
  ------------------
  457|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  458|       |
  459|  19.4k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  19.4k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  460|  19.4k|			in_path->type, sc_print_path(in_path), file_out);
  461|  19.4k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  19.4k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  19.4k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  463|  19.4k|	if (auth_current_ef)
  ------------------
  |  Branch (463:6): [True: 12.1k, False: 7.30k]
  ------------------
  464|  12.1k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   71|  12.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  465|  19.4k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  466|       |
  467|  19.4k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  38.9k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  19.3k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (467:6): [True: 170, False: 19.3k]
  |  Branch (467:42): [True: 9.75k, False: 9.57k]
  ------------------
  468|  9.92k|		sc_file_free(auth_current_ef);
  469|  9.92k|		auth_current_ef = NULL;
  470|       |
  471|  9.92k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  472|  9.92k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  9.92k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.92k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.92k|	int _ret = (r); \
  |  |  |  |  168|  9.92k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.25k, False: 6.66k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.25k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.25k|		return _ret; \
  |  |  |  |  172|  3.25k|	} \
  |  |  |  |  173|  9.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.66k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|  6.66k|		if (!tmp_file)
  ------------------
  |  Branch (473:7): [True: 0, False: 6.66k]
  ------------------
  474|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  475|       |
  476|  6.66k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  6.66k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (476:7): [True: 57, False: 6.61k]
  ------------------
  477|     57|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  478|     57|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (478:8): [True: 57, False: 0]
  ------------------
  479|     57|				tmp_file->path.len -= 2;
  480|       |
  481|     57|			sc_file_free(auth_current_df);
  482|     57|			auth_current_df = NULL;
  483|     57|			sc_file_dup(&auth_current_df, tmp_file);
  484|  6.61k|		} else {
  485|  6.61k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  6.61k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (485:8): [True: 237, False: 6.37k]
  ------------------
  486|    237|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  487|       |
  488|    237|				sc_file_free(auth_current_df);
  489|    237|				auth_current_df = NULL;
  490|    237|				sc_file_dup(&auth_current_df, tmp_file);
  491|  6.37k|			} else {
  492|  6.37k|				sc_file_free(auth_current_ef);
  493|  6.37k|				auth_current_ef = NULL;
  494|       |
  495|  6.37k|				sc_file_dup(&auth_current_ef, tmp_file);
  496|  6.37k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  497|  6.37k|			}
  498|  6.61k|		}
  499|  6.66k|		if (file_out) {
  ------------------
  |  Branch (499:7): [True: 5.34k, False: 1.32k]
  ------------------
  500|  5.34k|			sc_file_free(*file_out);
  501|  5.34k|			sc_file_dup(file_out, tmp_file);
  502|  5.34k|		}
  503|       |
  504|  6.66k|		sc_file_free(tmp_file);
  505|  9.57k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  9.57k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (505:13): [True: 1.47k, False: 8.09k]
  ------------------
  506|  1.47k|		rv = iso_ops->select_file(card, &path, NULL);
  507|  1.47k|		if (rv) {
  ------------------
  |  Branch (507:7): [True: 1.40k, False: 64]
  ------------------
  508|  1.40k|			sc_file_free(auth_current_ef);
  509|  1.40k|			auth_current_ef = NULL;
  510|  1.40k|		}
  511|  1.47k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  1.47k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.47k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.47k|	int _ret = (r); \
  |  |  |  |  168|  1.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.40k, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.40k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.40k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.40k|		return _ret; \
  |  |  |  |  172|  1.40k|	} \
  |  |  |  |  173|  1.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|  8.09k|	} else {
  513|  17.3k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (513:18): [True: 16.0k, False: 1.29k]
  |  Branch (513:37): [True: 9.49k, False: 6.57k]
  ------------------
  514|  9.49k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (514:8): [True: 182, False: 9.31k]
  ------------------
  515|  9.31k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (515:6): [True: 39, False: 9.27k]
  ------------------
  516|    221|				break;
  517|       |
  518|  8.09k|		sc_log(card->ctx, "offs %zu", offs);
  ------------------
  |  |   71|  8.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__
  |  |  ------------------
  ------------------
  519|  8.09k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (519:7): [True: 8.03k, False: 63]
  |  Branch (519:15): [True: 158, False: 7.87k]
  ------------------
  520|    158|			size_t deep = auth_current_df->path.len - offs;
  521|       |
  522|    158|			sc_log(card->ctx, "deep %zu", deep);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  523|    215|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (523:17): [True: 170, False: 45]
  ------------------
  524|    170|				struct sc_path tmp_path;
  525|       |
  526|    170|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  527|    170|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|    170|#define SC_PATH_TYPE_PARENT		5
  ------------------
  528|       |
  529|    170|				if (file_out) {
  ------------------
  |  Branch (529:9): [True: 18, False: 152]
  ------------------
  530|     18|					sc_file_free(*file_out);
  531|     18|					*file_out = NULL;
  532|     18|				}
  533|       |
  534|    170|				rv = auth_select_file (card, &tmp_path, file_out);
  535|    170|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|    170|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    170|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    170|	int _ret = (r); \
  |  |  |  |  168|    170|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 113, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  169|    113|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    113|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    113|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    113|		return _ret; \
  |  |  |  |  172|    113|	} \
  |  |  |  |  173|    170|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    170|			}
  537|    158|		}
  538|       |
  539|  7.98k|		if (path.len > offs) {
  ------------------
  |  Branch (539:7): [True: 6.68k, False: 1.29k]
  ------------------
  540|  6.68k|			struct sc_path tmp_path;
  541|       |
  542|  6.68k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  543|  6.68k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  6.68k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  544|  6.68k|			tmp_path.len = 2;
  545|       |
  546|  13.2k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (546:17): [True: 9.75k, False: 3.54k]
  ------------------
  547|  9.75k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  548|       |
  549|  9.75k|				if (file_out) {
  ------------------
  |  Branch (549:9): [True: 6.97k, False: 2.78k]
  ------------------
  550|  6.97k|					sc_file_free(*file_out);
  551|  6.97k|					*file_out = NULL;
  552|  6.97k|				}
  553|       |
  554|  9.75k|				rv = auth_select_file(card, &tmp_path, file_out);
  555|  9.75k|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  9.75k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.75k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.75k|	int _ret = (r); \
  |  |  |  |  168|  9.75k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.14k, False: 6.61k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.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|  3.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.14k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.14k|		return _ret; \
  |  |  |  |  172|  3.14k|	} \
  |  |  |  |  173|  9.75k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.61k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  9.75k|			}
  557|  6.68k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (557:14): [True: 1.29k, False: 0]
  |  Branch (557:38): [True: 0, False: 1.29k]
  ------------------
  558|      0|			if (sc_compare_path(&path, &auth_current_df->path) && file_out) {
  ------------------
  |  Branch (558:8): [True: 0, False: 0]
  |  Branch (558:58): [True: 0, False: 0]
  ------------------
  559|      0|				sc_file_free(*file_out);
  560|      0|				sc_file_dup(file_out, auth_current_df);
  561|      0|			} else  if (auth_current_ef && file_out) {
  ------------------
  |  Branch (561:16): [True: 0, False: 0]
  |  Branch (561:35): [True: 0, False: 0]
  ------------------
  562|      0|				sc_file_free(*file_out);
  563|      0|				sc_file_dup(file_out, auth_current_ef);
  564|      0|			} else {
  565|      0|				LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "No current EF");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|      0|			}
  567|      0|		}
  568|  7.98k|	}
  569|       |
  570|  11.5k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  11.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.5k|	int _ret = r; \
  |  |  |  |  155|  11.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 11.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.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|  11.5k|	return _ret; \
  |  |  |  |  163|  11.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|  11.5k|}
card-oberthur.c:auth_read_binary:
 2102|  4.04k|{
 2103|  4.04k|	int rv;
 2104|  4.04k|	size_t sz;
 2105|  4.04k|	struct sc_pkcs15_bignum bn[2];
 2106|  4.04k|	unsigned char *out = NULL;
 2107|  4.04k|	bn[0].data = NULL;
 2108|  4.04k|	bn[1].data = NULL;
 2109|       |
 2110|  4.04k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.04k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.04k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2111|       |
 2112|  4.04k|	if (!auth_current_ef)
  ------------------
  |  Branch (2112:6): [True: 21, False: 4.02k]
  ------------------
 2113|  4.04k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid auth_current_ef");
  ------------------
  |  |  174|     21|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     21|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     21|	int _ret = (r); \
  |  |  |  |  168|     21|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2114|       |
 2115|  4.02k|	sc_log(card->ctx, "offset %i; size %zu; flags 0x%lX", offset, count, flags ? *flags : 0);
  ------------------
  |  |   71|  8.05k|#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: 4.02k]
  |  |  ------------------
  ------------------
 2116|  4.02k|	sc_log(card->ctx, "last selected : magic %X; ef %X",
  ------------------
  |  |   71|  4.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2117|  4.02k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2118|       |
 2119|  4.02k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2119:6): [True: 0, False: 4.02k]
  ------------------
 2120|  4.02k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid file offset");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|       |
 2122|  4.02k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   56|  8.05k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2122:6): [True: 4.02k, False: 0]
  ------------------
 2123|  4.02k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2123:4): [True: 136, False: 3.89k]
  ------------------
 2124|    136|		int jj;
 2125|    136|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2126|    136|		size_t resp_len, out_len;
 2127|    136|		struct sc_pkcs15_pubkey_rsa key;
 2128|       |
 2129|    136|		resp_len = sizeof(resp);
 2130|    136|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2131|    136|				2, resp, resp_len);
 2132|    136|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    136|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    136|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    136|	int _ret = (r); \
  |  |  |  |  168|    136|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 34, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  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|    136|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2133|       |
 2134|    448|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2134:14): [True: 440, False: 8]
  |  Branch (2134:23): [True: 346, False: 94]
  ------------------
 2135|    346|			;
 2136|       |
 2137|    102|		if (rv - jj == 0)
  ------------------
  |  Branch (2137:7): [True: 8, False: 94]
  ------------------
 2138|      8|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      8|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2139|     94|		bn[0].data = calloc(1, rv - jj);
 2140|     94|		if (!bn[0].data) {
  ------------------
  |  Branch (2140:7): [True: 0, False: 94]
  ------------------
 2141|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2142|      0|			goto err;
 2143|      0|		}
 2144|     94|		bn[0].len = rv - jj;
 2145|     94|		memcpy(bn[0].data, resp + jj, rv - jj);
 2146|       |
 2147|     94|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2148|     94|				1, resp, resp_len);
 2149|     94|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|     94|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     94|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     94|	int _ret = (r); \
  |  |  |  |  178|     94|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 17, False: 77]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     17|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     17|		goto err; \
  |  |  |  |  182|     17|	} \
  |  |  |  |  183|     94|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 77]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|       |
 2151|     77|		bn[1].data = calloc(1, rv);
 2152|     77|		if (!bn[1].data) {
  ------------------
  |  Branch (2152:7): [True: 0, False: 77]
  ------------------
 2153|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2154|      0|			goto err;
 2155|      0|		}
 2156|     77|		bn[1].len = rv;
 2157|     77|		memcpy(bn[1].data, resp, rv);
 2158|       |
 2159|     77|		key.exponent = bn[0];
 2160|     77|		key.modulus = bn[1];
 2161|       |
 2162|     77|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|     77|#define SC_SUCCESS				0
  ------------------
  |  Branch (2162:7): [True: 5, False: 72]
  ------------------
 2163|      5|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2164|      5|			LOG_TEST_GOTO_ERR(card->ctx, rv, "cannot encode RSA public key");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2165|      5|		}
 2166|     72|		else {
 2167|     72|			if (out_len < offset) {
  ------------------
  |  Branch (2167:8): [True: 4, False: 68]
  ------------------
 2168|      4|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      4|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2169|      4|				goto err;
 2170|      4|			}
 2171|     68|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   69|     68|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 48, False: 20]
  |  |  ------------------
  ------------------
 2172|     68|			memcpy(buf, out + offset, sz);
 2173|       |
 2174|     68|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|     68|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     68|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2175|     68|			rv = (int)sz;
 2176|     68|		}
 2177|  3.89k|	} else {
 2178|  3.89k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2179|  3.89k|	}
 2180|       |
 2181|  3.98k|err:
 2182|  3.98k|	free(bn[0].data);
 2183|  3.98k|	free(bn[1].data);
 2184|  3.98k|	free(out);
 2185|       |
 2186|  3.98k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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: 183, False: 3.80k]
  |  |  |  |  ------------------
  |  |  |  |  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|    146|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 146, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  157|    183|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.80k|	} else { \
  |  |  |  |  159|  3.80k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.80k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.80k|	} \
  |  |  |  |  162|  3.98k|	return _ret; \
  |  |  |  |  163|  3.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2187|  3.98k|}
card-oberthur.c:auth_read_component:
 1463|    230|{
 1464|    230|	struct sc_apdu apdu;
 1465|    230|	int rv;
 1466|    230|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1467|       |
 1468|    230|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    230|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    230|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    230|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    230|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 230]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1469|    230|	sc_log(card->ctx, "num %i, outlen %zu, type %i", num, outlen, type);
  ------------------
  |  |   71|    230|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1470|       |
 1471|    230|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1471:6): [True: 0, False: 230]
  |  Branch (1471:17): [True: 0, False: 230]
  ------------------
 1472|    230|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|       |
 1474|    230|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    230|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1475|    230|	apdu.cla |= 0x80;
 1476|    230|	apdu.le = outlen;
 1477|    230|	apdu.resp = resp;
 1478|    230|	apdu.resplen = sizeof(resp);
 1479|    230|	rv = sc_transmit_apdu(card, &apdu);
 1480|    230|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    230|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    230|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    230|	int _ret = (r); \
  |  |  |  |  168|    230|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 226]
  |  |  |  |  ------------------
  |  |  |  |  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|    230|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 226]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1481|       |
 1482|    226|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1483|    226|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    226|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    226|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    226|	int _ret = (r); \
  |  |  |  |  168|    226|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 47, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  169|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     47|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     47|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     47|		return _ret; \
  |  |  |  |  172|     47|	} \
  |  |  |  |  173|    226|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1484|       |
 1485|    179|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1485:6): [True: 0, False: 179]
  ------------------
 1486|    179|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|       |
 1488|    179|	memcpy(out, apdu.resp, apdu.resplen);
 1489|    179|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 9, False: 170]
  |  |  |  |  ------------------
  |  |  |  |  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|    170|	} else { \
  |  |  |  |  159|    170|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    170|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    170|	} \
  |  |  |  |  162|    179|	return _ret; \
  |  |  |  |  163|    179|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1490|    179|}
card-oberthur.c:auth_read_record:
 2193|  4.58k|{
 2194|  4.58k|	struct sc_apdu apdu;
 2195|  4.58k|	int rv = 0;
 2196|  4.58k|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2197|       |
 2198|  4.58k|	sc_log(card->ctx, "auth_read_record(): nr_rec %i; count %zu", nr_rec, count);
  ------------------
  |  |   71|  4.58k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2199|       |
 2200|  4.58k|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2200:6): [True: 0, False: 4.58k]
  |  Branch (2200:23): [True: 1.06k, False: 3.52k]
  ------------------
 2201|  4.58k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|  1.06k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.06k|	int _ret = r; \
  |  |  |  |  155|  1.06k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.06k|	} else { \
  |  |  |  |  159|      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.06k|	return _ret; \
  |  |  |  |  163|  1.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2202|       |
 2203|  3.52k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|  3.52k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2204|  3.52k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  3.52k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2205|  3.52k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  3.52k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2205:6): [True: 3.52k, False: 0]
  ------------------
 2206|  3.52k|		apdu.p2 |= 0x04;
 2207|       |
 2208|  3.52k|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   69|  3.52k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 3.52k, False: 0]
  |  |  ------------------
  ------------------
 2209|  3.52k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  3.52k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2210|  3.52k|	apdu.resp = recvbuf;
 2211|       |
 2212|  3.52k|	rv = sc_transmit_apdu(card, &apdu);
 2213|  3.52k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  3.52k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.52k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.52k|	int _ret = (r); \
  |  |  |  |  168|  3.52k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 3.51k]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|  3.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.51k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2214|  3.51k|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2214:6): [True: 1.51k, False: 2.00k]
  ------------------
 2215|  3.51k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  1.51k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.51k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.51k|	int _ret = r; \
  |  |  |  |  155|  1.51k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.51k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.51k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 46, False: 1.47k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.51k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.51k|	} else { \
  |  |  |  |  159|      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.51k|	return _ret; \
  |  |  |  |  163|  1.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2216|  2.00k|	if (count < apdu.resplen)
  ------------------
  |  Branch (2216:6): [True: 2, False: 1.99k]
  ------------------
 2217|  2.00k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2218|  1.99k|	memcpy(buf, recvbuf, apdu.resplen);
 2219|       |
 2220|  1.99k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2221|  1.99k|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|  1.99k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.99k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.99k|	int _ret = (r); \
  |  |  |  |  168|  1.99k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 1.98k]
  |  |  |  |  ------------------
  |  |  |  |  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.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2222|       |
 2223|  1.98k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.98k|	int _ret = r; \
  |  |  |  |  155|  1.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.98k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.98k|	} else { \
  |  |  |  |  159|  1.98k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.98k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.98k|	} \
  |  |  |  |  162|  1.98k|	return _ret; \
  |  |  |  |  163|  1.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2224|  1.98k|}
card-oberthur.c:auth_card_ctl:
 1435|      4|{
 1436|      4|	switch (cmd) {
 1437|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1437:2): [True: 0, False: 4]
  ------------------
 1438|      0|		return auth_get_default_key(card,
 1439|      0|				(struct sc_cardctl_default_key *) ptr);
 1440|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1440:2): [True: 0, False: 4]
  ------------------
 1441|      0|		return auth_generate_key(card, 0,
 1442|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1443|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1443:2): [True: 0, False: 4]
  ------------------
 1444|      0|		return auth_update_key(card,
 1445|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1446|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1446:2): [True: 0, False: 4]
  ------------------
 1447|      0|		return auth_create_reference_data(card,
 1448|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1449|      4|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1449:2): [True: 4, False: 0]
  ------------------
 1450|      4|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1451|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1451:2): [True: 0, False: 4]
  ------------------
 1452|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1452:2): [True: 0, False: 4]
  ------------------
 1453|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1454|      0|	default:
  ------------------
  |  Branch (1454:2): [True: 0, False: 4]
  ------------------
 1455|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1456|      4|	}
 1457|      4|}
card-oberthur.c:auth_init_pin_info:
 1521|  1.39k|{
 1522|  1.39k|	pin->offset = 0;
 1523|  1.39k|	pin->pad_char   = 0xFF;
 1524|  1.39k|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|  1.39k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1525|       |
 1526|  1.39k|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|  1.39k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1526:6): [True: 1.38k, False: 1]
  ------------------
 1527|  1.38k|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.38k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1528|  1.38k|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.38k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1529|  1.38k|	} else {
 1530|      1|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      1|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1531|      1|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      1|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1532|      1|	}
 1533|  1.39k|}
card-oberthur.c:auth_get_serialnr:
 2249|      4|{
 2250|      4|	if (!serial)
  ------------------
  |  Branch (2250:6): [True: 0, False: 4]
  ------------------
 2251|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2252|       |
 2253|      4|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2253:6): [True: 0, False: 4]
  ------------------
 2254|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2255|       |
 2256|      4|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2257|       |
 2258|      4|	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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2259|      4|}
card-oberthur.c:auth_set_security_env:
  978|    527|{
  979|    527|	struct auth_senv *auth_senv = &((struct auth_private_data *) card->drv_data)->senv;
  980|    527|	struct sc_apdu apdu;
  981|    527|	long unsigned pads = env->algorithm_flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|    527|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  982|    527|	long unsigned supported_pads = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    527|#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|    527|#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|    527|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	long unsigned supported_pads = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  106|    527|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  983|    527|	int rv;
  984|    527|	unsigned char rsa_sbuf[3] = {
  985|    527|		0x80, 0x01, 0xFF
  986|    527|	};
  987|    527|	unsigned char des_sbuf[13] = {
  988|    527|		0x80, 0x01, 0x01,
  989|    527|		0x87, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  990|    527|	};
  991|       |
  992|    527|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    527|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    527|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    527|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    527|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 527]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  993|    527|	sc_log(card->ctx,
  ------------------
  |  |   71|    527|#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|    527|	       "op %i; path %s; key_ref 0x%X; algos 0x%lX; flags 0x%lX",
  995|    527|	       env->operation, sc_print_path(&env->file_ref), env->key_ref[0],
  996|    527|	       env->algorithm_flags, env->flags);
  997|       |
  998|    527|	memset(auth_senv, 0, sizeof(struct auth_senv));
  999|       |
 1000|    527|	if (!(env->flags & SC_SEC_ENV_FILE_REF_PRESENT))
  ------------------
  |  |   57|    527|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1000:6): [True: 0, False: 527]
  ------------------
 1001|    527|		LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "Key file is not selected.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1002|       |
 1003|    527|	switch (env->algorithm) {
 1004|      0|	case SC_ALGORITHM_DES:
  ------------------
  |  |   76|      0|#define SC_ALGORITHM_DES		64
  ------------------
  |  Branch (1004:2): [True: 0, False: 527]
  ------------------
 1005|      0|	case SC_ALGORITHM_3DES:
  ------------------
  |  |   77|      0|#define SC_ALGORITHM_3DES		65
  ------------------
  |  Branch (1005:2): [True: 0, False: 527]
  ------------------
 1006|      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__
  |  |  ------------------
  ------------------
 1007|      0|		       "algo SC_ALGORITHM_xDES: ref %lX, flags %lX",
 1008|      0|		       env->algorithm_ref, env->flags);
 1009|       |
 1010|      0|		if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|      0|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1010:7): [True: 0, False: 0]
  ------------------
 1011|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1012|      0|			apdu.lc = 3;
 1013|      0|			apdu.data = des_sbuf;
 1014|      0|			apdu.datalen = 3;
 1015|      0|		} else {
 1016|      0|			sc_log(card->ctx, "Invalid crypto operation: %X", env->operation);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1017|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Invalid crypto operation");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1018|      0|		}
 1019|       |
 1020|      0|		break;
 1021|    527|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    527|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1021:2): [True: 527, False: 0]
  ------------------
 1022|    527|		sc_log(card->ctx, "algo SC_ALGORITHM_RSA");
  ------------------
  |  |   71|    527|#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|    527|		if (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) {
  ------------------
  |  |  142|    527|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1023:7): [True: 0, False: 527]
  ------------------
 1024|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "No support for hashes.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|      0|		}
 1026|       |
 1027|    527|		if (pads & (~supported_pads)) {
  ------------------
  |  Branch (1027:7): [True: 0, False: 527]
  ------------------
 1028|      0|			sc_log(card->ctx, "No support for PAD %lX", pads);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1029|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "No padding support.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1030|      0|		}
 1031|       |
 1032|    527|		if (env->operation == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   48|    527|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1032:7): [True: 309, False: 218]
  ------------------
 1033|    309|			rsa_sbuf[2] = 0x11;
 1034|       |
 1035|    309|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB6);
  ------------------
  |  |  293|    309|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1036|    309|			apdu.lc = sizeof(rsa_sbuf);
 1037|    309|			apdu.datalen = sizeof(rsa_sbuf);
 1038|    309|			apdu.data = rsa_sbuf;
 1039|    309|		} else if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|    218|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1039:14): [True: 218, False: 0]
  ------------------
 1040|    218|			rsa_sbuf[2] = 0x11;
 1041|       |
 1042|    218|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|    218|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1043|    218|			apdu.lc = sizeof(rsa_sbuf);
 1044|    218|			apdu.datalen = sizeof(rsa_sbuf);
 1045|    218|			apdu.data = rsa_sbuf;
 1046|    218|		} else {
 1047|      0|			sc_log(card->ctx, "Invalid crypto operation: %X", env->operation);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1048|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1049|      0|		}
 1050|       |
 1051|    527|		break;
 1052|    527|	default:
  ------------------
  |  Branch (1052:2): [True: 0, False: 527]
  ------------------
 1053|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Invalid crypto algorithm supplied");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1054|    527|	}
 1055|       |
 1056|    527|	rv = sc_transmit_apdu(card, &apdu);
 1057|    527|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    527|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    527|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    527|	int _ret = (r); \
  |  |  |  |  168|    527|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 507]
  |  |  |  |  ------------------
  |  |  |  |  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|    527|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 507]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1058|    507|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1059|    507|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    507|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    507|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    507|	int _ret = (r); \
  |  |  |  |  168|    507|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 167, False: 340]
  |  |  |  |  ------------------
  |  |  |  |  169|    167|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    167|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    167|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    167|		return _ret; \
  |  |  |  |  172|    167|	} \
  |  |  |  |  173|    507|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 340]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1060|       |
 1061|    340|	auth_senv->algorithm = env->algorithm;
 1062|       |
 1063|    340|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    340|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    340|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    340|	int _ret = r; \
  |  |  |  |  155|    340|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 340, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    340|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 340]
  |  |  |  |  ------------------
  |  |  |  |  157|    340|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    340|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    340|	return _ret; \
  |  |  |  |  163|    340|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1064|    340|}
card-oberthur.c:auth_compute_signature:
 1077|    175|{
 1078|    175|	struct sc_apdu apdu;
 1079|    175|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1080|    175|	int rv;
 1081|       |
 1082|    175|	if (!card || !in || !out) {
  ------------------
  |  Branch (1082:6): [True: 0, False: 175]
  |  Branch (1082:15): [True: 0, False: 175]
  |  Branch (1082:22): [True: 0, False: 175]
  ------------------
 1083|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1084|    175|	} else if (ilen > 96) {
  ------------------
  |  Branch (1084:13): [True: 61, False: 114]
  ------------------
 1085|     61|		sc_log(card->ctx, "Illegal input length %zu", ilen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1086|     61|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Illegal input length");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|     61|	}
 1088|       |
 1089|    114|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    114|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    114|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    114|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    114|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 114]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|    114|	sc_log(card->ctx, "inlen %zu, outlen %zu", ilen, olen);
  ------------------
  |  |   71|    114|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1091|       |
 1092|    114|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|    114|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1093|    114|	apdu.datalen = ilen;
 1094|    114|	apdu.data = in;
 1095|    114|	apdu.lc = ilen;
 1096|    114|	apdu.le = MIN(olen, SC_MAX_APDU_RESP_SIZE);
  ------------------
  |  |   69|    114|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 114]
  |  |  ------------------
  ------------------
 1097|    114|	apdu.resp = resp;
 1098|    114|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    114|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1099|       |
 1100|    114|	rv = sc_transmit_apdu(card, &apdu);
 1101|    114|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    114|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    114|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    114|	int _ret = (r); \
  |  |  |  |  168|    114|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  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|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1102|     88|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1103|     88|	LOG_TEST_RET(card->ctx, rv, "Compute signature failed");
  ------------------
  |  |  174|     88|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     88|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     88|	int _ret = (r); \
  |  |  |  |  168|     88|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|       |
 1105|     69|	if (apdu.resplen > olen) {
  ------------------
  |  Branch (1105:6): [True: 0, False: 69]
  ------------------
 1106|      0|		sc_log(card->ctx, "Compute signature failed: invalid response length %zu", apdu.resplen);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1107|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1108|      0|	}
 1109|       |
 1110|     69|	memcpy(out, apdu.resp, apdu.resplen);
 1111|       |
 1112|     69|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 24, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  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|     45|	} else { \
  |  |  |  |  159|     45|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     45|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     45|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1113|     69|}
card-oberthur.c:auth_decipher:
 1119|    165|{
 1120|    165|	struct sc_apdu apdu;
 1121|    165|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1122|    165|	int rv;
 1123|    165|	size_t _inlen = inlen;
 1124|       |
 1125|    165|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    165|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    165|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    165|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    165|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 165]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1126|    165|	sc_log(card->ctx, "crgram_len %zu;  outlen %zu", inlen, outlen);
  ------------------
  |  |   71|    165|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1127|    165|	if (!out || !outlen || inlen > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|    165|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1127:6): [True: 0, False: 165]
  |  Branch (1127:14): [True: 0, False: 165]
  |  Branch (1127:25): [True: 13, False: 152]
  ------------------
 1128|    165|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|       |
 1130|    152|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|    152|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1131|       |
 1132|    152|	sc_log(card->ctx, "algorithm SC_ALGORITHM_RSA");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1133|    152|	if (inlen % 64) {
  ------------------
  |  Branch (1133:6): [True: 69, False: 83]
  ------------------
 1134|     69|		rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     69|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1135|     69|		goto done;
 1136|     69|	}
 1137|       |
 1138|     83|	_inlen = inlen;
 1139|     83|	if (_inlen == SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|     83|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (1139:6): [True: 43, False: 40]
  ------------------
 1140|     43|		apdu.cla |= 0x10;
 1141|     43|		apdu.data = in;
 1142|     43|		apdu.datalen = 8;
 1143|     43|		apdu.resp = resp;
 1144|     43|		apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     43|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1145|     43|		apdu.lc = 8;
 1146|     43|		apdu.le = SC_MAX_APDU_RESP_SIZE;
  ------------------
  |  |   36|     43|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
 1147|       |
 1148|     43|		rv = sc_transmit_apdu(card, &apdu);
 1149|     43|		sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1150|     43|		LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 12, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|     31|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1152|     31|		LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|     31|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     31|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     31|	int _ret = (r); \
  |  |  |  |  168|     31|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1153|       |
 1154|     19|		_inlen -= 8;
 1155|     19|		in += 8;
 1156|       |
 1157|     19|		apdu.cla &= ~0x10;
 1158|     19|	}
 1159|       |
 1160|     59|	apdu.data = in;
 1161|     59|	apdu.datalen = _inlen;
 1162|     59|	apdu.resp = resp;
 1163|     59|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     59|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1164|     59|	apdu.lc = _inlen;
 1165|     59|	apdu.le = _inlen;
 1166|       |
 1167|     59|	rv = sc_transmit_apdu(card, &apdu);
 1168|     59|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1169|     59|	LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 16, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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|     59|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|     43|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1171|     43|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1172|     43|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  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: 15, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1173|       |
 1174|     28|	if (outlen > apdu.resplen)
  ------------------
  |  Branch (1174:6): [True: 28, False: 0]
  ------------------
 1175|     28|		outlen = apdu.resplen;
 1176|       |
 1177|     28|	memcpy(out, apdu.resp, outlen);
 1178|     28|	rv = (int)outlen;
 1179|       |
 1180|     97|done:
 1181|     97|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|     97|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     97|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     97|	int _ret = r; \
  |  |  |  |  155|     97|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 76, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  156|     76|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 69, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|     76|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     76|	} else { \
  |  |  |  |  159|     21|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     21|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     21|	} \
  |  |  |  |  162|     97|	return _ret; \
  |  |  |  |  163|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1182|     97|}
card-oberthur.c:auth_process_fci:
  297|  6.82k|{
  298|  6.82k|	unsigned char type;
  299|  6.82k|	const unsigned char *attr;
  300|  6.82k|	size_t attr_len = 0;
  301|       |
  302|  6.82k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.82k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.82k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.82k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.82k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.82k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  6.82k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  6.82k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 3.62k, False: 3.20k]
  |  Branch (304:15): [True: 15, False: 3.18k]
  ------------------
  305|  6.82k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  3.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.63k|	int _ret = r; \
  |  |  |  |  155|  3.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.63k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.63k|	return _ret; \
  |  |  |  |  163|  3.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  3.18k|	type = attr[0];
  307|       |
  308|  3.18k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  3.18k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 151, False: 3.03k]
  |  Branch (309:15): [True: 10, False: 3.02k]
  ------------------
  310|  3.18k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    161|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    161|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    161|	int _ret = r; \
  |  |  |  |  155|    161|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 161, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    161|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    161|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 161, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    161|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    161|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    161|	return _ret; \
  |  |  |  |  163|    161|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  3.02k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  3.02k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 264, False: 2.76k]
  ------------------
  314|  3.02k|	switch (type) {
  315|    264|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 264, False: 2.76k]
  ------------------
  316|    264|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 46, False: 218]
  |  Branch (316:16): [True: 19, False: 199]
  ------------------
  317|    264|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     65|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     65|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     65|	int _ret = r; \
  |  |  |  |  155|     65|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 65, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     65|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     65|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 65, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     65|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     65|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     65|	return _ret; \
  |  |  |  |  163|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    199|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    199|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    199|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    199|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    199|		file->size = attr[0]*0x100 + attr[1];
  321|    199|		break;
  322|  2.05k|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 2.05k, False: 974]
  ------------------
  323|  2.05k|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 334, False: 1.72k]
  |  Branch (323:16): [True: 10, False: 1.71k]
  ------------------
  324|  2.05k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    344|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    344|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    344|	int _ret = r; \
  |  |  |  |  155|    344|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 344, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    344|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    344|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 344, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    344|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    344|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    344|	return _ret; \
  |  |  |  |  163|    344|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|  1.71k|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.71k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|  1.71k|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|  1.71k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|  1.71k|		file->size = attr[0];
  328|  1.71k|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|  1.71k|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 1.71k]
  |  Branch (329:16): [True: 18, False: 1.69k]
  ------------------
  330|  1.71k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|  1.69k|		file->record_length = attr[2]*0x100+attr[3];
  332|  1.69k|		file->record_count = attr[4];
  333|  1.69k|		break;
  334|     67|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 67, False: 2.96k]
  ------------------
  335|     67|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 18, False: 49]
  |  Branch (335:16): [True: 10, False: 39]
  ------------------
  336|     67|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|     39|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     39|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     39|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     39|		file->size = attr[0]*0x100 + attr[1];
  340|     39|		file->size /= 8;
  341|     39|		break;
  342|    172|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 172, False: 2.85k]
  ------------------
  343|    172|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 12, False: 160]
  |  Branch (343:16): [True: 20, False: 140]
  ------------------
  344|    172|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|    140|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    140|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    140|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    140|		file->size = attr[0]*0x100 + attr[1];
  349|    140|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 19, False: 121]
  ------------------
  350|     19|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     19|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    121|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 21, False: 100]
  ------------------
  352|     21|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     21|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|    100|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 1, False: 99]
  ------------------
  354|      1|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      1|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|     99|		else {
  356|     99|			sc_log(card->ctx, "Not supported public key size: %zu", file->size);
  ------------------
  |  |   71|     99|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|     99|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     99|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     99|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     99|	int _ret = r; \
  |  |  |  |  155|     99|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 99, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     99|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     99|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     99|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     99|	return _ret; \
  |  |  |  |  163|     99|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|     99|		}
  359|     41|		break;
  360|     41|	case 0x14:
  ------------------
  |  Branch (360:2): [True: 34, False: 2.99k]
  ------------------
  361|     34|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (361:7): [True: 12, False: 22]
  |  Branch (361:16): [True: 10, False: 12]
  ------------------
  362|     34|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     22|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     22|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     22|	int _ret = r; \
  |  |  |  |  155|     22|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     22|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     22|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     22|	return _ret; \
  |  |  |  |  163|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     12|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     12|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  364|     12|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  365|     12|		file->size = attr[0]*0x100 + attr[1];
  366|     12|		break;
  367|    355|	case 0x38:
  ------------------
  |  Branch (367:2): [True: 355, False: 2.67k]
  ------------------
  368|    355|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (368:7): [True: 20, False: 335]
  |  Branch (368:16): [True: 10, False: 325]
  ------------------
  369|    355|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|    325|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    325|#define SC_FILE_TYPE_DF			0x04
  ------------------
  371|    325|		file->size = attr[0];
  372|    325|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    325|#define SC_SUCCESS				0
  ------------------
  |  Branch (372:7): [True: 0, False: 325]
  ------------------
  373|    325|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|    325|		break;
  375|    325|	default:
  ------------------
  |  Branch (375:2): [True: 82, False: 2.94k]
  ------------------
  376|     82|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|     82|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 82, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|  3.02k|	}
  378|       |
  379|  2.30k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  380|  2.30k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (380:6): [True: 1.87k, False: 437]
  |  Branch (380:15): [True: 24, False: 413]
  ------------------
  381|  2.30k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.89k|	int _ret = r; \
  |  |  |  |  155|  1.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.89k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.89k|	return _ret; \
  |  |  |  |  163|  1.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    413|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    413|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (383:6): [True: 278, False: 135]
  ------------------
  384|    278|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    278|#define SC_AC_OP_CREATE			3
  ------------------
  385|    278|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    278|#define SC_AC_OP_CRYPTO			7
  ------------------
  386|    278|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    278|#define SC_AC_OP_LIST_FILES		6
  ------------------
  387|    278|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    278|#define SC_AC_OP_DELETE			2
  ------------------
  388|    278|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    278|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  389|    278|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    278|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  390|    278|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    278|#define SC_AC_OP_PIN_RESET		19
  ------------------
  391|    278|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  392|    278|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    135|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (392:13): [True: 76, False: 59]
  ------------------
  393|     76|		switch (file->ef_structure) {
  ------------------
  |  Branch (393:11): [True: 76, False: 0]
  ------------------
  394|     39|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (394:3): [True: 39, False: 37]
  ------------------
  395|     39|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     39|#define SC_AC_OP_UPDATE			23
  ------------------
  396|     39|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     39|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  397|     39|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     39|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  398|     39|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     39|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  399|     39|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     39|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  400|     39|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     39|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  401|     39|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     39|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  402|     39|			break;
  403|     27|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (403:3): [True: 27, False: 49]
  ------------------
  404|     27|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     27|#define SC_AC_OP_UPDATE			23
  ------------------
  405|     27|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     27|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  406|     27|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_SIGNATURE, attr[4]);
  ------------------
  |  |  178|     27|#define SC_AC_OP_PSO_VERIFY_SIGNATURE	12
  ------------------
  407|     27|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     27|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  408|     27|			break;
  409|     10|		case SC_CARDCTL_OBERTHUR_KEY_RSA_CRT:
  ------------------
  |  Branch (409:3): [True: 10, False: 66]
  ------------------
  410|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  411|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     10|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  412|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_SIGNATURE, attr[3]);
  ------------------
  |  |  177|     10|#define SC_AC_OP_PSO_COMPUTE_SIGNATURE	11
  ------------------
  413|     10|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     10|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  414|     10|			break;
  415|     76|		}
  416|     76|	} else {
  417|     59|		switch (file->ef_structure) {
  ------------------
  |  Branch (417:11): [True: 59, False: 0]
  ------------------
  418|     44|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     44|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (418:3): [True: 44, False: 15]
  ------------------
  419|     44|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     44|#define SC_AC_OP_WRITE			24
  ------------------
  420|     44|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     44|#define SC_AC_OP_UPDATE			23
  ------------------
  421|     44|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     44|#define SC_AC_OP_READ			22
  ------------------
  422|     44|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     44|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     44|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  423|     44|			break;
  424|     15|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     15|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (424:3): [True: 15, False: 44]
  ------------------
  425|     15|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     15|#define SC_AC_OP_WRITE			24
  ------------------
  426|     15|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     15|#define SC_AC_OP_UPDATE			23
  ------------------
  427|     15|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     15|#define SC_AC_OP_READ			22
  ------------------
  428|     15|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     15|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     15|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  429|     15|			break;
  430|     59|		}
  431|     59|	}
  432|       |
  433|    413|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    413|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  434|    413|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    413|#define SC_FILE_MAGIC			0x14426950
  ------------------
  435|       |
  436|    413|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    413|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    413|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    413|	int _ret = r; \
  |  |  |  |  155|    413|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 413, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    413|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 413]
  |  |  |  |  ------------------
  |  |  |  |  157|    413|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    413|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    413|	return _ret; \
  |  |  |  |  163|    413|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    413|}
card-oberthur.c:add_acl_entry:
  260|  2.60k|{
  261|  2.60k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 708, False: 1.89k]
  ------------------
  262|    708|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    708|#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|    708|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    708|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    708|		return;
  265|    708|	}
  266|       |
  267|  1.89k|	switch (acl_byte) {
  268|    430|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 430, False: 1.46k]
  ------------------
  269|    430|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    430|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    430|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    430|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     64|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 64, False: 1.83k]
  ------------------
  273|    107|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 43, False: 1.85k]
  ------------------
  274|    107|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|    107|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |   41|    107|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|    107|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    195|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 195, False: 1.70k]
  ------------------
  278|    312|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 117, False: 1.77k]
  ------------------
  279|    312|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    312|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 57, False: 255]
  ------------------
  280|     57|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     57|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    255|		else
  282|    255|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    255|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    312|		break;
  284|    258|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 258, False: 1.63k]
  ------------------
  285|    258|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    258|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    258|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    258|		break;
  287|    788|	default:
  ------------------
  |  Branch (287:2): [True: 788, False: 1.10k]
  ------------------
  288|    788|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    788|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    788|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    788|		break;
  290|  1.89k|	}
  291|  1.89k|}
card-oberthur.c:auth_pin_cmd:
 1875|  1.54k|{
 1876|  1.54k|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.54k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1877|       |
 1878|  1.54k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.54k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.54k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.54k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.54k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.54k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1879|  1.54k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.54k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1879:6): [True: 0, False: 1.54k]
  ------------------
 1880|  1.54k|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "auth_pin_cmd() unsupported PIN type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1881|       |
 1882|  1.54k|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   71|  1.54k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1883|  1.54k|			data->pin_reference, data->pin1.data, data->pin1.len,
 1884|  1.54k|			data->pin2.data, data->pin2.len);
 1885|  1.54k|	switch (data->cmd) {
 1886|  1.32k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|  1.32k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1886:2): [True: 1.32k, False: 222]
  ------------------
 1887|  1.32k|		rv = auth_pin_verify(card, SC_AC_CHV, data);
  ------------------
  |  |  151|  1.32k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1888|  1.32k|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|  1.32k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.32k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.32k|	int _ret = (r); \
  |  |  |  |  168|  1.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 157, False: 1.16k]
  |  |  |  |  ------------------
  |  |  |  |  169|    157|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    157|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    157|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    157|		return _ret; \
  |  |  |  |  172|    157|	} \
  |  |  |  |  173|  1.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1889|  1.16k|		break;
 1890|  1.16k|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     28|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1890:2): [True: 28, False: 1.51k]
  ------------------
 1891|     28|		rv = auth_pin_change(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     28|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1892|     28|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' 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: 19, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|      9|		break;
 1894|     31|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|     31|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1894:2): [True: 31, False: 1.51k]
  ------------------
 1895|     31|		rv = auth_pin_reset(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     31|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1896|     31|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|     31|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     31|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     31|	int _ret = (r); \
  |  |  |  |  168|     31|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     31|		return _ret; \
  |  |  |  |  172|     31|	} \
  |  |  |  |  173|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|      0|		break;
 1898|    163|	default:
  ------------------
  |  Branch (1898:2): [True: 163, False: 1.38k]
  ------------------
 1899|    163|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN operation");
  ------------------
  |  |  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: 163, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    163|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    163|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    163|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    163|		return _ret; \
  |  |  |  |  172|    163|	} \
  |  |  |  |  173|    163|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|  1.54k|	}
 1901|       |
 1902|  1.17k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  1.17k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.17k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.17k|	int _ret = r; \
  |  |  |  |  155|  1.17k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.17k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.17k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.17k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.17k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.17k|	return _ret; \
  |  |  |  |  163|  1.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1903|  1.17k|}
card-oberthur.c:auth_pin_verify:
 1595|  1.33k|{
 1596|  1.33k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1597|  1.33k|	int rv;
 1598|       |
 1599|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1600|       |
 1601|  1.33k|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|  1.33k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1601:6): [True: 0, False: 1.33k]
  ------------------
 1602|  1.33k|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "PIN type other then SC_AC_CHV is not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1603|       |
 1604|  1.33k|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|  1.33k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1605|       |
 1606|  1.33k|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|  1.33k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1607|       |
 1608|       |	/* User PIN is always local. */
 1609|  1.33k|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  2.66k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1609:6): [True: 588, False: 745]
  ------------------
 1610|    745|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    745|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1610:7): [True: 0, False: 745]
  ------------------
 1611|    588|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    588|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1612|       |
 1613|  1.33k|        rv = auth_pin_is_verified(card, data->pin_reference, &data->pin1.tries_left);
 1614|  1.33k|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1615|       |
 1616|       |	/* Return if only PIN status has been asked. */
 1617|  1.33k|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1617:6): [True: 1.33k, False: 0]
  |  Branch (1617:25): [True: 1.21k, False: 115]
  ------------------
 1618|  1.33k|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  1.21k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.21k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.21k|	int _ret = r; \
  |  |  |  |  155|  1.21k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.21k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.21k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    111|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 111, False: 1.10k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.21k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.21k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.21k|	return _ret; \
  |  |  |  |  163|  1.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|       |	/* Return SUCCESS without verifying if
 1621|       |	 * PIN has been already verified and PIN pad has to be used. */
 1622|    115|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1622:6): [True: 55, False: 60]
  |  Branch (1622:13): [True: 0, False: 55]
  |  Branch (1622:33): [True: 0, False: 0]
  ------------------
 1623|    115|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1624|       |
 1625|    115|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1625:6): [True: 0, False: 115]
  |  Branch (1625:26): [True: 0, False: 0]
  ------------------
 1626|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1627|    115|	else
 1628|    115|		rv = iso_drv->ops->pin_cmd(card, data);
 1629|       |
 1630|    115|	LOG_FUNC_RETURN(card->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|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1631|    115|}
card-oberthur.c:auth_pin_is_verified:
 1636|  1.33k|{
 1637|  1.33k|	struct sc_apdu apdu;
 1638|  1.33k|	int rv;
 1639|       |
 1640|  1.33k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|  1.33k|#define SC_APDU_CASE_1			0x01
  ------------------
 1641|       |
 1642|  1.33k|	rv = sc_transmit_apdu(card, &apdu);
 1643|  1.33k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.33k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.33k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.33k|	int _ret = (r); \
  |  |  |  |  168|  1.33k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1.33k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.33k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.33k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1644|       |
 1645|  1.33k|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1645:6): [True: 1.33k, False: 0]
  |  Branch (1645:20): [True: 58, False: 1.27k]
  |  Branch (1645:40): [True: 51, False: 7]
  ------------------
 1646|     51|		*tries_left = apdu.sw2 & 0x0F;
 1647|       |
 1648|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1649|  1.33k|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1649:6): [True: 58, False: 1.27k]
  |  Branch (1649:26): [True: 3, False: 55]
  ------------------
 1650|      3|		apdu.sw1 = 0x69;
 1651|      3|		apdu.sw2 = 0x83;
 1652|      3|	}
 1653|       |
 1654|  1.33k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1655|       |
 1656|  1.33k|	return rv;
 1657|  1.33k|}
card-oberthur.c:auth_pin_change:
 1719|     28|{
 1720|     28|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1721|     28|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     28|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1722|       |
 1723|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1724|       |
 1725|     28|	if (data->pin1.len && data->pin2.len) {
  ------------------
  |  Branch (1725:6): [True: 28, False: 0]
  |  Branch (1725:24): [True: 28, False: 0]
  ------------------
 1726|       |		/* Direct unblock style */
 1727|     28|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     28|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1728|     28|		data->flags &= ~SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|     28|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 1729|     28|		data->apdu = NULL;
 1730|       |
 1731|     28|		data->pin_reference &= ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     28|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1732|       |
 1733|     28|		auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     28|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1734|     28|		auth_init_pin_info(card, &data->pin2, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     28|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1735|       |
 1736|     28|		rv = iso_drv->ops->pin_cmd(card, data);
 1737|     28|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN CHANGE' 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: 19, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1738|     28|	} else if (!data->pin1.len && !data->pin2.len) {
  ------------------
  |  Branch (1738:13): [True: 0, False: 0]
  |  Branch (1738:32): [True: 0, False: 0]
  ------------------
 1739|       |		/* Oberthur unblock style with PIN pad. */
 1740|      0|		rv = auth_pin_change_pinpad(card, data);
 1741|      0|		LOG_TEST_RET(card->ctx, rv, "'PIN CHANGE' failed: SOPIN verify with pinpad 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1742|      0|	} else {
 1743|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "'PIN CHANGE' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1744|      0|	}
 1745|       |
 1746|      9|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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|      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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1747|      9|}
card-oberthur.c:auth_pin_reset:
 1860|     32|{
 1861|     32|	int rv;
 1862|       |
 1863|     32|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     32|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     32|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     32|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     32|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1864|       |
 1865|       |	/* Oberthur unblock style: PUK value is a SOPIN */
 1866|     32|	rv = auth_pin_reset_oberthur_style(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     32|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1867|     32|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' failed");
  ------------------
  |  |  174|     32|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     32|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     32|	int _ret = (r); \
  |  |  |  |  168|     32|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     32|		return _ret; \
  |  |  |  |  172|     32|	} \
  |  |  |  |  173|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1868|       |
 1869|      0|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1870|      0|}
card-oberthur.c:auth_pin_reset_oberthur_style:
 1753|     32|{
 1754|     32|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1755|     32|	struct sc_pin_cmd_data pin_cmd;
 1756|     32|	struct sc_path tmp_path;
 1757|     32|	struct sc_file *tmp_file = NULL;
 1758|     32|	struct sc_apdu apdu;
 1759|     32|	unsigned char puk[OBERTHUR_AUTH_MAX_LENGTH_PUK];
 1760|     32|	unsigned char ffs1[0x100];
 1761|     32|	int rv, rvv, local_pin_reference;
 1762|       |
 1763|     32|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     32|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     32|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     32|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     32|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1764|       |
 1765|     32|	local_pin_reference = data->pin_reference & ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     32|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1766|       |
 1767|     32|	if (data->pin_reference !=  OBERTHUR_PIN_REFERENCE_USER)
  ------------------
  |  |   42|     32|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1767:6): [True: 21, False: 11]
  ------------------
 1768|     32|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Oberthur style 'PIN RESET' failed: invalid PIN reference");
  ------------------
  |  |  174|     21|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     21|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     21|	int _ret = (r); \
  |  |  |  |  168|     21|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1769|       |
 1770|     11|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1771|     11|	memset(&tmp_path, 0, sizeof(struct sc_path));
 1772|       |
 1773|     11|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|     11|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1774|     11|	pin_cmd.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|     11|#define SC_PIN_CMD_VERIFY	0
  ------------------
 1775|     11|	pin_cmd.pin_reference = OBERTHUR_PIN_REFERENCE_PUK;
  ------------------
  |  |   45|     11|#define OBERTHUR_PIN_REFERENCE_PUK	0x84
  ------------------
 1776|     11|	memcpy(&pin_cmd.pin1, &data->pin1, sizeof(pin_cmd.pin1));
 1777|       |
 1778|     11|	rv = auth_pin_verify(card, SC_AC_CHV, &pin_cmd);
  ------------------
  |  |  151|     11|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1779|     11|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' failed: SOPIN verify error");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1780|       |
 1781|      6|	sc_format_path("2000", &tmp_path);
 1782|      6|	tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      6|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1783|      6|	rv = iso_ops->select_file(card, &tmp_path, &tmp_file);
 1784|      6|	LOG_TEST_RET(card->ctx, rv, "select PUK file");
  ------------------
  |  |  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: 1, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1785|       |
 1786|      5|	if (!tmp_file || tmp_file->size < OBERTHUR_AUTH_MAX_LENGTH_PUK) {
  ------------------
  |  |   96|      5|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1786:6): [True: 0, False: 5]
  |  Branch (1786:19): [True: 1, False: 4]
  ------------------
 1787|      1|		sc_file_free(tmp_file);
 1788|      1|		LOG_TEST_RET(card->ctx, SC_ERROR_FILE_TOO_SMALL, "Oberthur style 'PIN RESET' failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1789|      1|	}
 1790|      4|	sc_file_free(tmp_file);
 1791|       |
 1792|      4|	rv = iso_ops->read_binary(card, 0, puk, OBERTHUR_AUTH_MAX_LENGTH_PUK, 0);
  ------------------
  |  |   96|      4|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1793|      4|	LOG_TEST_RET(card->ctx, rv, "read PUK file error");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1794|      2|	if (rv != OBERTHUR_AUTH_MAX_LENGTH_PUK)
  ------------------
  |  |   96|      2|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1794:6): [True: 1, False: 1]
  ------------------
 1795|      2|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA, "Oberthur style 'PIN RESET' failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1796|       |
 1797|      1|	memset(ffs1, 0xFF, sizeof(ffs1));
 1798|      1|	memcpy(ffs1, puk, rv);
 1799|       |
 1800|      1|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1801|      1|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      1|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1802|      1|        pin_cmd.cmd = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  417|      1|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
 1803|      1|	pin_cmd.pin_reference = local_pin_reference;
 1804|      1|	auth_init_pin_info(card, &pin_cmd.pin1, OBERTHUR_AUTH_TYPE_PUK);
  ------------------
  |  |   93|      1|#define OBERTHUR_AUTH_TYPE_PUK		2
  ------------------
 1805|      1|	pin_cmd.pin1.data = ffs1;
 1806|      1|	pin_cmd.pin1.len = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      1|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1807|       |
 1808|      1|	if (data->pin2.data) {
  ------------------
  |  Branch (1808:6): [True: 1, False: 0]
  ------------------
 1809|      1|		memcpy(&pin_cmd.pin2, &data->pin2, sizeof(pin_cmd.pin2));
 1810|      1|		rv = auth_pin_reset(card, SC_AC_CHV, &pin_cmd);
  ------------------
  |  |  151|      1|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1811|      1|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|      1|	}
 1813|       |
 1814|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2C, 0x00, local_pin_reference);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1815|      0|	apdu.lc = OBERTHUR_AUTH_MAX_LENGTH_PIN  + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   95|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
              	apdu.lc = OBERTHUR_AUTH_MAX_LENGTH_PIN  + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1816|      0|	apdu.datalen = OBERTHUR_AUTH_MAX_LENGTH_PIN  + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   95|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
              	apdu.datalen = OBERTHUR_AUTH_MAX_LENGTH_PIN  + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1817|      0|	apdu.data = ffs1;
 1818|       |
 1819|      0|	pin_cmd.apdu = &apdu;
 1820|      0|	pin_cmd.flags |= SC_PIN_CMD_USE_PINPAD | SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	pin_cmd.flags |= SC_PIN_CMD_USE_PINPAD | SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1821|       |
 1822|      0|	pin_cmd.pin1.min_length = 4;
 1823|      0|	pin_cmd.pin1.max_length = 8;
 1824|      0|	pin_cmd.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1825|      0|	pin_cmd.pin1.offset = 5;
 1826|       |
 1827|      0|	pin_cmd.pin2.data = &ffs1[OBERTHUR_AUTH_MAX_LENGTH_PUK];
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1828|      0|	pin_cmd.pin2.len = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1829|      0|	pin_cmd.pin2.offset = 5 + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1830|      0|	pin_cmd.pin2.min_length = 4;
 1831|      0|	pin_cmd.pin2.max_length = 8;
 1832|      0|	pin_cmd.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1833|       |
 1834|      0|	rvv = iso_drv->ops->pin_cmd(card, &pin_cmd);
 1835|      0|	if (rvv)
  ------------------
  |  Branch (1835:6): [True: 0, False: 0]
  ------------------
 1836|      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__
  |  |  ------------------
  ------------------
 1837|      0|				"%s: PIN CMD 'VERIFY' with pinpad failed",
 1838|      0|				sc_strerror(rvv));
 1839|       |
 1840|      0|	if (auth_current_ef) {
  ------------------
  |  Branch (1840:6): [True: 0, False: 0]
  ------------------
 1841|      0|		struct sc_file *ef = NULL;
 1842|      0|		rv = iso_ops->select_file(card, &auth_current_ef->path, &ef);
 1843|      0|		if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1843:7): [True: 0, False: 0]
  ------------------
 1844|      0|			sc_file_free(auth_current_ef);
 1845|      0|			auth_current_ef = ef;
 1846|      0|		} else
 1847|      0|			sc_file_free(ef);
 1848|      0|	}
 1849|       |
 1850|      0|	if (rv > 0)
  ------------------
  |  Branch (1850:6): [True: 0, False: 0]
  ------------------
 1851|      0|		rv = 0;
 1852|       |
 1853|      0|	LOG_FUNC_RETURN(card->ctx, rv ? rv: rvv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (154:13): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1854|      0|}
card-oberthur.c:auth_check_sw:
 2272|  24.2k|{
 2273|  24.2k|	int ii;
 2274|       |
 2275|  48.3k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2275:15): [True: 24.2k, False: 24.1k]
  ------------------
 2276|  24.2k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2276:7): [True: 67, False: 24.1k]
  ------------------
 2277|     67|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   71|     67|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2278|     67|			return auth_warnings[ii].errorno;
 2279|     67|		}
 2280|  24.2k|	}
 2281|       |
 2282|  24.1k|	return iso_ops->check_sw(card, sw1, sw2);
 2283|  24.2k|}

populate_blobs_to_mf:
  381|    764|{
  382|    764|	pgp_do_info_t	*info;
  383|       |
  384|    764|	if (priv->mf == NULL)
  ------------------
  |  Branch (384:6): [True: 0, False: 764]
  ------------------
  385|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  386|       |
  387|  44.5k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (387:33): [True: 44.5k, False: 0]
  |  Branch (387:51): [True: 43.8k, False: 764]
  ------------------
  388|  43.8k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (388:7): [True: 32.0k, False: 11.7k]
  |  Branch (388:53): [True: 14.3k, False: 17.7k]
  ------------------
  389|  14.3k|			pgp_blob_t *child = NULL;
  390|  14.3k|			sc_file_t *file = sc_file_new();
  391|       |
  392|  14.3k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  393|       |
  394|       |			/* catch out of memory condition */
  395|  14.3k|			if (child == NULL) {
  ------------------
  |  Branch (395:8): [True: 0, False: 14.3k]
  ------------------
  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|  14.3k|		}
  400|  43.8k|	}
  401|    764|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    764|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    764|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    764|	int _ret = r; \
  |  |  |  |  155|    764|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 764, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    764|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 764]
  |  |  |  |  ------------------
  |  |  |  |  157|    764|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    764|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    764|	return _ret; \
  |  |  |  |  163|    764|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    764|}
_pgp_add_algo:
  740|    764|{
  741|    764|	unsigned long flags = 0, ext_flags = 0;
  742|       |
  743|    764|	if (!card || !key_info)
  ------------------
  |  Branch (743:6): [True: 0, False: 764]
  |  Branch (743:15): [True: 0, False: 764]
  ------------------
  744|      0|		return 0;
  745|       |
  746|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  747|    764|	switch (key_info->algorithm) {
  748|    764|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    764|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (748:2): [True: 764, 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|    764|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  111|    764|#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|    764|#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|    764|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  752|    764|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  133|    764|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  753|    764|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |   93|    764|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  754|       |
  755|    764|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  756|    764|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %zu",
  ------------------
  |  |   71|    764|#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|    764|				do_num, key_info->u.rsa.modulus_len);
  758|    764|		break;
  759|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (759:2): [True: 0, False: 764]
  ------------------
  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:
  ------------------
  |  |  879|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (765:2): [True: 0, False: 764]
  ------------------
  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:
  ------------------
  |  |  880|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (781:2): [True: 0, False: 764]
  ------------------
  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: 764]
  ------------------
  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|    764|	}
  798|       |	/* return true */
  799|    764|	return 1;
  800|    764|}
sc_get_openpgp_driver:
 4209|  16.9k|{
 4210|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4211|       |
 4212|  16.9k|	iso_ops = iso_drv->ops;
 4213|       |
 4214|  16.9k|	pgp_ops = *iso_ops;
 4215|  16.9k|	pgp_ops.match_card	= pgp_match_card;
 4216|  16.9k|	pgp_ops.init		= pgp_init;
 4217|  16.9k|	pgp_ops.finish		= pgp_finish;
 4218|  16.9k|	pgp_ops.select_file	= pgp_select_file;
 4219|  16.9k|	pgp_ops.list_files	= pgp_list_files;
 4220|  16.9k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4221|  16.9k|	pgp_ops.read_binary	= pgp_read_binary;
 4222|  16.9k|	pgp_ops.write_binary	= NULL;
 4223|  16.9k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4224|  16.9k|	pgp_ops.logout		= pgp_logout;
 4225|  16.9k|	pgp_ops.get_data	= pgp_get_data;
 4226|  16.9k|	pgp_ops.put_data	= pgp_put_data;
 4227|  16.9k|	pgp_ops.set_security_env= pgp_set_security_env;
 4228|  16.9k|	pgp_ops.compute_signature= pgp_compute_signature;
 4229|  16.9k|	pgp_ops.decipher	= pgp_decipher;
 4230|  16.9k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4231|  16.9k|	pgp_ops.delete_file	= pgp_delete_file;
 4232|  16.9k|	pgp_ops.update_binary	= pgp_update_binary;
 4233|  16.9k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4234|       |
 4235|  16.9k|	return &pgp_drv;
 4236|  16.9k|}
card-openpgp.c:pgp_new_blob:
 1240|  44.4k|{
 1241|  44.4k|	pgp_blob_t *blob = NULL;
 1242|       |
 1243|  44.4k|	if (file == NULL)
  ------------------
  |  Branch (1243:6): [True: 0, False: 44.4k]
  ------------------
 1244|      0|		return NULL;
 1245|       |
 1246|  44.4k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1246:6): [True: 44.4k, False: 0]
  ------------------
 1247|  44.4k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  44.4k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1248|  44.4k|		pgp_do_info_t *info;
 1249|       |
 1250|  44.4k|		blob->file = file;
 1251|       |
 1252|  44.4k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  44.4k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1253|  44.4k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  44.4k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1254|  44.4k|		blob->file->id           = file_id;
 1255|       |
 1256|  44.4k|		blob->id     = file_id;
 1257|  44.4k|		blob->parent = parent;
 1258|       |
 1259|  44.4k|		if (parent != NULL) {
  ------------------
  |  Branch (1259:7): [True: 43.6k, False: 764]
  ------------------
 1260|  43.6k|			pgp_blob_t **p;
 1261|       |
 1262|       |			/* set file's path = parent's path + file's id */
 1263|  43.6k|			blob->file->path = parent->file->path;
 1264|  43.6k|			sc_append_file_id(&blob->file->path, file_id);
 1265|       |
 1266|       |			/* append blob to list of parent's children */
 1267|  7.87M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1267:29): [True: 7.82M, False: 43.6k]
  ------------------
 1268|  7.82M|				;
 1269|  43.6k|			*p = blob;
 1270|  43.6k|		}
 1271|    764|		else {
 1272|    764|			char path[10] = "0000";	/* long enough */
 1273|       |
 1274|       |			/* no parent: set file's path = file's id */
 1275|    764|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1275:8): [True: 0, False: 764]
  ------------------
 1276|      0|				free(blob);
 1277|      0|				return NULL;
 1278|      0|			}
 1279|       |
 1280|    764|			sc_format_path(path, &blob->file->path);
 1281|    764|		}
 1282|       |
 1283|       |		/* find matching DO info: set file type depending on it */
 1284|  1.72M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1284:34): [True: 1.72M, False: 0]
  |  Branch (1284:52): [True: 1.71M, False: 11.1k]
  ------------------
 1285|  1.71M|			if (info->id == file_id) {
  ------------------
  |  Branch (1285:8): [True: 33.2k, False: 1.67M]
  ------------------
 1286|  33.2k|				blob->info = info;
 1287|  33.2k|				blob->file->type = blob->info->type;
 1288|  33.2k|				pgp_attach_acl(card, blob->file, info);
 1289|  33.2k|				break;
 1290|  33.2k|			}
 1291|  1.71M|		}
 1292|  44.4k|	}
 1293|       |
 1294|  44.4k|	return blob;
 1295|  44.4k|}
card-openpgp.c:pgp_attach_acl:
 1172|  33.2k|{
 1173|  33.2k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  33.2k|#define SC_AC_NONE			0x00000000
  ------------------
 1174|  33.2k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  33.2k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1175|       |
 1176|       |	/* Write access */
 1177|  33.2k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1177:10): [True: 33.2k, False: 0]
  ------------------
 1178|  9.87k|	case WRITE_NEVER:
  ------------------
  |  Branch (1178:2): [True: 9.87k, False: 23.3k]
  ------------------
 1179|  9.87k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  9.87k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1180|  9.87k|		break;
 1181|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1181:2): [True: 0, False: 33.2k]
  ------------------
 1182|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1183|      0|		key_ref = 0x01;
 1184|      0|		break;
 1185|  1.52k|	case WRITE_PIN2:
  ------------------
  |  Branch (1185:2): [True: 1.52k, False: 31.7k]
  ------------------
 1186|  1.52k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.52k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1187|  1.52k|		key_ref = 0x02;
 1188|  1.52k|		break;
 1189|  21.8k|	case WRITE_PIN3:
  ------------------
  |  Branch (1189:2): [True: 21.8k, False: 11.4k]
  ------------------
 1190|  21.8k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  21.8k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1191|  21.8k|		key_ref = 0x03;
 1192|  21.8k|		break;
 1193|  33.2k|	}
 1194|       |
 1195|  33.2k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  66.4k|#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: 33.2k, False: 0]
  |  Branch (1195:30): [True: 0, False: 0]
  ------------------
 1196|  33.2k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  33.2k|#define SC_AC_OP_WRITE			24
  ------------------
 1197|  33.2k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  33.2k|#define SC_AC_OP_UPDATE			23
  ------------------
 1198|  33.2k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  33.2k|#define SC_AC_OP_DELETE			2
  ------------------
 1199|  33.2k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  33.2k|#define SC_AC_OP_CREATE			3
  ------------------
 1200|  33.2k|	}
 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|  33.2k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  33.2k|#define SC_AC_NONE			0x00000000
  ------------------
 1208|  33.2k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  33.2k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1209|       |	/* Read access */
 1210|  33.2k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1210:10): [True: 3.19k, False: 30.0k]
  ------------------
 1211|  1.67k|	case READ_NEVER:
  ------------------
  |  Branch (1211:2): [True: 1.67k, False: 31.5k]
  ------------------
 1212|  1.67k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.67k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1213|  1.67k|		break;
 1214|      0|	case READ_PIN1:
  ------------------
  |  Branch (1214:2): [True: 0, False: 33.2k]
  ------------------
 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|    764|	case READ_PIN2:
  ------------------
  |  Branch (1218:2): [True: 764, False: 32.4k]
  ------------------
 1219|    764|		method = SC_AC_CHV;
  ------------------
  |  |  151|    764|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1220|    764|		key_ref = 0x02;
 1221|    764|		break;
 1222|    764|	case READ_PIN3:
  ------------------
  |  Branch (1222:2): [True: 764, False: 32.4k]
  ------------------
 1223|    764|		method = SC_AC_CHV;
  ------------------
  |  |  151|    764|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1224|    764|		key_ref = 0x03;
 1225|    764|		break;
 1226|  33.2k|	}
 1227|       |
 1228|  33.2k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  66.4k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  30.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1228:6): [True: 3.19k, False: 30.0k]
  |  Branch (1228:30): [True: 0, False: 30.0k]
  ------------------
 1229|  3.19k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  3.19k|#define SC_AC_OP_READ			22
  ------------------
 1230|  3.19k|	}
 1231|  33.2k|}
card-openpgp.c:pgp_match_card:
  326|  3.60k|{
  327|  3.60k|	int i;
  328|       |
  329|  3.60k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.60k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.60k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.60k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.60k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.60k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.60k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.60k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 154, False: 3.44k]
  ------------------
  333|    154|		card->name = pgp_atrs[i].name;
  334|    154|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 154]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    154|	} else { \
  |  |  |  |  159|    154|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    154|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    154|	} \
  |  |  |  |  162|    154|	return _ret; \
  |  |  |  |  163|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|    154|	}
  336|  3.44k|	else {
  337|  3.44k|		sc_path_t	partial_aid;
  338|  3.44k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.44k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.44k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.44k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.44k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.44k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.44k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 636, False: 2.81k]
  ------------------
  346|    636|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    636|			card->name = default_cardname;
  348|       |
  349|    636|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 635, False: 1]
  ------------------
  350|    635|				(void) get_full_pgp_aid(card, file);
  351|    636|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 26, False: 610]
  ------------------
  352|     26|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     26|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     26|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 22]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|     13|					case 2:
  ------------------
  |  Branch (359:6): [True: 13, False: 13]
  ------------------
  360|     13|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|     13|						card->name = default_cardname_v2;
  362|     13|						break;
  363|      5|					case 3:
  ------------------
  |  Branch (363:6): [True: 5, False: 21]
  ------------------
  364|      5|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      5|						card->name = default_cardname_v3;
  366|      5|						break;
  367|      4|					default:
  ------------------
  |  Branch (367:6): [True: 4, False: 22]
  ------------------
  368|      4|						break;
  369|     26|				}
  370|     26|			}
  371|    636|			sc_file_free(file);
  372|    636|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    636|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    636|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    636|	int _ret = r; \
  |  |  |  |  155|    636|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 636]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    636|	} else { \
  |  |  |  |  159|    636|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    636|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    636|	} \
  |  |  |  |  162|    636|	return _ret; \
  |  |  |  |  163|    636|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    636|		}
  374|  3.44k|	}
  375|  2.81k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.81k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.81k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.81k|	int _ret = r; \
  |  |  |  |  155|  2.81k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.81k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.81k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.81k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.81k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.81k|	} else { \
  |  |  |  |  159|      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.81k|	return _ret; \
  |  |  |  |  163|  2.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.81k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.40k|{
  308|  1.40k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.40k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.40k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.40k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.40k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.40k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   66|  1.40k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (66:20): [True: 661, False: 743]
  |  |  ------------------
  ------------------
  314|  1.40k|	}
  315|       |
  316|  1.40k|	return r;
  317|  1.40k|}
card-openpgp.c:pgp_init:
  409|    790|{
  410|    790|	struct pgp_priv_data *priv;
  411|    790|	sc_path_t	path;
  412|    790|	sc_file_t	*file = NULL;
  413|    790|	int		r, i;
  414|       |
  415|    790|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    790|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    790|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    790|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    790|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 790]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |
  417|    790|	priv = calloc (1, sizeof *priv);
  418|    790|	if (!priv)
  ------------------
  |  Branch (418:6): [True: 0, False: 790]
  ------------------
  419|    790|		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|    790|	card->drv_data = priv;
  421|       |
  422|    790|	card->cla = 0x00;
  423|       |
  424|       |	/* select application "OpenPGP" */
  425|    790|	sc_format_path("D276:0001:2401", &path);
  426|    790|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    790|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  427|    790|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (427:6): [True: 20, False: 770]
  ------------------
  428|     20|		sc_file_free(file);
  429|     20|		pgp_finish(card);
  430|     20|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|     20|	}
  432|       |
  433|       |	/* defensive programming check */
  434|    770|	if (!file)   {
  ------------------
  |  Branch (434:6): [True: 0, False: 770]
  ------------------
  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|    770|	if (file->namelen != 16) {
  ------------------
  |  Branch (439:6): [True: 769, False: 1]
  ------------------
  440|       |		/* explicitly get the full aid */
  441|    769|		r = get_full_pgp_aid(card, file);
  442|    769|		if (r < 0) {
  ------------------
  |  Branch (442:7): [True: 6, False: 763]
  ------------------
  443|      6|			sc_file_free(file);
  444|      6|			pgp_finish(card);
  445|      6|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      6|		}
  447|    769|	}
  448|       |
  449|       |	/* read information from AID */
  450|    764|	if (file->namelen == 16) {
  ------------------
  |  Branch (450:6): [True: 427, False: 337]
  ------------------
  451|    427|		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|    427|		priv->bcd_version = bebytes2ushort(file->name + 6);
  455|    427|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    427|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  456|    427|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    427|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  457|       |
  458|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  459|    427|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (459:7): [True: 2, False: 425]
  ------------------
  460|    425|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (460:7): [True: 3, False: 422]
  ------------------
  461|    422|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (461:7): [True: 2, False: 420]
  ------------------
  462|      7|			snprintf(card_name, sizeof(card_name),
  463|      7|				 "OpenPGP card v%u.%u (%04X %08lX)",
  464|      7|				 card->version.hw_major, card->version.hw_minor,
  465|      7|				 bebytes2ushort(file->name + 8),
  466|      7|				 bebytes2ulong(file->name + 10));
  467|      7|		}
  468|    420|		else if (card->name != NULL) {
  ------------------
  |  Branch (468:12): [True: 420, False: 0]
  ------------------
  469|       |			/* for other cards, append serial number to the card name */
  470|    420|			snprintf(card_name, sizeof(card_name),
  471|    420|				 "%s (%04X %08lX)",
  472|    420|				 card->name,
  473|    420|				 bebytes2ushort(file->name + 8),
  474|    420|				 bebytes2ulong(file->name + 10));
  475|    420|		}
  476|    427|		card->name = card_name;
  477|       |
  478|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  479|    427|		memcpy(card->serialnr.value, file->name + 8, 6);
  480|    427|		card->serialnr.len = 6;
  481|    427|	} else {
  482|       |		/* set detailed card version */
  483|    337|		switch (card->type) {
  484|      2|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (484:4): [True: 2, False: 335]
  ------------------
  485|      2|				priv->bcd_version = OPENPGP_CARD_3_0;
  486|      2|				break;
  487|    131|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (487:4): [True: 131, False: 206]
  ------------------
  488|    140|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (488:4): [True: 9, False: 328]
  ------------------
  489|    140|				priv->bcd_version = OPENPGP_CARD_2_0;
  490|    140|				break;
  491|    195|			default:
  ------------------
  |  Branch (491:4): [True: 195, False: 142]
  ------------------
  492|    195|				priv->bcd_version = OPENPGP_CARD_1_1;
  493|    195|				break;
  494|    337|		}
  495|    337|	}
  496|       |
  497|       |	/* set pointer to correct list of card objects */
  498|    764|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (498:22): [True: 225, False: 539]
  ------------------
  499|    764|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (499:8): [True: 141, False: 398]
  ------------------
  500|    539|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (500:8): [True: 7, False: 391]
  ------------------
  501|    398|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (501:8): [True: 6, False: 385]
  ------------------
  502|    391|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (502:8): [True: 1, False: 384]
  ------------------
  503|    385|			  :					     pgp34_objects;
  504|       |
  505|       |	/* With gnuk, we use different curves */
  506|    764|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (506:6): [True: 151, False: 613]
  ------------------
  507|    151|		priv->ec_curves = ec_curves_gnuk;
  508|    613|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (508:13): [True: 371, False: 242]
  ------------------
  509|    371|		priv->ec_curves = ec_curves_openpgp34;
  510|    371|	} else {
  511|    242|		priv->ec_curves = ec_curves_openpgp;
  512|    242|	}
  513|       |
  514|       |	/* change file path to MF for reuse in MF */
  515|    764|	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|    764|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  520|    764|	if (!priv->mf) {
  ------------------
  |  Branch (520:6): [True: 0, False: 764]
  ------------------
  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|    764|	priv->current = priv->mf;
  528|       |
  529|    764|	r = populate_blobs_to_mf(card, priv);
  530|    764|	if (r < 0) {
  ------------------
  |  Branch (530:6): [True: 0, False: 764]
  ------------------
  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|    764|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (536:6): [True: 28, False: 736]
  ------------------
  537|     28|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|     28|	}
  539|       |
  540|       |	/* if algorithm attributes can be changed,
  541|       |	 * add supported algorithms based on specification for pkcs15-init */
  542|    736|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (542:6): [True: 86, False: 650]
  ------------------
  543|     86|		unsigned long flags_rsa, flags_ecc, ext_flags;
  544|     86|		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|     86|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  111|     86|#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|     86|#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|     86|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  548|     86|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  133|     86|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  549|     86|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     86|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     86|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|     86|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  551|     86|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|     86|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  552|     86|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|     86|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     86|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  553|     86|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     86|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|     86|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|     86|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  555|       |
  556|     86|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  188|     86|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  557|     86|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     86|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  558|       |		/* xeddsa may allow signing at some time */
  559|     86|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  173|     86|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  560|     86|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     86|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  561|       |
  562|     86|		switch (card->type) {
  563|      1|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (563:4): [True: 1, False: 85]
  ------------------
  564|       |				/* RSA 1024 was removed for v3+ */
  565|      1|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  566|      1|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  567|       |				/* fallthrough */
  568|     48|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (568:4): [True: 47, False: 39]
  ------------------
  569|     48|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  570|    343|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (570:15): [True: 295, False: 48]
  ------------------
  571|    295|				{
  572|    295|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   70|    295|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (572:10): [True: 103, False: 192]
  ------------------
  573|    103|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  574|    103|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  575|    192|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    192|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (575:15): [True: 96, False: 96]
  ------------------
  576|     96|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  577|     96|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  578|     96|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     96|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (578:15): [True: 96, False: 0]
  ------------------
  579|     96|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  580|     96|								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|    295|				}
  584|     48|				break;
  585|     48|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (585:4): [True: 2, False: 84]
  ------------------
  586|     38|			default:
  ------------------
  |  Branch (586:4): [True: 36, False: 50]
  ------------------
  587|     38|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  588|     38|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  589|     38|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  590|     38|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  591|     38|				break;
  592|     86|		}
  593|     86|	}
  594|       |
  595|    736|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    736|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    736|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    736|	int _ret = r; \
  |  |  |  |  155|    736|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 736, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    736|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 736]
  |  |  |  |  ------------------
  |  |  |  |  157|    736|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    736|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    736|	return _ret; \
  |  |  |  |  163|    736|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|    736|}
card-openpgp.c:pgp_get_blob:
 1480|  11.7k|{
 1481|  11.7k|	pgp_blob_t		*child;
 1482|  11.7k|	int			r;
 1483|       |
 1484|  11.7k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1484:6): [True: 1.10k, False: 10.6k]
  ------------------
 1485|  1.10k|		return r;
 1486|       |
 1487|  78.3k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1487:28): [True: 76.2k, False: 2.12k]
  ------------------
 1488|  76.2k|		if (child->id == id) {
  ------------------
  |  Branch (1488:7): [True: 8.54k, False: 67.6k]
  ------------------
 1489|  8.54k|			(void) pgp_read_blob(card, child);
 1490|  8.54k|			*ret = child;
 1491|  8.54k|			return SC_SUCCESS;
  ------------------
  |  |   28|  8.54k|#define SC_SUCCESS				0
  ------------------
 1492|  8.54k|		}
 1493|  76.2k|	}
 1494|       |
 1495|       |	/* This part is for "NOT FOUND" cases */
 1496|       |
 1497|       |	/* Special case:
 1498|       |	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
 1499|       |	 * So, if these blob was not found, we create it. */
 1500|  2.12k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  4.24k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|    510|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|    510|#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: 255, False: 1.86k]
  |  Branch (1500:36): [True: 0, False: 255]
  |  Branch (1500:53): [True: 255, False: 0]
  |  Branch (1500:75): [True: 0, False: 0]
  ------------------
 1501|    255|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1502|    255|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1503|    255|		if (child) {
  ------------------
  |  Branch (1503:7): [True: 255, False: 0]
  ------------------
 1504|    255|			pgp_set_blob(child, NULL, 0);
 1505|    255|			*ret = child;
 1506|    255|			return SC_SUCCESS;
  ------------------
  |  |   28|    255|#define SC_SUCCESS				0
  ------------------
 1507|    255|		}
 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|    255|			       "Not enough memory to create blob for DO %X",
 1511|    255|			       id);
 1512|    255|	}
 1513|       |
 1514|  1.86k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.86k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1515|  2.12k|}
card-openpgp.c:pgp_enumerate_blob:
 1398|  12.1k|{
 1399|  12.1k|	const u8	*in;
 1400|  12.1k|	int		r;
 1401|  12.1k|	sc_file_t	*file = NULL;
 1402|       |
 1403|  12.1k|	if (blob->files != NULL)
  ------------------
  |  Branch (1403:6): [True: 9.85k, False: 2.29k]
  ------------------
 1404|  9.85k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.85k|#define SC_SUCCESS				0
  ------------------
 1405|       |
 1406|  2.29k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1406:6): [True: 977, False: 1.31k]
  ------------------
 1407|    977|		return r;
 1408|       |
 1409|  1.31k|	in = blob->data;
 1410|       |
 1411|  30.5k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1411:9): [True: 29.7k, False: 876]
  ------------------
 1412|  29.7k|		unsigned int	cla, tag, tmptag;
 1413|  29.7k|		size_t		len;
 1414|  29.7k|		const u8	*data = in;
 1415|  29.7k|		pgp_blob_t	*new;
 1416|       |
 1417|  29.7k|		if (!in)
  ------------------
  |  Branch (1417:7): [True: 0, False: 29.7k]
  ------------------
 1418|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1419|       |
 1420|  29.7k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1421|  29.7k|					&cla, &tag, &len);
 1422|  29.7k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  29.7k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1422:7): [True: 117, False: 29.5k]
  ------------------
 1423|    117|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   71|    117|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1424|    117|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    117|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1425|    117|		}
 1426|       |		/* Check for unknown error, or empty data */
 1427|  29.5k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    232|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1427:8): [True: 232, False: 29.3k]
  |  Branch (1427:19): [True: 0, False: 232]
  ------------------
 1428|  29.5k|		    (data == NULL)) {
  ------------------
  |  Branch (1428:7): [True: 127, False: 29.4k]
  ------------------
 1429|    127|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1430|    127|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    127|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1431|    127|		}
 1432|       |
 1433|       |		/* undo ASN1's split of tag & class */
 1434|  29.8k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1434:22): [True: 389, False: 29.4k]
  ------------------
 1435|    389|			cla <<= 8;
 1436|    389|		}
 1437|  29.4k|		tag |= cla;
 1438|       |		/* Check for length mismatch */
 1439|  29.4k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  29.4k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1439:7): [True: 232, False: 29.2k]
  ------------------
 1440|  29.2k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1440:7): [True: 0, False: 29.2k]
  ------------------
 1441|       |			// Check if it is not known Yubikey 5 issue
 1442|    232|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1442:8): [True: 183, False: 49]
  |  Branch (1442:29): [True: 11, False: 38]
  ------------------
 1443|    194|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    194|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1444|    194|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    194|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1445|    194|			}
 1446|    232|		}
 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|  29.2k|		if (tag == blob->id) {
  ------------------
  |  Branch (1451:7): [True: 245, False: 29.0k]
  ------------------
 1452|    245|			in = data;
 1453|    245|			continue;
 1454|    245|		}
 1455|       |
 1456|       |		/* create fake file system hierarchy by
 1457|       |		 * using constructed DOs as DF */
 1458|  29.0k|		file = sc_file_new();
 1459|  29.0k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1459:7): [True: 0, False: 29.0k]
  ------------------
 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|  29.0k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  29.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1463:7): [True: 0, False: 29.0k]
  ------------------
 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|  29.0k|		in = data + len;
 1468|  29.0k|	}
 1469|       |
 1470|    876|	return SC_SUCCESS;
  ------------------
  |  |   28|    876|#define SC_SUCCESS				0
  ------------------
 1471|  1.31k|}
card-openpgp.c:pgp_set_blob:
 1140|  30.6k|{
 1141|  30.6k|	if (blob->data)
  ------------------
  |  Branch (1141:6): [True: 0, False: 30.6k]
  ------------------
 1142|      0|		free(blob->data);
 1143|  30.6k|	blob->data = NULL;
 1144|  30.6k|	blob->len    = 0;
 1145|  30.6k|	blob->status = 0;
 1146|       |
 1147|  30.6k|	if (len > 0) {
  ------------------
  |  Branch (1147:6): [True: 15.5k, False: 15.0k]
  ------------------
 1148|  15.5k|		void *tmp = calloc(1, len);
 1149|       |
 1150|  15.5k|		if (tmp == NULL)
  ------------------
  |  Branch (1150:7): [True: 0, False: 15.5k]
  ------------------
 1151|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|  15.5k|		blob->data = tmp;
 1154|  15.5k|		blob->len  = (unsigned int)len;
 1155|  15.5k|		if (data != NULL)
  ------------------
  |  Branch (1155:7): [True: 15.5k, False: 0]
  ------------------
 1156|  15.5k|			memcpy(blob->data, data, len);
 1157|  15.5k|	}
 1158|       |
 1159|  30.6k|	if (blob->file)
  ------------------
  |  Branch (1159:6): [True: 30.6k, False: 0]
  ------------------
 1160|  30.6k|		blob->file->size = len;
 1161|       |
 1162|  30.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  30.6k|#define SC_SUCCESS				0
  ------------------
 1163|  30.6k|}
card-openpgp.c:pgp_read_blob:
 1348|  14.4k|{
 1349|  14.4k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  14.4k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1350|       |
 1351|  14.4k|	if (blob->data != NULL)
  ------------------
  |  Branch (1351:6): [True: 10.3k, False: 4.06k]
  ------------------
 1352|  10.3k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.3k|#define SC_SUCCESS				0
  ------------------
 1353|  4.06k|	if (blob->info == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 4.06k]
  ------------------
 1354|      0|		return blob->status;
 1355|       |
 1356|  4.06k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1356:6): [True: 4.02k, False: 46]
  ------------------
 1357|  4.02k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1358|  4.02k|		size_t	buf_len = sizeof(buffer);
 1359|  4.02k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.02k|#define SC_SUCCESS				0
  ------------------
 1360|       |
 1361|       |		/* buffer length for certificate */
 1362|  4.02k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  8.04k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1362:7): [True: 140, False: 3.88k]
  |  Branch (1362:30): [True: 41, False: 99]
  ------------------
 1363|     41|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   69|     41|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 28, False: 13]
  |  |  ------------------
  ------------------
 1364|     41|		}
 1365|       |
 1366|       |		/* buffer length for Gnuk pubkey */
 1367|  4.02k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1367:7): [True: 787, False: 3.23k]
  ------------------
 1368|    787|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|  1.57k|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1368:8): [True: 0, False: 787]
  ------------------
 1369|    787|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|  1.57k|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1369:8): [True: 0, False: 787]
  ------------------
 1370|    787|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|  1.57k|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1370:8): [True: 0, False: 787]
  ------------------
 1371|    787|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|  1.57k|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1371:8): [True: 0, False: 787]
  ------------------
 1372|    787|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|  1.57k|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1372:8): [True: 0, False: 787]
  ------------------
 1373|    787|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|    787|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1373:8): [True: 0, False: 787]
  ------------------
 1374|      0|			buf_len = MIN(MAXLEN_RESP_PUBKEY_GNUK, sizeof(buffer));
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, Folded]
  |  |  ------------------
  ------------------
 1375|      0|		}
 1376|       |
 1377|  4.02k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1378|       |
 1379|  4.02k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1379:7): [True: 2.70k, False: 1.31k]
  ------------------
 1380|  2.70k|			blob->status = r;
 1381|  2.70k|			return r;
 1382|  2.70k|		}
 1383|       |
 1384|  1.31k|		return pgp_set_blob(blob, buffer, r);
 1385|  4.02k|	}
 1386|     46|	else {		/* un-readable DO or part of a constructed DO */
 1387|     46|		return SC_SUCCESS;
  ------------------
  |  |   28|     46|#define SC_SUCCESS				0
  ------------------
 1388|     46|	}
 1389|  4.06k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  634|  12.1k|{
  635|  12.1k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  12.1k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  636|  12.1k|	struct sc_object_id oid;
  637|  12.1k|	unsigned int j, r;
  638|       |
  639|  12.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  12.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |
  641|  12.1k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (641:6): [True: 0, False: 12.1k]
  |  Branch (641:22): [True: 1.99k, False: 10.1k]
  |  Branch (641:44): [True: 0, False: 10.1k]
  ------------------
  642|  10.1k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 10.1k]
  |  Branch (642:27): [True: 0, False: 10.1k]
  |  Branch (642:48): [True: 0, False: 10.1k]
  ------------------
  643|  1.99k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.99k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.99k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.99k|	int _ret = r; \
  |  |  |  |  155|  1.99k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.99k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|  1.99k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.99k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.99k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.99k|	return _ret; \
  |  |  |  |  163|  1.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|  1.99k|	}
  645|       |
  646|  10.1k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  647|       |
  648|  10.1k|	switch (blob->data[0]) {
  649|  1.88k|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|  1.88k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (649:3): [True: 1.88k, False: 8.30k]
  ------------------
  650|  1.88k|			if (blob->len < 5) {
  ------------------
  |  Branch (650:8): [True: 1.12k, False: 764]
  ------------------
  651|  1.12k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.12k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.12k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.12k|	int _ret = r; \
  |  |  |  |  155|  1.12k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.12k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.12k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.12k|	return _ret; \
  |  |  |  |  163|  1.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|  1.12k|			}
  653|       |
  654|    764|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  877|    764|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  655|    764|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  656|    764|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  657|       |
  658|    764|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (658:32): [True: 406, False: 358]
  ------------------
  659|    764|						  ? blob->data[5]
  660|    764|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  882|  1.12k|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  661|    764|			break;
  662|  3.23k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|  3.23k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (662:3): [True: 3.23k, False: 6.95k]
  ------------------
  663|  6.22k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|  6.22k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (663:3): [True: 2.98k, False: 7.20k]
  ------------------
  664|  6.56k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|  6.56k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (664:3): [True: 339, False: 9.84k]
  ------------------
  665|       |
  666|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  667|  6.56k|			key_info->algorithm = blob->data[0];
  668|       |
  669|       |			/* last byte is set to 0xFF if pubkey import is supported */
  670|  6.56k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  888|  6.56k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (670:8): [True: 1.45k, False: 5.10k]
  ------------------
  671|  1.45k|				if (blob->len < 3)
  ------------------
  |  Branch (671:9): [True: 826, False: 629]
  ------------------
  672|    826|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    826|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  673|    629|				key_info->u.ec.oidv_len = blob->len - 2;
  674|    629|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  888|    629|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  675|    629|			}
  676|  5.10k|			else {
  677|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  678|       |				 * it is not part of OID */
  679|  5.10k|				if (blob->len < 2)
  ------------------
  |  Branch (679:9): [True: 2.16k, False: 2.94k]
  ------------------
  680|  2.16k|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|  2.16k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  681|  2.94k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  887|  2.94k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (681:9): [True: 888, False: 2.05k]
  ------------------
  682|    888|					key_info->u.ec.oidv_len = blob->len - 2;
  683|  2.05k|				else
  684|  2.05k|					key_info->u.ec.oidv_len = blob->len - 1;
  685|  2.94k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  887|  2.94k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  686|  2.94k|			}
  687|       |
  688|       |			/* Create copy of oid from blob */
  689|  3.57k|			sc_init_oid(&oid);
  690|  3.57k|			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|  3.57k|			if (r > 0){
  ------------------
  |  Branch (693:8): [True: 2.53k, False: 1.03k]
  ------------------
  694|  2.53k|				return r;
  695|  2.53k|			}
  696|       |			/* compare with list of supported ec_curves */
  697|  14.3k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (697:16): [True: 13.3k, False: 1.03k]
  ------------------
  698|  13.3k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (698:9): [True: 0, False: 13.3k]
  ------------------
  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|  13.3k|			}
  706|       |			/* We did not match the OID */
  707|  1.03k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (707:8): [True: 1.03k, False: 0]
  ------------------
  708|  1.03k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|  1.03k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  1.03k|			}
  710|      0|			break;
  711|  1.74k|		default:
  ------------------
  |  Branch (711:3): [True: 1.74k, False: 8.44k]
  ------------------
  712|  1.74k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  1.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.74k|	int _ret = r; \
  |  |  |  |  155|  1.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.74k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.74k|	return _ret; \
  |  |  |  |  163|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|  10.1k|	}
  714|       |
  715|    764|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    764|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    764|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    764|	int _ret = r; \
  |  |  |  |  155|    764|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 764, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    764|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 764]
  |  |  |  |  ------------------
  |  |  |  |  157|    764|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    764|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    764|	return _ret; \
  |  |  |  |  163|    764|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|    764|}
card-openpgp.c:pgp_get_card_features:
  909|    764|{
  910|    764|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    764|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  911|    764|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  912|    764|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  913|    764|	unsigned int i;
  914|    764|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  915|    764|	int handled_algos = 0;
  916|       |
  917|    764|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    764|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    764|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    764|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    764|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 764]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  918|       |
  919|       |	/* parse card capabilities from historical bytes in ATR */
  920|    764|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (920:6): [True: 257, False: 507]
  ------------------
  921|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  922|    257|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (922:11): [True: 189, False: 68]
  ------------------
  923|    177|			case 0x00:
  ------------------
  |  Branch (923:4): [True: 177, False: 80]
  ------------------
  924|    177|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (924:9): [True: 168, False: 9]
  ------------------
  925|    168|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  926|    168|				}
  927|    177|				break;
  928|      9|			case 0x80:
  ------------------
  |  Branch (928:4): [True: 9, False: 248]
  ------------------
  929|      9|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (929:9): [True: 8, False: 1]
  ------------------
  930|      8|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  931|      8|				}
  932|      9|				break;
  933|      3|			case 0x10:
  ------------------
  |  Branch (933:4): [True: 3, False: 254]
  ------------------
  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|    257|		}
  939|    257|	}
  940|       |
  941|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  942|    764|	priv->ext_caps &= ~EXT_CAP_LCS;
  943|       |
  944|    764|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (944:6): [True: 539, False: 225]
  ------------------
  945|       |		/* get card capabilities from "historical bytes" DO */
  946|    539|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (946:7): [True: 539, False: 0]
  ------------------
  947|    539|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (947:7): [True: 55, False: 484]
  |  Branch (947:31): [True: 31, False: 24]
  ------------------
  948|       |
  949|     31|			if (blob->len > 4) {
  ------------------
  |  Branch (949:8): [True: 29, False: 2]
  ------------------
  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|     31|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (954:8): [True: 31, False: 0]
  |  Branch (954:35): [True: 30, False: 1]
  ------------------
  955|     30|				priv->state = blob->data[blob->len-3];
  956|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  957|     30|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (957:9): [True: 20, False: 10]
  ------------------
  958|     20|					priv->ext_caps |= EXT_CAP_LCS;
  959|     30|			}
  960|     31|		}
  961|    539|	}
  962|       |
  963|    764|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (963:6): [True: 386, False: 378]
  ------------------
  964|    386|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    386|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  965|    386|	}
  966|       |
  967|    764|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (967:6): [True: 384, False: 380]
  ------------------
  968|       |		/* Parse supported algorithms from Algorithm Information DO
  969|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  970|    384|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (970:7): [True: 384, False: 0]
  ------------------
  971|    384|			pgp_blob_t *child;
  972|    384|			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|  17.6k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (975:32): [True: 17.3k, False: 384]
  ------------------
  976|  17.3k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (976:9): [True: 3.93k, False: 13.3k]
  |  Branch (976:33): [True: 1.71k, False: 11.6k]
  ------------------
  977|  5.65k|					continue;
  978|  11.6k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  979|  11.6k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (979:9): [True: 553, False: 11.0k]
  ------------------
  980|    553|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  981|  11.6k|			}
  982|    384|		}
  983|    384|	}
  984|       |
  985|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  986|    764|	priv->max_specialDO_size = 254;
  987|       |
  988|    764|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (988:6): [True: 764, False: 0]
  ------------------
  989|    764|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (989:6): [True: 242, False: 522]
  ------------------
  990|       |
  991|       |		/* get "extended capabilities" DO */
  992|    242|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (992:7): [True: 101, False: 141]
  ------------------
  993|    101|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (993:7): [True: 99, False: 2]
  |  Branch (993:31): [True: 99, False: 0]
  ------------------
  994|     99|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (994:8): [True: 37, False: 62]
  |  Branch (994:34): [True: 25, False: 12]
  ------------------
  995|     25|				priv->ext_caps |= EXT_CAP_KDF_DO;
  996|     25|			}
  997|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  998|     99|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (998:8): [True: 92, False: 7]
  ------------------
  999|     92|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (999:6): [True: 87, False: 5]
  ------------------
 1000|     87|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
 1001|       |			/* bit 0x08 in first byte means "support for private use DOs" */
 1002|     99|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (1002:8): [True: 58, False: 41]
  ------------------
 1003|     58|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1004|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1005|     99|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1005:8): [True: 10, False: 89]
  ------------------
 1006|     10|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1007|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1008|     99|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1008:8): [True: 56, False: 43]
  ------------------
 1009|     56|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1010|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1011|     99|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1011:8): [True: 59, False: 40]
  ------------------
 1012|     59|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     59|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1013|     59|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1014|     59|			}
 1015|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1016|     99|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1016:8): [True: 61, False: 38]
  ------------------
 1017|     61|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1017:6): [True: 58, False: 3]
  ------------------
 1018|     58|				priv->ext_caps |= EXT_CAP_SM;
 1019|       |
 1020|     99|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1020:8): [True: 94, False: 5]
  |  Branch (1020:51): [True: 75, False: 19]
  ------------------
 1021|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1022|     75|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1023|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1024|     75|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1025|       |
 1026|     75|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1026:9): [True: 47, False: 28]
  ------------------
 1027|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1028|     47|					priv->sm_algo = blob->data[1];
 1029|     47|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1029:10): [True: 36, False: 11]
  |  Branch (1029:45): [True: 31, False: 5]
  ------------------
 1030|     31|						priv->sm_algo = SM_ALGO_3DES;
 1031|       |
 1032|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1033|     47|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1034|     47|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1035|     47|				}
 1036|     28|				else {
 1037|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1038|     28|					priv->sm_algo = blob->data[1];
 1039|     28|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1039:10): [True: 16, False: 12]
  |  Branch (1039:45): [True: 12, False: 4]
  ------------------
 1040|     12|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1041|       |
 1042|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1043|     28|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1044|     28|				}
 1045|     75|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1045:9): [True: 28, False: 47]
  |  Branch (1045:50): [True: 28, False: 0]
  ------------------
 1046|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1047|     28|					if (blob->data[9])
  ------------------
  |  Branch (1047:10): [True: 21, False: 7]
  ------------------
 1048|     21|						priv->ext_caps |= EXT_CAP_MSE;
 1049|     28|				}
 1050|     75|			}
 1051|     99|		}
 1052|       |
 1053|       |		/* get max. PIN length from "CHV status bytes" DO */
 1054|    242|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1054:7): [True: 199, False: 43]
  ------------------
 1055|    199|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1055:4): [True: 197, False: 2]
  |  Branch (1055:28): [True: 196, False: 1]
  ------------------
 1056|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1057|    196|			card->max_pin_len = blob->data[1];
 1058|    196|		}
 1059|       |
 1060|    242|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1060:7): [True: 120, False: 122]
  ------------------
 1061|       |			/* v3.0+: get length info from "extended length information" DO */
 1062|    120|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1062:8): [True: 3, False: 117]
  ------------------
 1063|      3|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1063:5): [True: 2, False: 1]
  |  Branch (1063:29): [True: 1, False: 1]
  ------------------
 1064|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1065|      1|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1066|      1|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1067|      1|			}
 1068|    120|		}
 1069|       |
 1070|    242|#ifdef ENABLE_OPENSSL
 1071|    242|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1071:7): [True: 25, False: 217]
  ------------------
 1072|     25|			int r = pgp_decode_kdf_do(card, priv);
 1073|     25|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (1073:8): [True: 24, False: 1]
  ------------------
 1074|     24|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1075|     24|			}
 1076|     25|		}
 1077|    242|#endif /* ENABLE_OPENSSL */
 1078|       |
 1079|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1080|    242|		if (handled_algos) {
  ------------------
  |  Branch (1080:7): [True: 2, False: 240]
  ------------------
 1081|      2|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1082|      2|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  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: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      2|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      2|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      2|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1083|      2|		}
 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|    960|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1091:20): [True: 720, False: 240]
  ------------------
 1092|    720|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1093|       |
 1094|    720|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   71|    720|#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|    720|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1097:8): [True: 531, False: 189]
  ------------------
 1098|    531|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1098:8): [True: 211, False: 320]
  ------------------
 1099|    211|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1099:9): [True: 0, False: 211]
  ------------------
 1100|    211|					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|    211|			}
 1102|    720|		}
 1103|       |
 1104|    240|	}
 1105|       |
 1106|    762|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    762|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    762|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    762|	int _ret = r; \
  |  |  |  |  155|    762|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 736, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  156|    736|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 736]
  |  |  |  |  ------------------
  |  |  |  |  157|    736|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    736|	} else { \
  |  |  |  |  159|     26|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     26|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     26|	} \
  |  |  |  |  162|    762|	return _ret; \
  |  |  |  |  163|    762|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|    762|}
card-openpgp.c:pgp_parse_hist_bytes:
  604|    207|{
  605|    207|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    207|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  606|    207|	const u8 *ptr;
  607|       |
  608|       |	/* IS07816-4 hist bytes: 3rd function table */
  609|    207|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (609:6): [True: 172, False: 35]
  ------------------
  610|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  611|    172|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (611:7): [True: 15, False: 157]
  ------------------
  612|     15|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     15|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  613|     15|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  614|     15|		}
  615|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  616|    172|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (616:7): [True: 158, False: 14]
  ------------------
  617|    158|			priv->ext_caps |= EXT_CAP_CHAINING;
  618|    158|		}
  619|    172|	}
  620|       |
  621|    207|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (621:6): [True: 51, False: 156]
  ------------------
  622|     51|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (622:6): [True: 24, False: 27]
  ------------------
  623|       |		// ToDo ...
  624|     24|	}
  625|    207|}
card-openpgp.c:pgp_decode_kdf_do:
  805|     25|{
  806|     25|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  807|     25|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     25|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  808|     25|	pgp_blob_t *kdf_blob;
  809|     25|	const uint8_t *data;
  810|     25|	size_t data_len;
  811|     25|	size_t tag_len;
  812|     25|	const uint8_t *p;
  813|     25|	pgp_blob_t *blob;
  814|       |
  815|     25|	if (!pin_kdf_info) {
  ------------------
  |  Branch (815:6): [True: 0, False: 25]
  ------------------
  816|      0|		return r;
  817|      0|	}
  818|       |
  819|     25|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     25|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  820|     25|	priv->pin_kdf_info = NULL;
  821|     25|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     25|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (821:6): [True: 0, False: 25]
  |  Branch (821:73): [True: 7, False: 18]
  ------------------
  822|      7|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  823|      7|		goto out;
  824|      7|	}
  825|       |
  826|     18|	data = kdf_blob->data;
  827|     18|	data_len = kdf_blob->len;
  828|     18|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  829|     18|	if (!p) {
  ------------------
  |  Branch (829:6): [True: 6, False: 12]
  ------------------
  830|      6|		sc_log(card->ctx, "KDF algorithm byte not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  831|      6|		goto out;
  832|      6|	}
  833|     12|	if (tag_len != 1) {
  ------------------
  |  Branch (833:6): [True: 1, False: 11]
  ------------------
  834|      1|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  835|      1|		goto out;
  836|      1|	}
  837|       |
  838|     11|	if (*p != 0x3) {
  ------------------
  |  Branch (838:6): [True: 3, False: 8]
  ------------------
  839|      3|		if (*p == 0x0) {
  ------------------
  |  Branch (839:7): [True: 1, False: 2]
  ------------------
  840|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  841|      1|			sc_log(card->ctx, "KDF derived PIN format disabled");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  842|      2|		} else {
  843|      2|			sc_log(card->ctx, "Unknown KDF algorithm ID %x", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  844|      2|		}
  845|      3|		goto out;
  846|      3|	}
  847|       |
  848|      8|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  849|      8|	if (!p) {
  ------------------
  |  Branch (849:6): [True: 1, False: 7]
  ------------------
  850|      1|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  851|      1|		goto out;
  852|      1|	}
  853|      7|	if (tag_len != 1) {
  ------------------
  |  Branch (853:6): [True: 2, False: 5]
  ------------------
  854|      2|		sc_log(card->ctx, "Unexpected KDF hash algorithm byte length, expects 1, got %zu", tag_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__
  |  |  ------------------
  ------------------
  855|      2|		goto out;
  856|      2|	}
  857|       |
  858|      5|	switch (*p) {
  859|      1|	case 0x08:
  ------------------
  |  Branch (859:2): [True: 1, False: 4]
  ------------------
  860|      1|		pin_kdf_info->hash_algo = "SHA256";
  861|      1|		break;
  862|      3|	case 0x0A:
  ------------------
  |  Branch (862:2): [True: 3, False: 2]
  ------------------
  863|      3|		pin_kdf_info->hash_algo = "SHA512";
  864|      3|		break;
  865|      1|	default:
  ------------------
  |  Branch (865:2): [True: 1, False: 4]
  ------------------
  866|      1|		sc_log(card->ctx, "Unknown KDF hash algorithm ID %x", *p);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  867|      1|		goto out;
  868|      5|	}
  869|       |
  870|      4|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  871|      4|	if (!p) {
  ------------------
  |  Branch (871:6): [True: 2, False: 2]
  ------------------
  872|      2|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  873|      2|		goto out;
  874|      2|	}
  875|      2|	if (tag_len != 4) {
  ------------------
  |  Branch (875:6): [True: 1, False: 1]
  ------------------
  876|      1|		sc_log(card->ctx, "Unexpected KDF iteration count length, expects 4, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  877|      1|		goto out;
  878|      1|	}
  879|      1|	pin_kdf_info->iterations = (uint32_t)bebytes2ulong(p);
  880|       |
  881|      1|	r = pgp_get_blob(card, kdf_blob, 0x84, &blob);
  882|      1|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (882:6): [True: 1, False: 0]
  ------------------
  883|      1|		sc_log(card->ctx, "Failed to get salt bytes of user password");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  884|      1|		goto out;
  885|      1|	}
  886|      0|	pin_kdf_info->userpw_salt = blob;
  887|       |
  888|      0|	r = pgp_get_blob(card, kdf_blob, 0x86, &blob);
  889|      0|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (889:6): [True: 0, False: 0]
  ------------------
  890|      0|		sc_log(card->ctx, "Failed to get salt bytes of admin password");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  891|      0|		goto out;
  892|      0|	}
  893|      0|	pin_kdf_info->adminpw_salt = blob;
  894|       |
  895|      0|	sc_log(card->ctx, "KDF derived PIN format enabled");
  ------------------
  |  |   71|      0|#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|      0|	priv->pin_kdf_info = pin_kdf_info;
  897|      0|	return r;
  898|     25|out:
  899|     25|	free(pin_kdf_info);
  900|     25|	return r;
  901|      0|}
card-openpgp.c:pgp_finish:
 1115|    790|{
 1116|    790|	if (card != NULL) {
  ------------------
  |  Branch (1116:6): [True: 790, False: 0]
  ------------------
 1117|    790|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    790|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1118|       |
 1119|    790|		if (priv != NULL) {
  ------------------
  |  Branch (1119:7): [True: 790, False: 0]
  ------------------
 1120|       |			/* delete fake file hierarchy */
 1121|    790|			pgp_free_blobs(priv->mf);
 1122|       |
 1123|       |			/* delete kdf do related data if exists */
 1124|    790|			free(priv->pin_kdf_info);
 1125|       |
 1126|       |			/* delete private data */
 1127|    790|			free(priv);
 1128|    790|		}
 1129|    790|		card->drv_data = NULL;
 1130|    790|	}
 1131|    790|	return SC_SUCCESS;
  ------------------
  |  |   28|    790|#define SC_SUCCESS				0
  ------------------
 1132|    790|}
card-openpgp.c:pgp_free_blobs:
 1328|  44.4k|{
 1329|  44.4k|	if (blob) {
  ------------------
  |  Branch (1329:6): [True: 44.4k, False: 26]
  ------------------
 1330|  44.4k|		pgp_blob_t *child = blob->files;
 1331|       |
 1332|  88.0k|		while (child != NULL) {
  ------------------
  |  Branch (1332:10): [True: 43.6k, False: 44.4k]
  ------------------
 1333|  43.6k|			pgp_blob_t *next = child->next;
 1334|       |
 1335|  43.6k|			pgp_free_blobs(child);
 1336|  43.6k|			child = next;
 1337|  43.6k|		}
 1338|  44.4k|		pgp_free_blob(blob);
 1339|  44.4k|	}
 1340|  44.4k|}
card-openpgp.c:pgp_free_blob:
 1303|  44.4k|{
 1304|  44.4k|	if (blob) {
  ------------------
  |  Branch (1304:6): [True: 44.4k, False: 0]
  ------------------
 1305|  44.4k|		if (blob->parent) {
  ------------------
  |  Branch (1305:7): [True: 43.6k, False: 764]
  ------------------
 1306|  43.6k|			pgp_blob_t **p;
 1307|       |
 1308|       |			/* remove blob from list of parent's children */
 1309|  43.6k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1309:35): [True: 43.6k, False: 0]
  |  Branch (1309:49): [True: 0, False: 43.6k]
  ------------------
 1310|      0|				;
 1311|  43.6k|			if (*p == blob)
  ------------------
  |  Branch (1311:8): [True: 43.6k, False: 0]
  ------------------
 1312|  43.6k|				*p = blob->next;
 1313|  43.6k|		}
 1314|       |
 1315|  44.4k|		sc_file_free(blob->file);
 1316|  44.4k|		if (blob->data)
  ------------------
  |  Branch (1316:7): [True: 15.5k, False: 28.8k]
  ------------------
 1317|  15.5k|			free(blob->data);
 1318|  44.4k|		free(blob);
 1319|  44.4k|	}
 1320|  44.4k|}
card-openpgp.c:pgp_select_file:
 1614|  6.82k|{
 1615|  6.82k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  6.82k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1616|  6.82k|	pgp_blob_t	*blob;
 1617|  6.82k|	unsigned int	path_start = 0;
 1618|  6.82k|	unsigned int	n;
 1619|  6.82k|	sc_path_t dummy_path;
 1620|       |
 1621|  6.82k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.82k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.82k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.82k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.82k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.82k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  6.82k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  6.82k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1623:6): [True: 1.19k, False: 5.63k]
  ------------------
 1624|  6.82k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  164|  1.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.19k|	int _ret = r; \
  |  |  |  |  155|  1.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.19k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.19k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.12k, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.19k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.19k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.19k|	return _ret; \
  |  |  |  |  163|  1.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|       |
 1626|  5.63k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1626:6): [True: 0, False: 5.63k]
  |  Branch (1626:23): [True: 0, False: 5.63k]
  ------------------
 1627|  5.63k|		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|  5.63k|				"invalid path length");
 1629|       |
 1630|  5.63k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  11.2k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1630:6): [True: 0, False: 5.63k]
  |  Branch (1630:44): [True: 0, False: 0]
  ------------------
 1631|  5.63k|		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|  5.63k|				"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|  5.63k|	sc_format_path("11001101", &dummy_path);
 1641|  5.63k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1641:6): [True: 0, False: 5.63k]
  ------------------
 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|  5.63k|	path_start = pgp_strip_path(card, path);
 1653|       |
 1654|       |	/* starting with the MF ... */
 1655|  5.63k|	blob = priv->mf;
 1656|       |	/* ... recurse through the tree following the path */
 1657|  11.6k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1657:23): [True: 7.96k, False: 3.68k]
  ------------------
 1658|  7.96k|		unsigned int	id = bebytes2ushort(path->value + n);
 1659|  7.96k|		int		r = pgp_get_blob(card, blob, id, &blob);
 1660|       |
 1661|       |		/* This file ID is referred when importing key&certificate via pkcs15init, like above.
 1662|       |		 * We pretend to successfully find this inexistent file. */
 1663|  7.96k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1663:7): [True: 0, False: 7.96k]
  |  Branch (1663:23): [True: 0, False: 7.96k]
  ------------------
 1664|      0|			if (ret == NULL)
  ------------------
  |  Branch (1664:8): [True: 0, False: 0]
  ------------------
 1665|       |				/* No need to return file */
 1666|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1667|       |
 1668|       |			/* Else, need to return file */
 1669|      0|			*ret = sc_file_new();
 1670|      0|			(*ret)->size = priv->max_cert_size;
 1671|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1672|      0|		}
 1673|       |
 1674|  7.96k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1674:7): [True: 1.95k, False: 6.00k]
  ------------------
 1675|  1.95k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.95k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.95k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.95k|	int _ret = r; \
  |  |  |  |  155|  1.95k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.95k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.95k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.95k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.95k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.95k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.95k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.95k|	return _ret; \
  |  |  |  |  163|  1.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1676|  1.95k|		}
 1677|  7.96k|	}
 1678|       |
 1679|       |	/* success: select file = set "current" pointer to blob found */
 1680|  3.68k|	priv->current = blob;
 1681|       |
 1682|  3.68k|	if (ret)
  ------------------
  |  Branch (1682:6): [True: 2.03k, False: 1.64k]
  ------------------
 1683|  2.03k|		sc_file_dup(ret, blob->file);
 1684|       |
 1685|  3.68k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.68k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.68k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.68k|	int _ret = r; \
  |  |  |  |  155|  3.68k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.68k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.68k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.68k|	return _ret; \
  |  |  |  |  163|  3.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1686|  3.68k|}
card-openpgp.c:pgp_strip_path:
 1595|  5.63k|{
 1596|  5.63k|	unsigned int start_point = 0;
 1597|       |	/* start_point will move through the path string */
 1598|  5.63k|	if (path->len == 0)
  ------------------
  |  Branch (1598:6): [True: 0, False: 5.63k]
  ------------------
 1599|      0|		return 0;
 1600|       |
 1601|       |	/* ignore 3F00 (MF) at the beginning */
 1602|  5.63k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1602:16): [True: 3.06k, False: 2.57k]
  ------------------
 1603|       |	/* strip path of PKCS15-App DF (5015) */
 1604|  5.63k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1604:17): [True: 1.30k, False: 4.33k]
  ------------------
 1605|  5.63k|	return start_point;
 1606|  5.63k|}
card-openpgp.c:pgp_read_binary:
 1755|  3.57k|{
 1756|  3.57k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  3.57k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1757|  3.57k|	pgp_blob_t	*blob;
 1758|  3.57k|	int		r;
 1759|       |
 1760|  3.57k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.57k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.57k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.57k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1761|       |
 1762|       |	/* jump to selected file */
 1763|  3.57k|	blob = priv->current;
 1764|       |
 1765|  3.57k|	if (blob == NULL)
  ------------------
  |  Branch (1765:6): [True: 0, False: 3.57k]
  ------------------
 1766|  3.57k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|       |
 1768|  3.57k|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|  3.57k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1768:6): [True: 0, False: 3.57k]
  ------------------
 1769|  3.57k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|       |
 1771|  3.57k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1771:6): [True: 0, False: 3.57k]
  ------------------
 1772|  3.57k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|       |
 1774|  3.57k|	if (idx > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 3.57k]
  ------------------
 1775|  3.57k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1776|       |
 1777|  3.57k|	if (idx + count > blob->len)
  ------------------
  |  Branch (1777:6): [True: 0, False: 3.57k]
  ------------------
 1778|      0|		count = blob->len - idx;
 1779|  3.57k|	memcpy(buf, blob->data + idx, count);
 1780|       |
 1781|  3.57k|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  164|  3.57k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.57k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.57k|	int _ret = r; \
  |  |  |  |  155|  3.57k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 3.57k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.57k|	} else { \
  |  |  |  |  159|  3.57k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.57k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.57k|	} \
  |  |  |  |  162|  3.57k|	return _ret; \
  |  |  |  |  163|  3.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|  3.57k|}
card-openpgp.c:pgp_pin_cmd:
 2388|  1.07k|{
 2389|  1.07k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.07k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2390|  1.07k|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2391|       |
 2392|  1.07k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.07k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.07k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2393|       |
 2394|  1.07k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.07k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2394:6): [True: 0, False: 1.07k]
  ------------------
 2395|  1.07k|		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|  1.07k|				"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|  1.07k|	data->pin_reference |= 0x80;
 2423|       |
 2424|       |	/* check version-dependent constraints */
 2425|  1.07k|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|  2.14k|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|    991|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2425:6): [True: 81, False: 991]
  |  Branch (2425:40): [True: 82, False: 909]
  ------------------
 2426|    163|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2426:7): [True: 151, False: 12]
  ------------------
 2427|    151|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2427:8): [True: 57, False: 94]
  ------------------
 2428|     57|				data->pin_reference = 0x81;
 2429|       |
 2430|    151|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|    151|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2430:8): [True: 75, False: 76]
  ------------------
 2431|     75|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2431:9): [True: 0, False: 75]
  ------------------
 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|     75|					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|     75|							"v2 cards don't support implicit old PIN for PIN change");
 2435|       |
 2436|     75|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|     75|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2437|     75|			}
 2438|    151|		} else {
 2439|     12|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2439:8): [True: 12, False: 0]
  ------------------
 2440|     12|				sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2441|     12|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2442|     12|				sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2443|     12|				       "please make sure that you have verified the relevant PIN first.");
 2444|     12|				data->pin1.len = 0;
 2445|     12|			}
 2446|       |
 2447|     12|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|     12|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2448|     12|		}
 2449|    163|	}
 2450|       |
 2451|  1.07k|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  417|  2.14k|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2451:6): [True: 82, False: 990]
  |  Branch (2451:41): [True: 0, False: 82]
  ------------------
 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|  1.07k|		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|  1.07k|				"new PIN must be provided for unblock operation");
 2455|       |
 2456|       |	/* ensure pin_reference is 81, 82, 83 */
 2457|  1.07k|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2457:6): [True: 16, False: 1.05k]
  |  Branch (2457:36): [True: 0, False: 1.05k]
  ------------------
 2458|  1.07k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2459|  1.05k|				"Invalid key ID; must be 1, 2, or 3");
 2460|       |
 2461|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2462|  1.05k|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  418|  2.11k|#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|    638|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2462:6): [True: 638, False: 418]
  |  Branch (2462:42): [True: 347, False: 291]
  ------------------
 2463|    347|		u8 c4data[10];
 2464|    347|		int r;
 2465|       |
 2466|    347|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2467|    347|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  174|    347|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    347|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    347|	int _ret = (r); \
  |  |  |  |  168|    347|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 314, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  169|    314|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    314|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    314|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    314|		return _ret; \
  |  |  |  |  172|    314|	} \
  |  |  |  |  173|    347|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 33]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2468|       |
 2469|     33|		if (r != 7)
  ------------------
  |  Branch (2469:7): [True: 27, False: 6]
  ------------------
 2470|     33|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  174|     27|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     27|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     27|	int _ret = (r); \
  |  |  |  |  168|     27|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2471|      6|				"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|      6|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2478:7): [True: 5, False: 1]
  |  Branch (2478:48): [True: 2, False: 3]
  ------------------
 2479|      2|			data->pin_reference = 0x81;
 2480|       |
 2481|      6|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2482|      6|		data->pin1.max_tries = 3;
 2483|      6|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      6|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2484|       |
 2485|      6|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2486|      6|	}
 2487|       |
 2488|    709|#ifdef ENABLE_OPENSSL
 2489|    709|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2489:6): [True: 0, False: 709]
  ------------------
 2490|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2491|      0|	}
 2492|    709|#endif /* ENABLE_OPENSSL */
 2493|       |
 2494|    709|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  164|    709|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    709|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    709|	int _ret = r; \
  |  |  |  |  155|    709|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 709, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    709|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    538|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 538, False: 171]
  |  |  |  |  ------------------
  |  |  |  |  157|    709|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    709|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    709|	return _ret; \
  |  |  |  |  163|    709|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2495|    709|}
card-openpgp.c:pgp_get_data:
 1994|  5.98k|{
 1995|  5.98k|	sc_apdu_t	apdu;
 1996|  5.98k|	int		r;
 1997|       |
 1998|  5.98k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.98k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.98k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.98k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.98k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1999|       |
 2000|  5.98k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  5.98k|#define SC_APDU_CASE_2			0x22
  ------------------
 2001|  5.98k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  547|  4.20k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2001:13): [True: 4.20k, False: 1.77k]
  |  Branch (2001:33): [True: 4.10k, False: 98]
  ------------------
 2002|  5.98k|	apdu.resp = buf;
 2003|  5.98k|	apdu.resplen = buf_len;
 2004|       |
 2005|  5.98k|	r = sc_transmit_apdu(card, &apdu);
 2006|  5.98k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  5.98k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.98k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.98k|	int _ret = (r); \
  |  |  |  |  168|  5.98k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 5.94k]
  |  |  |  |  ------------------
  |  |  |  |  169|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     38|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     38|		return _ret; \
  |  |  |  |  172|     38|	} \
  |  |  |  |  173|  5.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.94k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2007|       |
 2008|  5.94k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2009|       |
 2010|       |	/* Gnuk returns an error instead of empty data if there is no certificate or private DO.
 2011|       |	 * So, for this case, we ignore error and consider success */
 2012|  5.94k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2012:6): [True: 1.35k, False: 4.59k]
  ------------------
 2013|  1.35k|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|  2.70k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2013:7): [True: 184, False: 1.16k]
  ------------------
 2014|  1.16k|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|  2.52k|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2014:7): [True: 15, False: 1.15k]
  ------------------
 2015|  1.15k|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|  2.50k|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2015:7): [True: 19, False: 1.13k]
  ------------------
 2016|  1.13k|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|  2.48k|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2016:7): [True: 19, False: 1.11k]
  ------------------
 2017|  1.11k|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|  1.11k|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2017:7): [True: 20, False: 1.09k]
  ------------------
 2018|    257|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    257|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2018:7): [True: 1, False: 256]
  ------------------
 2019|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2020|      1|			apdu.resplen = 0;
 2021|      1|		}
 2022|    257|	}
 2023|  5.94k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  5.94k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.94k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.94k|	int _ret = (r); \
  |  |  |  |  168|  5.94k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.61k, False: 2.32k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.61k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.61k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.61k|		return _ret; \
  |  |  |  |  172|  3.61k|	} \
  |  |  |  |  173|  5.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.32k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2024|       |
 2025|  2.32k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.32k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.32k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.32k|	int _ret = r; \
  |  |  |  |  155|  2.32k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 773, False: 1.55k]
  |  |  |  |  ------------------
  |  |  |  |  156|    773|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 773]
  |  |  |  |  ------------------
  |  |  |  |  157|    773|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.55k|	} else { \
  |  |  |  |  159|  1.55k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.55k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.55k|	} \
  |  |  |  |  162|  2.32k|	return _ret; \
  |  |  |  |  163|  2.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2026|  2.32k|}
card-openpgp.c:pgp_set_security_env:
 2538|    359|{
 2539|    359|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    359|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2540|       |
 2541|    359|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    359|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    359|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    359|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    359|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 359]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2542|       |
 2543|       |	/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
 2544|    359|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   60|    359|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (2544:6): [True: 359, False: 0]
  ------------------
 2545|    359|		&& (env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    359|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2545:6): [True: 0, False: 359]
  ------------------
 2546|      0|		&& (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (2546:6): [True: 0, False: 0]
  ------------------
 2547|      0|		&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
  ------------------
  |  Branch (2547:6): [True: 0, False: 0]
  ------------------
 2548|    359|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2549|    359|				"only RSA algorithm supported");
 2550|       |
 2551|    359|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len != 1))
  ------------------
  |  |   58|    359|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (2551:6): [True: 0, False: 359]
  |  Branch (2551:52): [True: 0, False: 359]
  ------------------
 2552|    359|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2553|    359|				"exactly one key reference required");
 2554|       |
 2555|    359|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   57|    359|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (2555:6): [True: 0, False: 359]
  ------------------
 2556|    359|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2557|    359|			"passing file references not supported");
 2558|       |
 2559|    359|	sc_log(card->ctx, "Key ref %d", env->key_ref[0]);
  ------------------
  |  |   71|    359|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2560|    359|	switch (env->operation) {
 2561|    288|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    288|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2561:2): [True: 288, False: 71]
  ------------------
 2562|    288|		sc_log(card->ctx, "Operation: Sign.");
  ------------------
  |  |   71|    288|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2563|    288|		if (env->key_ref[0] != 0x00 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2563:7): [True: 190, False: 98]
  |  Branch (2563:34): [True: 0, False: 190]
  ------------------
 2564|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2565|      0|				"Key reference not compatible with "
 2566|      0|				"requested usage");
 2567|      0|		}
 2568|    288|		break;
 2569|    288|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     71|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2569:2): [True: 71, False: 288]
  ------------------
 2570|     71|		sc_log(card->ctx, "Operation: Decipher.");
  ------------------
  |  |   71|     71|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2571|       |		/* we allow key ref 2 (auth key) to be used for deciphering */
 2572|     71|		if (env->key_ref[0] != 0x01 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2572:7): [True: 13, False: 58]
  |  Branch (2572:34): [True: 0, False: 13]
  ------------------
 2573|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2574|      0|				"Key reference not compatible with "
 2575|      0|				"requested usage");
 2576|      0|		}
 2577|     71|		break;
 2578|     71|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2578:2): [True: 0, False: 359]
  ------------------
 2579|      0|		sc_log(card->ctx, "Operation: Derive: No particular action needed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2580|      0|		break;
 2581|      0|	default:
  ------------------
  |  Branch (2581:2): [True: 0, False: 359]
  ------------------
 2582|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2583|    359|				"invalid operation");
 2584|    359|	}
 2585|       |
 2586|    359|	priv->sec_env = *env;
 2587|       |
 2588|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2589|    359|}
card-openpgp.c:pgp_compute_signature:
 2643|    288|{
 2644|    288|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|    288|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2645|    288|	sc_security_env_t	*env = &priv->sec_env;
 2646|    288|	sc_apdu_t		apdu;
 2647|    288|	u8 apdu_case = (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
  ------------------
  |  Branch (2647:17): [True: 95, False: 193]
  ------------------
 2648|    288|			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  294|     95|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  303|    481|#define SC_APDU_CASE_4			0x24
  ------------------
 2649|    288|	int			r;
 2650|       |
 2651|    288|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    288|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    288|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    288|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    288|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 288]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2652|       |
 2653|    288|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|    288|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2653:6): [True: 0, False: 288]
  ------------------
 2654|    288|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2655|    288|				"invalid operation");
 2656|       |
 2657|    288|	switch (env->key_ref[0]) {
 2658|     98|	case 0x00: /* signature key */
  ------------------
  |  Branch (2658:2): [True: 98, False: 190]
  ------------------
 2659|       |		/* PSO SIGNATURE */
 2660|     98|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x9E, 0x9A);
 2661|     98|		break;
 2662|    190|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2662:2): [True: 190, False: 98]
  ------------------
 2663|       |		/* INTERNAL AUTHENTICATE */
 2664|    190|		sc_format_apdu(card, &apdu, apdu_case, 0x88, 0, 0);
 2665|    190|		break;
 2666|      0|	case 0x01:
  ------------------
  |  Branch (2666:2): [True: 0, False: 288]
  ------------------
 2667|      0|	default:
  ------------------
  |  Branch (2667:2): [True: 0, False: 288]
  ------------------
 2668|       |		/* From PKCS #11 point of view, we should be able to use
 2669|       |		 * curve25519 to do digital signature, but it is not how it
 2670|       |		 * is used in OpenPGP so we will not allow it here */
 2671|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2672|    288|			"invalid key reference");
 2673|    288|	}
 2674|       |
 2675|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2676|    288|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|    288|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2676:6): [True: 271, False: 17]
  |  Branch (2676:52): [True: 95, False: 176]
  ------------------
 2677|     95|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     95|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2678|       |
 2679|    288|	apdu.lc = data_len;
 2680|    288|	apdu.data = (u8 *)data;
 2681|    288|	apdu.datalen = data_len;
 2682|    288|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|    288|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2682:13): [True: 288, False: 0]
  |  Branch (2682:32): [True: 271, False: 17]
  ------------------
 2683|    288|	apdu.resp    = out;
 2684|    288|	apdu.resplen = outlen;
 2685|       |
 2686|    288|	r = sc_transmit_apdu(card, &apdu);
 2687|    288|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    288|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    288|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    288|	int _ret = (r); \
  |  |  |  |  168|    288|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 134, False: 154]
  |  |  |  |  ------------------
  |  |  |  |  169|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    134|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    134|		return _ret; \
  |  |  |  |  172|    134|	} \
  |  |  |  |  173|    288|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 154]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2688|       |
 2689|    154|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2690|    154|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|    154|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    154|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    154|	int _ret = (r); \
  |  |  |  |  168|    154|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 117, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  169|    117|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    117|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    117|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    117|		return _ret; \
  |  |  |  |  172|    117|	} \
  |  |  |  |  173|    154|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2691|       |
 2692|     37|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|     37|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     37|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     37|	int _ret = r; \
  |  |  |  |  155|     37|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     37|	return _ret; \
  |  |  |  |  163|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2693|     37|}
card-openpgp.c:pgp_decipher:
 2702|     63|{
 2703|     63|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     63|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2704|     63|	sc_security_env_t	*env = &priv->sec_env;
 2705|     63|	sc_apdu_t	apdu;
 2706|     63|	u8 apdu_case = SC_APDU_CASE_4;
  ------------------
  |  |  303|     63|#define SC_APDU_CASE_4			0x24
  ------------------
 2707|     63|	u8		*temp = NULL, *p = NULL;
 2708|     63|	size_t		templen, pklen, dolen;
 2709|     63|	int		r;
 2710|       |
 2711|     63|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     63|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     63|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     63|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     63|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 63]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2712|       |
 2713|       |	/* padding according to OpenPGP card spec 1.1 & 2.x section 7.2.9 / 3.x section 7.2.11
 2714|       |	 * The longest possible prefix is 10 bytes for ECDH */
 2715|     63|	templen = inlen + 10;
 2716|     63|	if (!(temp = malloc(templen)))
  ------------------
  |  Branch (2716:6): [True: 0, False: 63]
  ------------------
 2717|     63|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2718|       |
 2719|       |	/* padding byte: 0xa6 = ECC; 0x00 = RSA; 0x02 = AES */
 2720|     63|	switch (env->algorithm) {
 2721|     63|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|     63|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2721:2): [True: 63, False: 0]
  ------------------
 2722|       |		/* This is just PKCS#1.5 start byte and it should be already
 2723|       |		 * provided by the padding routines. But it lets put it here
 2724|       |		 * to make sure it does not conflict with following indicators */
 2725|     63|		temp[0] = 0x00;
 2726|     63|		memcpy(temp + 1, in, inlen);
 2727|     63|		inlen += 1;
 2728|     63|		break;
 2729|       |
 2730|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2730:2): [True: 0, False: 63]
  ------------------
 2731|      0|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (2731:2): [True: 0, False: 63]
  ------------------
 2732|       |		/* Calculate length of External Public Key (0x86) */
 2733|      0|		r = sc_asn1_put_tag(0x86, NULL, inlen, NULL, 0, NULL);
 2734|      0|		if (r <= 0) {
  ------------------
  |  Branch (2734:7): [True: 0, False: 0]
  ------------------
 2735|      0|			free(temp);
 2736|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2737|      0|		}
 2738|      0|		pklen = r;
 2739|       |
 2740|       |		/* Calculate length of Public Key DO (0x7F49) */
 2741|      0|		r = sc_asn1_put_tag(0x7f49, NULL, pklen, NULL, 0, NULL);
 2742|      0|		if (r <= 0) {
  ------------------
  |  Branch (2742:7): [True: 0, False: 0]
  ------------------
 2743|      0|			free(temp);
 2744|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2745|      0|		}
 2746|      0|		dolen = r;
 2747|       |
 2748|      0|		p = temp;
 2749|       |		/* This is 0xA6 Cipher DO with associated length field */
 2750|      0|		r = sc_asn1_put_tag(0xA6, NULL, dolen, p, templen - (p - temp), &p);
 2751|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2751:7): [True: 0, False: 0]
  ------------------
 2752|      0|			free(temp);
 2753|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2754|      0|		}
 2755|       |
 2756|       |		/* Public Key DO (0x7F49) with associated length field */
 2757|      0|		r = sc_asn1_put_tag(0x7F49, NULL, pklen, p, templen - (p - temp), &p);
 2758|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2758:7): [True: 0, False: 0]
  ------------------
 2759|      0|			free(temp);
 2760|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2761|      0|		}
 2762|       |
 2763|       |		/* External Public Key (0x86) with associated length */
 2764|      0|		r = sc_asn1_put_tag(0x86, in, inlen, p, templen - (p - temp), &p);
 2765|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2765:7): [True: 0, False: 0]
  ------------------
 2766|      0|			free(temp);
 2767|      0|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2768|      0|		}
 2769|      0|		inlen = (p - temp);
 2770|      0|		break;
 2771|      0|	case SC_ALGORITHM_AES:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (2771:2): [True: 0, False: 63]
  ------------------
 2772|       |		/* not supported yet */
 2773|       |		/*
 2774|       |		temp[0] = 0x02;
 2775|       |		memcpy(temp + 1, in, inlen);
 2776|       |		inlen += 1;
 2777|       |		*/
 2778|       |		/* fall through */
 2779|      0|	default:
  ------------------
  |  Branch (2779:2): [True: 0, False: 63]
  ------------------
 2780|      0|		free(temp);
 2781|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2782|     63|	}
 2783|       |
 2784|     63|	in = temp;
 2785|       |
 2786|     63|	if (env->operation != SC_SEC_OPERATION_DECIPHER &&
  ------------------
  |  |   47|    126|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2786:6): [True: 0, False: 63]
  ------------------
 2787|      0|			env->operation != SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2787:4): [True: 0, False: 0]
  ------------------
 2788|      0|		free(temp);
 2789|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2790|      0|				"invalid operation");
 2791|      0|	}
 2792|       |
 2793|     63|	switch (env->key_ref[0]) {
 2794|     50|	case 0x01: /* Decryption key */
  ------------------
  |  Branch (2794:2): [True: 50, False: 13]
  ------------------
 2795|     63|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2795:2): [True: 13, False: 50]
  ------------------
 2796|       |		/* PSO DECIPHER */
 2797|     63|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x80, 0x86);
 2798|     63|		break;
 2799|      0|	case 0x00: /* signature key */
  ------------------
  |  Branch (2799:2): [True: 0, False: 63]
  ------------------
 2800|      0|	default:
  ------------------
  |  Branch (2800:2): [True: 0, False: 63]
  ------------------
 2801|      0|		free(temp);
 2802|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2803|     63|				"invalid key reference");
 2804|     63|	}
 2805|       |
 2806|       |	/* Gnuk only supports short APDU, so we need to use command chaining */
 2807|     63|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (2807:6): [True: 18, False: 45]
  ------------------
 2808|     18|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     18|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2809|     18|	}
 2810|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2811|     63|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|     63|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2811:6): [True: 56, False: 7]
  |  Branch (2811:52): [True: 18, False: 38]
  ------------------
 2812|     18|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     18|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2813|       |
 2814|     63|	apdu.lc = inlen;
 2815|     63|	apdu.data = (u8 *)in;
 2816|     63|	apdu.datalen = inlen;
 2817|     63|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|     63|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2817:13): [True: 63, False: 0]
  |  Branch (2817:32): [True: 56, False: 7]
  ------------------
 2818|     63|	apdu.resp = out;
 2819|     63|	apdu.resplen = outlen;
 2820|       |
 2821|       |	/* For OpenPGP Card >=v3.3, key slot 3 instead of 2 can be used for deciphering,
 2822|       |	 * but this has to be set via MSE beforehand on every usage (slot 2 is used by default)
 2823|       |	 * see section 7.2.18 of the specification of OpenPGP Card v3.3 */
 2824|     63|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2824:6): [True: 45, False: 18]
  |  Branch (2824:47): [True: 13, False: 32]
  ------------------
 2825|     13|		pgp_set_MSE(card, 3, 0xb8);
 2826|     13|	}
 2827|       |
 2828|     63|	r = sc_transmit_apdu(card, &apdu);
 2829|     63|	free(temp);
 2830|     63|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 15, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  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|     63|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2831|       |
 2832|     48|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2833|     48|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 37, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2834|       |
 2835|       |	/* For OpenPGP Card >=v3.3, use key slot 2 for deciphering again (set to default) */
 2836|     11|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2836:6): [True: 9, False: 2]
  |  Branch (2836:47): [True: 4, False: 5]
  ------------------
 2837|      4|		pgp_set_MSE(card, 2, 0xb8);
 2838|      4|	}
 2839|       |
 2840|     11|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|      5|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      5|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      5|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|     11|}
card-openpgp.c:pgp_set_MSE:
 2604|     17|{
 2605|     17|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     17|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2606|     17|	sc_apdu_t	apdu;
 2607|     17|	u8	apdu_case = SC_APDU_CASE_3;
  ------------------
  |  |  302|     17|#define SC_APDU_CASE_3			0x23
  ------------------
 2608|     17|	u8	apdu_data[3];
 2609|     17|	int	r;
 2610|       |
 2611|     17|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     17|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     17|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     17|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     17|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2612|       |
 2613|       |	// check if MSE is supported
 2614|     17|	if (!(priv->ext_caps & EXT_CAP_MSE))
  ------------------
  |  Branch (2614:6): [True: 0, False: 17]
  ------------------
 2615|     17|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2616|       |
 2617|       |	// create apdu
 2618|     17|	sc_format_apdu(card, &apdu, apdu_case, 0x22, 0x41, p2);
 2619|     17|	apdu.lc = 3;
 2620|     17|	apdu_data[0] = 0x83;
 2621|     17|	apdu_data[1] = 0x01;
 2622|     17|	apdu_data[2] = key;
 2623|     17|	apdu.data = apdu_data;
 2624|     17|	apdu.datalen = 3;
 2625|       |
 2626|       |	// transmit apdu
 2627|     17|	r = sc_transmit_apdu(card, &apdu);
 2628|     17|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2629|       |
 2630|     14|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2631|     14|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 11, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2632|       |
 2633|      3|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2634|      3|}
card-openpgp.c:pgp_card_ctl:
 4009|    240|{
 4010|    240|	int r;
 4011|       |
 4012|    240|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4013|       |
 4014|    240|	switch(cmd) {
  ------------------
  |  Branch (4014:9): [True: 240, False: 0]
  ------------------
 4015|     31|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4015:2): [True: 31, False: 209]
  ------------------
 4016|     31|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4017|     31|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4018|      0|		break;
 4019|    209|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4019:2): [True: 209, False: 31]
  ------------------
 4020|    209|		r = pgp_select_data(card, *((u8 *) ptr));
 4021|    209|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    209|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    209|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    209|	int _ret = r; \
  |  |  |  |  155|    209|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 209, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    209|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    191|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 191, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  157|    209|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    209|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    209|	return _ret; \
  |  |  |  |  163|    209|} 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: 240]
  ------------------
 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: 240]
  ------------------
 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: 240]
  ------------------
 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|    240|	}
 4038|       |
 4039|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4040|      0|}
card-openpgp.c:pgp_select_data:
 1956|    209|{
 1957|    209|	sc_apdu_t	apdu;
 1958|    209|	u8	apdu_data[6];
 1959|    209|	int	r;
 1960|    209|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    209|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1961|       |
 1962|    209|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    209|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    209|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    209|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    209|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 209]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1963|       |
 1964|    209|	if (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (1964:6): [True: 120, False: 89]
  ------------------
 1965|    209|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1966|       |
 1967|     89|	sc_log(card->ctx, "select data with: %u", p1);
  ------------------
  |  |   71|     89|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1968|       |
 1969|       |	// create apdu data (taken from spec: SELECT DATA 7.2.5.)
 1970|     89|	apdu_data[0] = 0x60;
 1971|     89|	apdu_data[1] = 0x04;
 1972|     89|	apdu_data[2] = 0x5c;
 1973|     89|	apdu_data[3] = 0x02;
 1974|     89|	apdu_data[4] = 0x7f;
 1975|     89|	apdu_data[5] = 0x21;
 1976|       |
 1977|       |	// apdu, cla, ins, p1, p2, data, datalen, resp, resplen
 1978|     89|	sc_format_apdu_ex(&apdu, 0x00, 0xA5, p1, 0x04, apdu_data, sizeof(apdu_data), NULL, 0);
 1979|       |
 1980|       |	// transmit apdu
 1981|     89|	r = sc_transmit_apdu(card, &apdu);
 1982|     89|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     89|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     89|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     89|	int _ret = (r); \
  |  |  |  |  168|     89|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 82]
  |  |  |  |  ------------------
  |  |  |  |  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|     89|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 82]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|     82|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1984|     82|	LOG_TEST_RET(card->ctx, r, "Card returned 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: 64, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  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|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1985|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1986|     18|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4169|  10.0k|{
 4170|  10.0k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  10.0k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4171|  10.0k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  10.0k|#define SC_SUCCESS				0
  ------------------
 4172|       |
 4173|  10.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.0k]
  |  |  ------------------
  ------------------
 4174|       |
 4175|  10.0k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  537|  20.0k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4175:6): [True: 0, False: 10.0k]
  ------------------
 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|  10.0k|	if (was_reset > 0) {
  ------------------
  |  Branch (4190:6): [True: 0, False: 10.0k]
  ------------------
 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|  10.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  10.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.0k|	int _ret = r; \
  |  |  |  |  155|  10.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10.0k]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  10.0k|	return _ret; \
  |  |  |  |  163|  10.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4201|  10.0k|}

sc_get_piv_driver:
 6708|  16.9k|{
 6709|  16.9k|	return sc_get_driver();
 6710|  16.9k|}
card-piv.c:sc_get_driver:
 6681|  16.9k|{
 6682|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6683|       |
 6684|  16.9k|	piv_ops = *iso_drv->ops;
 6685|  16.9k|	piv_ops.match_card = piv_match_card;
 6686|  16.9k|	piv_ops.init = piv_init;
 6687|  16.9k|	piv_ops.finish = piv_finish;
 6688|       |
 6689|  16.9k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6690|  16.9k|	piv_ops.get_challenge = piv_get_challenge;
 6691|  16.9k|	piv_ops.logout = piv_logout;
 6692|  16.9k|	piv_ops.read_binary = piv_read_binary;
 6693|  16.9k|	piv_ops.write_binary = piv_write_binary;
 6694|  16.9k|	piv_ops.set_security_env = piv_set_security_env;
 6695|  16.9k|	piv_ops.restore_security_env = piv_restore_security_env;
 6696|  16.9k|	piv_ops.compute_signature = piv_compute_signature;
 6697|  16.9k|	piv_ops.decipher = piv_decipher;
 6698|  16.9k|	piv_ops.check_sw = piv_check_sw;
 6699|  16.9k|	piv_ops.card_ctl = piv_card_ctl;
 6700|  16.9k|	piv_ops.pin_cmd = piv_pin_cmd;
 6701|  16.9k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6702|       |
 6703|  16.9k|	return &piv_drv;
 6704|  16.9k|}
card-piv.c:piv_match_card:
 5629|  5.92k|{
 5630|  5.92k|	int r = 0;
 5631|       |
 5632|  5.92k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.92k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5633|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5634|       |	/* user provided card type must be one we know */
 5635|  5.92k|	switch (card->type) {
 5636|  5.92k|	case -1:
  ------------------
  |  Branch (5636:2): [True: 5.92k, False: 0]
  ------------------
 5637|  5.92k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5637:2): [True: 0, False: 5.92k]
  ------------------
 5638|  5.92k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5638:2): [True: 0, False: 5.92k]
  ------------------
 5639|  5.92k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5639:2): [True: 0, False: 5.92k]
  ------------------
 5640|  5.92k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5640:2): [True: 0, False: 5.92k]
  ------------------
 5641|  5.92k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5641:2): [True: 0, False: 5.92k]
  ------------------
 5642|  5.92k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5642:2): [True: 0, False: 5.92k]
  ------------------
 5643|  5.92k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5643:2): [True: 0, False: 5.92k]
  ------------------
 5644|  5.92k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5644:2): [True: 0, False: 5.92k]
  ------------------
 5645|  5.92k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5645:2): [True: 0, False: 5.92k]
  ------------------
 5646|  5.92k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5646:2): [True: 0, False: 5.92k]
  ------------------
 5647|  5.92k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5647:2): [True: 0, False: 5.92k]
  ------------------
 5648|  5.92k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5648:2): [True: 0, False: 5.92k]
  ------------------
 5649|  5.92k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5649:2): [True: 0, False: 5.92k]
  ------------------
 5650|  5.92k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5650:2): [True: 0, False: 5.92k]
  ------------------
 5651|  5.92k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5651:2): [True: 0, False: 5.92k]
  ------------------
 5652|  5.92k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5652:2): [True: 0, False: 5.92k]
  ------------------
 5653|  5.92k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5653:2): [True: 0, False: 5.92k]
  ------------------
 5654|  5.92k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5654:2): [True: 0, False: 5.92k]
  ------------------
 5655|  5.92k|		break;
 5656|      0|	default:
  ------------------
  |  Branch (5656:2): [True: 0, False: 5.92k]
  ------------------
 5657|      0|		return 0; /* can not handle the card */
 5658|  5.92k|	}
 5659|       |
 5660|  5.92k|	r = sc_lock(card);
 5661|  5.92k|	if (r < 0)
  ------------------
  |  Branch (5661:6): [True: 0, False: 5.92k]
  ------------------
 5662|      0|		return 0;
 5663|       |	/* its one we know, or we can test for it in piv_init */
 5664|  5.92k|	r = piv_match_card_continued(card);
 5665|  5.92k|	sc_unlock(card);
 5666|       |
 5667|  5.92k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5667:6): [True: 4.80k, False: 1.11k]
  |  Branch (5667:15): [True: 0, False: 1.11k]
  ------------------
 5668|       |		/* clean up what we left in card */
 5669|  4.80k|		piv_finish(card);
 5670|  4.80k|		return 0; /* match failed */
 5671|  4.80k|	}
 5672|       |
 5673|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5674|  1.11k|	return 1; /* matched */
 5675|  5.92k|}
card-piv.c:piv_match_card_continued:
 5679|  5.92k|{
 5680|  5.92k|	int i, r = 0, r2 = 0;
 5681|  5.92k|	int type = -1;
 5682|  5.92k|	piv_private_data_t *priv = NULL;
 5683|  5.92k|	int saved_type = card->type;
 5684|  5.92k|	sc_apdu_t apdu;
 5685|  5.92k|	u8 yubico_version_buf[3] = {0};
 5686|       |
 5687|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5688|       |	/* User provided card type must be one we know */
 5689|       |
 5690|  5.92k|	switch (card->type) {
 5691|  5.92k|	case -1:
  ------------------
  |  Branch (5691:2): [True: 5.92k, False: 0]
  ------------------
 5692|  5.92k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5692:2): [True: 0, False: 5.92k]
  ------------------
 5693|  5.92k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5693:2): [True: 0, False: 5.92k]
  ------------------
 5694|  5.92k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5694:2): [True: 0, False: 5.92k]
  ------------------
 5695|  5.92k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5695:2): [True: 0, False: 5.92k]
  ------------------
 5696|  5.92k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5696:2): [True: 0, False: 5.92k]
  ------------------
 5697|  5.92k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5697:2): [True: 0, False: 5.92k]
  ------------------
 5698|  5.92k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5698:2): [True: 0, False: 5.92k]
  ------------------
 5699|  5.92k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5699:2): [True: 0, False: 5.92k]
  ------------------
 5700|  5.92k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5700:2): [True: 0, False: 5.92k]
  ------------------
 5701|  5.92k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5701:2): [True: 0, False: 5.92k]
  ------------------
 5702|  5.92k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5702:2): [True: 0, False: 5.92k]
  ------------------
 5703|  5.92k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5703:2): [True: 0, False: 5.92k]
  ------------------
 5704|  5.92k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5704:2): [True: 0, False: 5.92k]
  ------------------
 5705|  5.92k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5705:2): [True: 0, False: 5.92k]
  ------------------
 5706|  5.92k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5706:2): [True: 0, False: 5.92k]
  ------------------
 5707|  5.92k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5707:2): [True: 0, False: 5.92k]
  ------------------
 5708|  5.92k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5708:2): [True: 0, False: 5.92k]
  ------------------
 5709|  5.92k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5709:2): [True: 0, False: 5.92k]
  ------------------
 5710|       |
 5711|  5.92k|		type = card->type;
 5712|  5.92k|		break;
 5713|      0|	default:
  ------------------
  |  Branch (5713:2): [True: 0, False: 5.92k]
  ------------------
 5714|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5715|  5.92k|	}
 5716|  5.92k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.92k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5717|  5.92k|	if (type == -1) {
  ------------------
  |  Branch (5717:6): [True: 5.92k, False: 0]
  ------------------
 5718|       |		/*
 5719|       |		 * Try to identify card by ATR or historical data in ATR
 5720|       |		 * currently all PIV card will respond to piv_find_aid
 5721|       |		 * the same. But in future may need to know card type first,
 5722|       |		 * so do it here.
 5723|       |		 */
 5724|       |
 5725|  5.92k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5725:7): [True: 2.34k, False: 3.57k]
  ------------------
 5726|  2.34k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5726:8): [True: 566, False: 1.78k]
  ------------------
 5727|    566|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5727:6): [True: 216, False: 350]
  ------------------
 5728|    216|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5729|  2.13k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5729:15): [True: 1.43k, False: 696]
  ------------------
 5730|  1.43k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5730:6): [True: 356, False: 1.07k]
  ------------------
 5731|    356|				type = SC_CARD_TYPE_PIV_II_NEO;
 5732|  1.77k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5732:15): [True: 1.11k, False: 662]
  ------------------
 5733|  1.11k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5733:6): [True: 111, False: 1.00k]
  ------------------
 5734|    111|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5735|  1.66k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5735:15): [True: 1.00k, False: 662]
  ------------------
 5736|  1.00k|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5736:6): [True: 21, False: 981]
  ------------------
 5737|     21|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5738|     21|			}
 5739|       |			/* look for TLV historic data */
 5740|  1.64k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5740:13): [True: 1.61k, False: 28]
  ------------------
 5741|  1.61k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5741:6): [True: 512, False: 1.10k]
  ------------------
 5742|    512|				size_t datalen;
 5743|    512|				const u8 *data;
 5744|       |
 5745|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5746|    512|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5746:9): [True: 46, False: 466]
  ------------------
 5747|    512|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5748|     46|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5748:10): [True: 34, False: 12]
  |  Branch (5748:26): [True: 18, False: 16]
  ------------------
 5749|     18|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5750|     28|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5750:17): [True: 4, False: 24]
  |  Branch (5750:33): [True: 1, False: 3]
  ------------------
 5751|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5752|      1|					}
 5753|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5754|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5755|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5756|       |					 * will look at only 6 bytes that do match
 5757|       |					 */
 5758|     27|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5758:15): [True: 3, False: 24]
  |  Branch (5758:31): [True: 1, False: 2]
  ------------------
 5759|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5760|      1|					}
 5761|    466|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5761:16): [True: 136, False: 330]
  ------------------
 5762|    466|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5763|    136|					int k;
 5764|       |
 5765|    237|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5765:18): [True: 187, False: 50]
  ------------------
 5766|    187|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5766:11): [True: 179, False: 8]
  ------------------
 5767|    179|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5767:9): [True: 86, False: 93]
  ------------------
 5768|     86|							type = SC_CARD_TYPE_PIV_II_HIST;
 5769|     86|							break;
 5770|     86|						}
 5771|    187|					}
 5772|    136|				}
 5773|    512|			}
 5774|  2.34k|		}
 5775|       |
 5776|  5.92k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.92k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5777|       |
 5778|  5.92k|		if (type == -1) {
  ------------------
  |  Branch (5778:7): [True: 5.11k, False: 810]
  ------------------
 5779|       |			/* use known ATRs  which changes the type */
 5780|  5.11k|			i = _sc_match_atr(card, piv_atrs, &type);
 5781|  5.11k|			if (i < 0)
  ------------------
  |  Branch (5781:8): [True: 5.08k, False: 28]
  ------------------
 5782|  5.08k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5783|  5.11k|		}
 5784|  5.92k|	}
 5785|       |
 5786|  5.92k|	card->type = type;
 5787|       |
 5788|       |	/* we either found via ATR historic bytes or ATR directly */
 5789|  5.92k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.92k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5790|       |
 5791|       |	/* allocate and init basic fields */
 5792|  5.92k|	priv = calloc(1, sizeof(piv_private_data_t));
 5793|       |
 5794|  5.92k|	if (!priv)
  ------------------
  |  Branch (5794:6): [True: 0, False: 5.92k]
  ------------------
 5795|  5.92k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5796|       |
 5797|  5.92k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5798|       |	/*
 5799|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5800|       |	 * If for some reason future cards have larger objects, this value needs to
 5801|       |	 * be increased here.
 5802|       |	 */
 5803|  5.92k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  5.92k|#define MAX_FILE_SIZE 65535
  ------------------
 5804|  5.92k|	priv->selected_obj = -1;
 5805|  5.92k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5806|  5.92k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  5.92k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5807|  5.92k|	priv->pstate = PIV_STATE_MATCH;
 5808|       |
 5809|       |#ifdef ENABLE_PIV_SM
 5810|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5811|       |	card->sm_ctx.ops.open = piv_sm_open;
 5812|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5813|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5814|       |	card->sm_ctx.ops.close = piv_sm_close;
 5815|       |#endif /* ENABLE_PIV_SM */
 5816|       |
 5817|       |	/* See if contactless  or run as virtual card */
 5818|       |	/* PivApplet in .github/test_piv.sh for example */
 5819|  5.92k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5819:6): [True: 2.63k, False: 3.28k]
  ------------------
 5820|  2.63k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5820:4): [True: 2.36k, False: 279]
  ------------------
 5821|  2.36k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5821:4): [True: 158, False: 2.20k]
  ------------------
 5822|    158|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5822:4): [True: 95, False: 63]
  ------------------
 5823|     95|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5823:4): [True: 76, False: 19]
  ------------------
 5824|     76|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|     76|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5825|     76|	}
 5826|       |
 5827|   361k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5827:14): [True: 355k, False: 5.92k]
  ------------------
 5828|   355k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  655|   355k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5828:7): [True: 118k, False: 236k]
  ------------------
 5829|   118k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|   124k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5830|       |	/*
 5831|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5832|       |	 * and PIV must be the default application.
 5833|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5834|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5835|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5836|       |	 *
 5837|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5838|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5839|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5840|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5841|       |	 */
 5842|       |
 5843|       |	/*
 5844|       |	 * if ATR matched or user forced card type
 5845|       |	 * test if PIV is active applet without using AID If fails try AID
 5846|       |	 */
 5847|       |
 5848|  5.92k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5848:6): [True: 838, False: 5.08k]
  ------------------
 5849|    838|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|    838|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5849:4): [True: 836, False: 2]
  ------------------
 5850|    836|		r = piv_find_discovery(card);
 5851|    836|		if (r < 0) {
  ------------------
  |  Branch (5851:7): [True: 519, False: 317]
  ------------------
 5852|    519|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5853|    519|			r = piv_find_aid(card);
 5854|    519|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  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: 143, False: 376]
  |  |  |  |  ------------------
  |  |  |  |  179|    143|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    143|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    143|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    143|		goto err; \
  |  |  |  |  182|    143|	} \
  |  |  |  |  183|    519|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 376]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5855|    519|		}
 5856|  5.08k|	} else {
 5857|       |		/* piv_find_aid saves al_label from response */
 5858|  5.08k|		r = piv_find_aid(card);
 5859|  5.08k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  5.08k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.08k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.08k|	int _ret = (r); \
  |  |  |  |  178|  5.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.65k, False: 425]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.65k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.65k|		goto err; \
  |  |  |  |  182|  4.65k|	} \
  |  |  |  |  183|  5.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 425]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5860|  5.08k|	}
 5861|       |
 5862|       |	/* Know to be PIV card but not the type */
 5863|       |
 5864|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5865|  1.11k|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5865:6): [True: 18, False: 1.10k]
  |  Branch (5865:24): [True: 14, False: 4]
  ------------------
 5866|     14|		switch (card->type) {
  ------------------
  |  Branch (5866:11): [True: 13, False: 1]
  ------------------
 5867|     13|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5867:3): [True: 13, False: 1]
  ------------------
 5868|     13|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5868:3): [True: 0, False: 14]
  ------------------
 5869|     36|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5869:16): [True: 25, False: 11]
  ------------------
 5870|     25|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5870:9): [True: 23, False: 2]
  ------------------
 5871|     23|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5871:7): [True: 2, False: 21]
  ------------------
 5872|      2|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_type);
  ------------------
  |  |   70|      2|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5873|      2|					card->type = al_map[i].al_type;
 5874|      2|					break;
 5875|      2|				}
 5876|     25|			}
 5877|     13|			break;
 5878|     14|		}
 5879|     14|	}
 5880|       |
 5881|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5882|  1.11k|			card->type, priv->card_issues, r, priv->alg_ids);
 5883|       |
 5884|       |	/*
 5885|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5886|       |	 * via ATR, ATR Historic bytes or Application Label
 5887|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5888|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5889|       |	 */
 5890|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (5890:10): [True: 949, False: 169]
  ------------------
 5891|    305|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5891:2): [True: 305, False: 813]
  ------------------
 5892|    505|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5892:2): [True: 200, False: 918]
  ------------------
 5893|    522|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5893:2): [True: 17, False: 1.10k]
  ------------------
 5894|    524|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5894:2): [True: 2, False: 1.11k]
  ------------------
 5895|    525|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5895:2): [True: 1, False: 1.11k]
  ------------------
 5896|    526|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5896:2): [True: 1, False: 1.11k]
  ------------------
 5897|    526|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5897:2): [True: 0, False: 1.11k]
  ------------------
 5898|    949|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5898:2): [True: 423, False: 695]
  ------------------
 5899|    949|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    949|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5900|    949|		apdu.lc = 0;
 5901|    949|		apdu.data = NULL;
 5902|    949|		apdu.datalen = 0;
 5903|    949|		apdu.resp = yubico_version_buf;
 5904|    949|		apdu.resplen = sizeof(yubico_version_buf);
 5905|    949|		apdu.le = apdu.resplen;
 5906|    949|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5907|    949|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  1.89k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5907:7): [True: 945, False: 4]
  |  Branch (5907:27): [True: 550, False: 395]
  ------------------
 5908|    550|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5909|    550|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    550|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5910|    550|			if (priv->yubico_version == 1) {
  ------------------
  |  Branch (5910:8): [True: 6, False: 544]
  ------------------
 5911|      6|				sc_log(card->ctx, "Detected Alpha/development version of yubikey. Assuming v6");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5912|      6|				priv->yubico_version = 0x060000;
 5913|      6|			}
 5914|    550|		}
 5915|    949|		break;
 5916|  1.11k|	}
 5917|       |
 5918|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5919|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5920|       |
 5921|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5922|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5923|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (5923:10): [True: 511, False: 607]
  ------------------
 5924|       |	/*
 5925|       |	 * For cards that may also be CAC, try and read the CCC
 5926|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5927|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5928|       |	 */
 5929|    423|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5929:2): [True: 423, False: 695]
  ------------------
 5930|    423|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5930:2): [True: 0, False: 1.11k]
  ------------------
 5931|    508|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5931:2): [True: 85, False: 1.03k]
  ------------------
 5932|    508|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5932:2): [True: 0, False: 1.11k]
  ------------------
 5933|    508|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5933:2): [True: 0, False: 1.11k]
  ------------------
 5934|    511|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5934:2): [True: 3, False: 1.11k]
  ------------------
 5935|    511|		r2 = piv_process_ccc(card);
 5936|    511|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    511|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5937|    511|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5938|       |		/* Ignore any error. */
 5939|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5940|    511|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    511|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5940:7): [True: 6, False: 505]
  ------------------
 5941|      6|			switch (card->type) {
  ------------------
  |  Branch (5941:12): [True: 6, False: 0]
  ------------------
 5942|      1|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5942:4): [True: 1, False: 5]
  ------------------
 5943|      1|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5943:4): [True: 0, False: 6]
  ------------------
 5944|      5|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5944:4): [True: 4, False: 2]
  ------------------
 5945|      5|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5945:4): [True: 0, False: 6]
  ------------------
 5946|      5|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5947|      5|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      5|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5948|      5|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      5|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5949|      5|				break;
 5950|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5950:4): [True: 0, False: 6]
  ------------------
 5951|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5952|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5953|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5954|      0|				break;
 5955|      1|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5955:4): [True: 1, False: 5]
  ------------------
 5956|      1|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5957|      1|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      1|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5958|      1|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      1|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5959|      1|				break;
 5960|      6|			}
 5961|      6|		}
 5962|    511|		break;
 5963|       |
 5964|    511|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5964:2): [True: 0, False: 1.11k]
  ------------------
 5965|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5965:2): [True: 0, False: 1.11k]
  ------------------
 5966|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5966:2): [True: 0, False: 1.11k]
  ------------------
 5967|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5968|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5969|      0|		break;
 5970|  1.11k|	}
 5971|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5972|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5973|       |
 5974|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5975|  1.11k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  380|  1.11k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  385|    317|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5975:6): [True: 317, False: 801]
  |  Branch (5975:51): [True: 0, False: 317]
  ------------------
 5976|      0|		r2 = piv_find_aid(card);
 5977|      0|	}
 5978|       |
 5979|       |	/* Read AID if needed for these cards types */
 5980|  1.11k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|  1.11k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5980:6): [True: 317, False: 801]
  ------------------
 5981|    317|		switch (card->type) {
  ------------------
  |  Branch (5981:11): [True: 18, False: 299]
  ------------------
 5982|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5982:3): [True: 0, False: 317]
  ------------------
 5983|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5983:3): [True: 0, False: 317]
  ------------------
 5984|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5984:3): [True: 0, False: 317]
  ------------------
 5985|     17|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5985:3): [True: 17, False: 300]
  ------------------
 5986|     18|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5986:3): [True: 1, False: 316]
  ------------------
 5987|     18|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5987:3): [True: 0, False: 317]
  ------------------
 5988|     18|		case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5988:3): [True: 0, False: 317]
  ------------------
 5989|       |
 5990|     18|			r2 = piv_find_aid(card);
 5991|    317|		}
 5992|    317|	}
 5993|       |
 5994|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5995|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5996|       |
 5997|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5998|  1.11k|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  617|  1.11k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  608|  1.11k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  609|  1.11k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  610|  1.11k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  612|  1.11k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  613|  1.11k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5998:6): [True: 1.11k, False: 2]
  ------------------
 5999|  1.11k|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  617|  1.11k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  608|  1.11k|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  609|  1.11k|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  610|  1.11k|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  612|  1.11k|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  613|  1.11k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 6000|  1.11k|	}
 6001|       |
 6002|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 6003|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (6003:10): [True: 422, False: 696]
  ------------------
 6004|    422|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6004:2): [True: 422, False: 696]
  ------------------
 6005|    422|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6005:2): [True: 0, False: 1.11k]
  ------------------
 6006|    422|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|    422|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (6006:7): [True: 0, False: 422]
  ------------------
 6007|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6008|      0|		}
 6009|       |
 6010|       |#ifdef ENABLE_PIV_SM
 6011|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 6012|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 6013|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6014|       |		}
 6015|       |#endif
 6016|    422|		break;
 6017|  1.11k|	}
 6018|       |
 6019|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6020|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6021|       |
 6022|       |	/*
 6023|       |	 * Set card_issues flags based card->type and version numbers if available.
 6024|       |	 *
 6025|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 6026|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 6027|       |	 * access to all the different devices or versions of the devices.
 6028|       |	 * Vendor and user input is welcome on any compliance issues.
 6029|       |	 *
 6030|       |	 * For the Yubico devices The assumption is also made that if a bug is
 6031|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 6032|       |	 *
 6033|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 6034|       |	 * may be set earlier or later then in the following code.
 6035|       |	 */
 6036|       |
 6037|  1.11k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  1.11k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6038|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6039|  1.11k|	switch (card->type) {
 6040|    305|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (6040:2): [True: 305, False: 813]
  ------------------
 6041|    305|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  603|    305|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 6042|    305|				     CI_VERIFY_630X |
  ------------------
  |  |  591|    305|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 6043|    305|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|    305|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6044|    305|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  596|    305|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6045|    305|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  601|    305|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 6046|    305|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6046:7): [True: 202, False: 103]
  ------------------
 6047|    202|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|    202|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6048|    305|		break;
 6049|       |
 6050|      1|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (6050:2): [True: 1, False: 1.11k]
  ------------------
 6051|       |		/* also supports using yubico-piv-tool */
 6052|      1|		priv->card_issues |= CI_ENFORCES_EC_HASH_EQ_KEYSIZE |
  ------------------
  |  |  605|      1|#define CI_ENFORCES_EC_HASH_EQ_KEYSIZE	    0x00001000U /* Applet enforces hash size == EC field size for ECDSA. Windows issue */
  ------------------
 6053|      1|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|      1|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6054|      1|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  596|      1|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6055|      1|		break;
 6056|       |
 6057|    200|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (6057:2): [True: 200, False: 918]
  ------------------
 6058|    201|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (6058:2): [True: 1, False: 1.11k]
  ------------------
 6059|    203|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (6059:2): [True: 2, False: 1.11k]
  ------------------
 6060|    203|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|    203|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6061|    203|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  596|    203|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6062|    203|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6062:7): [True: 63, False: 140]
  ------------------
 6063|     63|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|     63|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6064|    203|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (6064:7): [True: 134, False: 69]
  ------------------
 6065|    134|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  611|    134|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  614|    134|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  615|    134|#define AI_X25519			    0x00200000U
  ------------------
 6066|    203|		break;
 6067|       |
 6068|     17|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (6068:2): [True: 17, False: 1.10k]
  ------------------
 6069|     17|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|     17|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6070|     17|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (6070:7): [True: 11, False: 6]
  ------------------
 6071|     11|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  611|     11|#define AI_RSA_4096			    0x00000008U
  ------------------
 6072|     17|		break;
 6073|       |
 6074|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (6074:2): [True: 0, False: 1.11k]
  ------------------
 6075|      2|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (6075:2): [True: 2, False: 1.11k]
  ------------------
 6076|      2|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (6076:2): [True: 0, False: 1.11k]
  ------------------
 6077|      2|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (6077:2): [True: 0, False: 1.11k]
  ------------------
 6078|      2|		priv->card_issues |= 0; /* could add others here */
 6079|      2|		break;
 6080|       |
 6081|    422|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6081:2): [True: 422, False: 696]
  ------------------
 6082|    503|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (6082:2): [True: 81, False: 1.03k]
  ------------------
 6083|    503|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (6083:2): [True: 0, False: 1.11k]
  ------------------
 6084|    503|		priv->card_issues |= 0; /* could add others here */
 6085|    503|		break;
 6086|       |
 6087|      5|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (6087:2): [True: 5, False: 1.11k]
  ------------------
 6088|      5|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (6088:2): [True: 0, False: 1.11k]
  ------------------
 6089|      6|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (6089:2): [True: 1, False: 1.11k]
  ------------------
 6090|      6|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      6|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6091|      6|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  598|      6|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6092|      6|				     CI_NO_RANDOM |
  ------------------
  |  |  594|      6|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6093|      6|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      6|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6094|      6|		break;
 6095|       |
 6096|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6096:2): [True: 0, False: 1.11k]
  ------------------
 6097|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6098|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6099|      0|		break;
 6100|       |
 6101|     81|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (6101:2): [True: 81, False: 1.03k]
  ------------------
 6102|     81|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|     81|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6103|     81|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  598|     81|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6104|     81|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  594|     81|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6105|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 6106|     81|		break;
 6107|       |
 6108|      0|	default:
  ------------------
  |  Branch (6108:2): [True: 0, False: 1.11k]
  ------------------
 6109|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6110|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6111|       |		/* opensc.conf may have it wrong, continue anyway */
 6112|      0|		sc_log(card->ctx, "Unknown PIV card->type %d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6113|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 6114|  1.11k|	}
 6115|  1.11k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|  1.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6116|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6117|       |
 6118|  1.11k|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  597|  1.11k|#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.11k|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (6118:6): [True: 1.11k, False: 6]
  |  Branch (6118:53): [True: 796, False: 316]
  ------------------
 6119|       |		/*
 6120|       |		 * We now know PIV AID is active, test DISCOVERY object again
 6121|       |		 * Some PIV don't support DISCOVERY and return
 6122|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 6123|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 6124|       |		 * to test for active AID.
 6125|       |		 */
 6126|    796|		r2 = piv_find_discovery(card);
 6127|       |
 6128|    796|		if (r2 < 0) {
  ------------------
  |  Branch (6128:7): [True: 693, False: 103]
  ------------------
 6129|    693|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|    693|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 6130|    693|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    693|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 6131|    693|		}
 6132|    796|	}
 6133|       |
 6134|  1.11k|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|  1.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6135|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6136|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 6137|  1.11k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.11k|	int _ret = r; \
  |  |  |  |  155|  1.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.11k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.11k|	return _ret; \
  |  |  |  |  163|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6138|       |
 6139|  4.80k|err:
 6140|  4.80k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH failed card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|  4.80k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6141|  4.80k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6142|       |	/* don't match. Does not have a PIV applet. */
 6143|  4.80k|	piv_finish(card);
 6144|  4.80k|	card->type = saved_type;
 6145|  4.80k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.80k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.80k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.80k|	int _ret = r; \
  |  |  |  |  155|  4.80k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.80k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.80k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.80k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.80k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.80k|	return _ret; \
  |  |  |  |  163|  4.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6146|  4.80k|}
card-piv.c:piv_find_discovery:
 5276|  5.83k|{
 5277|  5.83k|	int r = 0;
 5278|  5.83k|	size_t rbuflen;
 5279|  5.83k|	u8 *rbuf = NULL;
 5280|  5.83k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  5.83k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5281|       |
 5282|  5.83k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.83k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.83k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.83k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.83k]
  |  |  ------------------
  ------------------
 5283|       |
 5284|       |	/*
 5285|       |	 * During piv_card_reader_lock_obtained,
 5286|       |	 * we use the discovery object to test if card present, and
 5287|       |	 * if PIV AID is active.
 5288|       |	 */
 5289|  5.83k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  5.83k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5289:6): [True: 0, False: 5.83k]
  ------------------
 5290|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5291|      0|		goto end;
 5292|      0|	}
 5293|       |
 5294|       |	/* If not valid: read, test,  cache */
 5295|  5.83k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|  5.83k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5295:6): [True: 1.63k, False: 4.20k]
  ------------------
 5296|  1.63k|		r = piv_process_discovery(card);
 5297|  4.20k|	} else {
 5298|       |		/* if already in cache,force read */
 5299|  4.20k|		rbuflen = 1;
 5300|  4.20k|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5301|       |		/* if same response as last, no need to parse */
 5302|  4.20k|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5302:7): [True: 0, False: 4.20k]
  |  Branch (5302:17): [True: 0, False: 0]
  ------------------
 5303|      0|			goto end;
 5304|       |
 5305|  4.20k|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5305:7): [True: 45, False: 4.16k]
  |  Branch (5305:17): [True: 44, False: 1]
  ------------------
 5306|     44|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5306:5): [True: 44, False: 0]
  ------------------
 5307|     44|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5307:5): [True: 15, False: 29]
  ------------------
 5308|     15|			goto end;
 5309|     15|		}
 5310|       |		/* This should not happen  bad card */
 5311|  4.19k|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 5312|  4.19k|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  4.19k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5313|  4.19k|		goto end;
 5314|  4.20k|	}
 5315|       |
 5316|  5.83k|end:
 5317|  5.83k|	free(rbuf);
 5318|  5.83k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  5.83k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.83k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.83k|	int _ret = r; \
  |  |  |  |  155|  5.83k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.82k, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.40k, False: 420]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.82k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.82k|	} else { \
  |  |  |  |  159|     15|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     15|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     15|	} \
  |  |  |  |  162|  5.83k|	return _ret; \
  |  |  |  |  163|  5.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5319|  5.83k|}
card-piv.c:piv_process_discovery:
 5169|  1.63k|{
 5170|  1.63k|	int r;
 5171|  1.63k|	u8 *rbuf = NULL;
 5172|  1.63k|	size_t rbuflen = 0;
 5173|       |
 5174|  1.63k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5175|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5176|  1.63k|	if (r < 0)
  ------------------
  |  Branch (5176:6): [True: 1.15k, False: 477]
  ------------------
 5177|  1.15k|		goto err;
 5178|       |
 5179|       |	/* the object is now cached, see what we have */
 5180|    477|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5181|       |
 5182|  1.63k|err:
 5183|  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|  1.21k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.21k, False: 420]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5184|  1.63k|}
card-piv.c:piv_get_cached_data:
 3214|  16.0k|{
 3215|       |
 3216|  16.0k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  16.0k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3217|  16.0k|	int r;
 3218|  16.0k|	u8 *rbuf = NULL;
 3219|  16.0k|	size_t rbuflen;
 3220|       |
 3221|  16.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.0k]
  |  |  ------------------
  ------------------
 3222|       |
 3223|  16.0k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3223:6): [True: 0, False: 16.0k]
  |  Branch (3223:21): [True: 0, False: 16.0k]
  ------------------
 3224|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3225|       |
 3226|  16.0k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3227|       |
 3228|       |	/* see if we have it cached */
 3229|  16.0k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  16.0k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3229:6): [True: 2.35k, False: 13.6k]
  ------------------
 3230|       |
 3231|  2.35k|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3232|  2.35k|				enumtag,
 3233|  2.35k|				priv->obj_cache[enumtag].obj_data,
 3234|  2.35k|				priv->obj_cache[enumtag].obj_len,
 3235|  2.35k|				priv->obj_cache[enumtag].internal_obj_data,
 3236|  2.35k|				priv->obj_cache[enumtag].internal_obj_len);
 3237|       |
 3238|  2.35k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3238:7): [True: 0, False: 2.35k]
  ------------------
 3239|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3240|      0|			sc_log(card->ctx, "#%d found but len=0", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3241|      0|			goto err;
 3242|      0|		}
 3243|  2.35k|		*buf = priv->obj_cache[enumtag].obj_data;
 3244|  2.35k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3245|  2.35k|		r = (int)*buf_len;
 3246|  2.35k|		goto ok;
 3247|  2.35k|	}
 3248|       |
 3249|       |	/*
 3250|       |	 * If we know it can not be on the card  i.e. History object
 3251|       |	 * has been read, and we know what other certs may or
 3252|       |	 * may not be on the card. We can avoid extra overhead
 3253|       |	 * Also used if object on card was not parsable
 3254|       |	 */
 3255|       |
 3256|  13.6k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  13.6k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3256:6): [True: 0, False: 13.6k]
  ------------------
 3257|      0|		sc_log(card->ctx, "no_obj #%d", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3258|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3259|      0|		goto err;
 3260|      0|	}
 3261|       |
 3262|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3263|  13.6k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  13.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3264|  13.6k|	rbuflen = 1;
 3265|  13.6k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3266|  13.6k|	if (r > 0) {
  ------------------
  |  Branch (3266:6): [True: 3.39k, False: 10.2k]
  ------------------
 3267|  3.39k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  3.39k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3268|  3.39k|		priv->obj_cache[enumtag].obj_len = r;
 3269|  3.39k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3270|  3.39k|		*buf = rbuf;
 3271|  3.39k|		*buf_len = r;
 3272|       |
 3273|  3.39k|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|  3.39k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3274|  3.39k|				enumtag,
 3275|  3.39k|				priv->obj_cache[enumtag].obj_data,
 3276|  3.39k|				priv->obj_cache[enumtag].obj_len,
 3277|  3.39k|				priv->obj_cache[enumtag].internal_obj_data,
 3278|  3.39k|				priv->obj_cache[enumtag].internal_obj_len);
 3279|       |
 3280|  10.2k|	} else {
 3281|  10.2k|		free(rbuf);
 3282|  10.2k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  10.2k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3282:7): [True: 0, False: 10.2k]
  |  Branch (3282:17): [True: 1.92k, False: 8.35k]
  ------------------
 3283|  1.92k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.92k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3284|  1.92k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.92k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3285|  1.92k|			priv->obj_cache[enumtag].obj_len = 0;
 3286|  8.35k|		} else {
 3287|  8.35k|			goto err;
 3288|  8.35k|		}
 3289|  10.2k|	}
 3290|  7.67k|ok:
 3291|       |
 3292|  16.0k|err:
 3293|  16.0k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  16.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.0k|	int _ret = r; \
  |  |  |  |  155|  16.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.2k, False: 5.74k]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.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|  10.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.2k|	} else { \
  |  |  |  |  159|  5.74k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  5.74k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  5.74k|	} \
  |  |  |  |  162|  16.0k|	return _ret; \
  |  |  |  |  163|  16.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3294|  16.0k|}
card-piv.c:piv_parse_discovery:
 5113|    477|{
 5114|    477|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|    477|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5115|    477|	int r = 0;
 5116|    477|	const u8 *body;
 5117|    477|	size_t bodylen;
 5118|    477|	const u8 *aid;
 5119|    477|	size_t aidlen;
 5120|    477|	const u8 *pinp;
 5121|    477|	size_t pinplen;
 5122|    477|	unsigned int cla_out, tag_out;
 5123|       |
 5124|    477|	if (rbuflen != 0) {
  ------------------
  |  Branch (5124:6): [True: 477, False: 0]
  ------------------
 5125|    477|		body = rbuf;
 5126|    477|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    954|#define SC_SUCCESS				0
  ------------------
  |  Branch (5126:7): [True: 0, False: 477]
  ------------------
 5127|    477|				body == NULL ||
  ------------------
  |  Branch (5127:5): [True: 0, False: 477]
  ------------------
 5128|    477|				bodylen == 0 ||
  ------------------
  |  Branch (5128:5): [True: 4, False: 473]
  ------------------
 5129|    473|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5129:5): [True: 0, False: 473]
  ------------------
 5130|      4|			sc_log(card->ctx, "DER problem %d", 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__
  |  |  ------------------
  ------------------
 5131|      4|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5132|      4|			goto err;
 5133|      4|		}
 5134|       |
 5135|    473|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   71|    473|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5136|    473|				cla_out, tag_out, body, bodylen);
 5137|    473|		aidlen = 0;
 5138|    473|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5139|    473|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5139:7): [True: 7, False: 466]
  |  Branch (5139:22): [True: 3, False: 463]
  ------------------
 5140|    463|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5140:5): [True: 43, False: 420]
  ------------------
 5141|     53|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5142|     53|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     53|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 5143|     53|			goto err;
 5144|     53|		}
 5145|    420|		if (aid_only == 0) {
  ------------------
  |  Branch (5145:7): [True: 420, False: 0]
  ------------------
 5146|    420|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5147|    420|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5147:8): [True: 234, False: 186]
  |  Branch (5147:16): [True: 229, False: 5]
  ------------------
 5148|    229|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|    229|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5149|    229|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5150|    229|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   71|    229|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5151|    229|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    229|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    229|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    229|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    229|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5151:9): [True: 6, False: 223]
  ------------------
 5152|      6|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|      6|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5152:7): [True: 4, False: 2]
  ------------------
 5153|      4|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5154|      4|					priv->pin_preference = 0x00;
 5155|      4|				}
 5156|    229|			}
 5157|    420|		}
 5158|    420|		r = SC_SUCCESS;
  ------------------
  |  |   28|    420|#define SC_SUCCESS				0
  ------------------
 5159|    420|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|    420|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5160|    420|	}
 5161|       |
 5162|    477|err:
 5163|    477|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    477|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    477|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    477|	int _ret = r; \
  |  |  |  |  155|    477|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 477, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    477|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 420]
  |  |  |  |  ------------------
  |  |  |  |  157|    477|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    477|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    477|	return _ret; \
  |  |  |  |  163|    477|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5164|    477|}
card-piv.c:piv_get_data:
 3104|  17.9k|{
 3105|  17.9k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  17.9k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3106|  17.9k|	u8 *p;
 3107|  17.9k|	u8 *tbuf;
 3108|  17.9k|	int r = 0;
 3109|  17.9k|	u8 tagbuf[8];
 3110|  17.9k|	size_t tag_len;
 3111|  17.9k|	int alloc_buf = 0;
 3112|       |
 3113|  17.9k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  17.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  17.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  17.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 17.9k]
  |  |  ------------------
  ------------------
 3114|       |
 3115|  17.9k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
 3116|       |
 3117|  17.9k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3118|  17.9k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  17.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3118:6): [True: 0, False: 17.9k]
  ------------------
 3119|      0|		sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3120|      0|		return r;
 3121|      0|	}
 3122|       |
 3123|  17.9k|	tag_len = piv_objects[enumtag].tag_len;
 3124|       |
 3125|  17.9k|	p = tagbuf;
 3126|  17.9k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3127|  17.9k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  17.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3127:6): [True: 0, False: 17.9k]
  ------------------
 3128|      0|		sc_log(card->ctx, "Failed to encode ASN1 tag");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3129|      0|		goto err;
 3130|      0|	}
 3131|       |
 3132|  17.9k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3132:6): [True: 17.8k, False: 39]
  |  Branch (3132:23): [True: 17.8k, False: 0]
  ------------------
 3133|  17.8k|		*buf_len = priv->max_object_size; /* will allocate below */
 3134|  17.8k|		alloc_buf = 1;
 3135|  17.8k|	}
 3136|       |
 3137|  17.9k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
 3138|  17.9k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3138:6): [True: 17.8k, False: 39]
  |  Branch (3138:22): [True: 17.8k, False: 0]
  ------------------
 3139|  17.8k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  17.8k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3139:7): [True: 0, False: 17.8k]
  ------------------
 3140|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3141|      0|			goto err;
 3142|      0|		}
 3143|  17.8k|		*buf = malloc(*buf_len);
 3144|  17.8k|		if (*buf == NULL) {
  ------------------
  |  Branch (3144:7): [True: 0, False: 17.8k]
  ------------------
 3145|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3146|      0|			goto err;
 3147|      0|		}
 3148|  17.8k|	}
 3149|       |
 3150|       |#ifdef ENABLE_PIV_SM
 3151|       |	/*
 3152|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3153|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3154|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3155|       |	 * i.e. no interference from other applications
 3156|       |	 */
 3157|       |	sc_log(card->ctx, "enumtag:%d sm_ctx.sm_mode:%d piv_objects[enumtag].flags:0x%8.8x sm_flags:0x%8.8lx it_flags:0x%8.8x",
 3158|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3159|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3160|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3161|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3162|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3163|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3164|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3165|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3166|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3167|       |	}
 3168|       |
 3169|       |#endif /* ENABLE_PIV_SM */
 3170|  17.9k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3171|  17.9k|	if (r > 0) {
  ------------------
  |  Branch (3171:6): [True: 4.73k, False: 13.1k]
  ------------------
 3172|  4.73k|		int r_tag;
 3173|  4.73k|		unsigned int cla_out, tag_out;
 3174|  4.73k|		size_t bodylen = 0;
 3175|  4.73k|		const u8 *body = *buf;
 3176|  4.73k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3177|  4.73k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  9.46k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3177:7): [True: 735, False: 3.99k]
  |  Branch (3177:30): [True: 107, False: 3.89k]
  ------------------
 3178|  3.89k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3178:5): [True: 452, False: 3.43k]
  ------------------
 3179|  1.29k|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 3180|  1.29k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.29k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3181|  1.29k|			goto err;
 3182|  1.29k|		}
 3183|  3.43k|		*buf_len = (body - *buf) + bodylen;
 3184|  13.1k|	} else if (r == 0) {
  ------------------
  |  Branch (3184:13): [True: 588, False: 12.5k]
  ------------------
 3185|    588|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    588|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3186|    588|		goto err;
 3187|  12.5k|	} else {
 3188|  12.5k|		goto err;
 3189|  12.5k|	}
 3190|       |
 3191|  3.43k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3191:6): [True: 3.43k, False: 2]
  |  Branch (3191:19): [True: 3.43k, False: 0]
  ------------------
 3192|  3.43k|		tbuf = malloc(r);
 3193|  3.43k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3193:7): [True: 0, False: 3.43k]
  ------------------
 3194|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3195|      0|			goto err;
 3196|      0|		}
 3197|  3.43k|		memcpy(tbuf, *buf, r);
 3198|  3.43k|		free(*buf);
 3199|  3.43k|		alloc_buf = 0;
 3200|  3.43k|		*buf = tbuf;
 3201|  3.43k|	}
 3202|       |
 3203|  17.9k|err:
 3204|  17.9k|	if (alloc_buf) {
  ------------------
  |  Branch (3204:6): [True: 14.4k, False: 3.47k]
  ------------------
 3205|  14.4k|		free(*buf);
 3206|  14.4k|		*buf = NULL;
 3207|  14.4k|	}
 3208|  17.9k|	sc_unlock(card);
 3209|  17.9k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  17.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.9k|	int _ret = r; \
  |  |  |  |  155|  17.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.4k, False: 3.43k]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.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|  14.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.4k|	} else { \
  |  |  |  |  159|  3.43k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.43k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.43k|	} \
  |  |  |  |  162|  17.9k|	return _ret; \
  |  |  |  |  163|  17.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3210|  17.9k|}
card-piv.c:piv_general_io:
 1803|  32.3k|{
 1804|  32.3k|	int r, cse;
 1805|  32.3k|	sc_apdu_t apdu;
 1806|       |
 1807|  32.3k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  32.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  32.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  32.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 32.3k]
  |  |  ------------------
  ------------------
 1808|       |
 1809|  32.3k|	r = sc_lock(card);
 1810|  32.3k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  32.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1810:6): [True: 0, False: 32.3k]
  ------------------
 1811|  32.3k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|       |
 1813|  32.3k|	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  294|  21.3k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  292|  11.0k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (1813:8): [True: 32.3k, False: 0]
  |  Branch (1813:19): [True: 21.3k, False: 11.0k]
  ------------------
 1814|  32.3k|			(sendbuf ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_1);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              			(sendbuf ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_1);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (1814:5): [True: 0, False: 0]
  ------------------
 1815|       |
 1816|  32.3k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
 1817|  32.3k|	if (sendbuflen > 255) {
  ------------------
  |  Branch (1817:6): [True: 206, False: 32.1k]
  ------------------
 1818|    206|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    206|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1819|       |#ifdef ENABLE_PIV_SM
 1820|       |		if (card->sm_ctx.sm_mode != SM_MODE_NONE) {
 1821|       |			/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1822|       |			apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1823|       |		}
 1824|       |#endif
 1825|    206|	}
 1826|  32.3k|	apdu.lc = sendbuflen;
 1827|  32.3k|	apdu.datalen = sendbuflen;
 1828|  32.3k|	apdu.data = sendbuf;
 1829|       |
 1830|  32.3k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1830:6): [True: 32.3k, False: 0]
  |  Branch (1830:17): [True: 32.3k, False: 0]
  ------------------
 1831|  32.3k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1831:13): [True: 32.3k, False: 39]
  ------------------
 1832|  32.3k|		apdu.resplen = recvbuflen;
 1833|  32.3k|	} else {
 1834|      0|		apdu.le = 0;
 1835|      0|		apdu.resplen = 0;
 1836|      0|	}
 1837|  32.3k|	apdu.resp = recvbuf;
 1838|       |
 1839|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1840|  32.3k|	r = sc_transmit_apdu(card, &apdu);
 1841|       |
 1842|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1843|  32.3k|	if (r < 0) {
  ------------------
  |  Branch (1843:6): [True: 818, False: 31.5k]
  ------------------
 1844|    818|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    818|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1845|    818|		goto err;
 1846|    818|	}
 1847|       |
 1848|  31.5k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1848:6): [True: 282, False: 31.2k]
  |  Branch (1848:26): [True: 25, False: 257]
  ------------------
 1849|     25|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     25|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1850|  31.5k|	else
 1851|  31.5k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1852|       |
 1853|  31.5k|	if (r < 0) {
  ------------------
  |  Branch (1853:6): [True: 24.3k, False: 7.16k]
  ------------------
 1854|  24.3k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  24.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1855|  24.3k|		goto err;
 1856|  24.3k|	}
 1857|       |
 1858|  7.16k|	r = (int)apdu.resplen;
 1859|       |
 1860|  32.3k|err:
 1861|  32.3k|	sc_unlock(card);
 1862|  32.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  32.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  32.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  32.3k|	int _ret = r; \
  |  |  |  |  155|  32.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.2k, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  |  156|  26.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|  25.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25.2k, False: 1.05k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.2k|	} else { \
  |  |  |  |  159|  6.10k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  6.10k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  6.10k|	} \
  |  |  |  |  162|  32.3k|	return _ret; \
  |  |  |  |  163|  32.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1863|  32.3k|}
card-piv.c:piv_obj_cache_free_entry:
 5573|   356k|{
 5574|   356k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|   356k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5575|       |
 5576|   356k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5576:6): [True: 3.39k, False: 353k]
  ------------------
 5577|  3.39k|		free(priv->obj_cache[enumtag].obj_data);
 5578|   356k|	priv->obj_cache[enumtag].obj_data = NULL;
 5579|   356k|	priv->obj_cache[enumtag].obj_len = 0;
 5580|       |
 5581|   356k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5581:6): [True: 2.35k, False: 354k]
  ------------------
 5582|  2.35k|		free(priv->obj_cache[enumtag].internal_obj_data);
 5583|   356k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5584|   356k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5585|   356k|	priv->obj_cache[enumtag].flags = flags;
 5586|       |
 5587|   356k|	return SC_SUCCESS;
  ------------------
  |  |   28|   356k|#define SC_SUCCESS				0
  ------------------
 5588|   356k|}
card-piv.c:piv_find_aid:
 2915|  6.70k|{
 2916|  6.70k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  6.70k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2917|  6.70k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2918|  6.70k|	int r, i, j;
 2919|  6.70k|	const u8 *tag;
 2920|  6.70k|	size_t taglen;
 2921|  6.70k|	const u8 *nextac;
 2922|  6.70k|	const u8 *next80;
 2923|  6.70k|	const u8 *pix;
 2924|  6.70k|	size_t pixlen;
 2925|  6.70k|	const u8 *al_label;
 2926|  6.70k|	size_t al_labellen;
 2927|  6.70k|	const u8 *actag; /* Cipher Suite */
 2928|  6.70k|	size_t actaglen;
 2929|  6.70k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2930|  6.70k|	size_t csailen;
 2931|  6.70k|	size_t resplen = sizeof(rbuf);
 2932|       |#ifdef ENABLE_PIV_SM
 2933|       |	int found_csai = 0;
 2934|       |#endif
 2935|       |
 2936|  6.70k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.70k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.70k]
  |  |  ------------------
  ------------------
 2937|       |
 2938|       |	/* first  see if the default application will return a template
 2939|       |	 * that we know about.
 2940|       |	 */
 2941|       |
 2942|  6.70k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2943|  6.70k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2943:6): [True: 0, False: 6.70k]
  |  Branch (2943:15): [True: 0, False: 0]
  |  Branch (2943:38): [True: 0, False: 0]
  |  Branch (2943:70): [True: 0, False: 0]
  ------------------
 2944|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2945|       |		/* no need to parse again, same as last time */
 2946|      0|	}
 2947|  6.70k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2947:6): [True: 999, False: 5.70k]
  |  Branch (2947:16): [True: 922, False: 77]
  ------------------
 2948|    922|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2949|    922|		if (tag != NULL) {
  ------------------
  |  Branch (2949:7): [True: 873, False: 49]
  ------------------
 2950|    873|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|    873|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2951|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2952|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2953|       |			 * where xx is the SM csID either 27 or 2E.
 2954|       |			 * Some vendors may include entries for supported Algorithms even when
 2955|       |			 * not required. We will use these if possible
 2956|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2957|       |			 */
 2958|    873|			nextac = tag;
 2959|    916|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2959:11): [True: 43, False: 873]
  ------------------
 2960|    916|						0xAC, &actaglen)) != NULL) {
 2961|     43|				nextac = actag + actaglen;
 2962|       |
 2963|     43|				next80 = actag;
 2964|    116|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2964:12): [True: 73, False: 43]
  ------------------
 2965|    116|							0x80, &csailen)) != NULL) {
 2966|     73|					next80 = csai + csailen;
 2967|     73|					if (csailen == 1) {
  ------------------
  |  Branch (2967:10): [True: 31, False: 42]
  ------------------
 2968|     31|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2969|     31|						j = piv_ai_map_find_by_id(card, *csai);
 2970|     31|						if (j >= 0) {
  ------------------
  |  Branch (2970:11): [True: 19, False: 12]
  ------------------
 2971|     19|							priv->alg_ids |= ai_map[j].ai_flag;
 2972|     19|							continue;
 2973|     19|						}
 2974|       |#ifdef ENABLE_PIV_SM
 2975|       |						/* check if id is NIST SM */
 2976|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2977|       |							if (*csai != css[i].id)
 2978|       |								continue;
 2979|       |							if (found_csai) {
 2980|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2981|       |							} else {
 2982|       |								priv->cs = &css[i];
 2983|       |								priv->csID = *csai;
 2984|       |								found_csai++;
 2985|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2986|       |							}
 2987|       |						}
 2988|       |#endif /* ENABLE_PIV_SM */
 2989|     31|					}
 2990|     73|				}
 2991|     43|			}
 2992|       |
 2993|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2994|    873|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2995|    873|			if (al_label != NULL) {
  ------------------
  |  Branch (2995:8): [True: 19, False: 854]
  ------------------
 2996|     19|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|     19|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     19|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2997|     19|				free(priv->al_label);
 2998|     19|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2998:9): [True: 0, False: 19]
  ------------------
 2999|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3000|      0|				}
 3001|     19|				memcpy(priv->al_label, al_label, al_labellen);
 3002|     19|				priv->al_labellen = (int)al_labellen;
 3003|     19|			}
 3004|       |
 3005|    873|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 3006|    873|			if (pix != NULL) {
  ------------------
  |  Branch (3006:8): [True: 833, False: 40]
  ------------------
 3007|    833|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    833|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3008|       |
 3009|       |				/* early cards returned full AID, rather then just the pix */
 3010|    906|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (3010:17): [True: 878, False: 28]
  ------------------
 3011|    878|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (3011:11): [True: 870, False: 8]
  ------------------
 3012|    870|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (3012:12): [True: 498, False: 372]
  ------------------
 3013|    380|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3013:10): [True: 365, False: 15]
  |  Branch (3013:45): [True: 307, False: 58]
  ------------------
 3014|    805|													     piv_aids[i].len_short) == 0))) {
 3015|    805|						free(priv->aid_der.value); /* free previous value if any */
 3016|    805|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3016:11): [True: 0, False: 805]
  ------------------
 3017|      0|							LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3018|      0|						}
 3019|    805|						memcpy(priv->aid_der.value, rbuf, resplen);
 3020|    805|						priv->aid_der.len = resplen;
 3021|    805|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  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: 788, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  156|    788|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 788]
  |  |  |  |  ------------------
  |  |  |  |  157|    788|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    788|	} else { \
  |  |  |  |  159|     17|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     17|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     17|	} \
  |  |  |  |  162|    805|	return _ret; \
  |  |  |  |  163|    805|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3022|    805|					}
 3023|    878|				}
 3024|    833|			}
 3025|    873|		}
 3026|    922|	}
 3027|       |
 3028|  5.89k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  5.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.89k|	int _ret = r; \
  |  |  |  |  155|  5.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.89k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.89k|	return _ret; \
  |  |  |  |  163|  5.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3029|  5.89k|}
card-piv.c:piv_ai_map_find_by_id:
 2898|     31|{
 2899|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2900|     31|	int i;
 2901|       |
 2902|    194|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2902:14): [True: 182, False: 12]
  ------------------
 2903|    182|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2903:7): [True: 19, False: 163]
  ------------------
 2904|     19|			return i;
 2905|    182|	}
 2906|     12|	return -1;
 2907|     31|}
card-piv.c:piv_process_ccc:
 5257|    511|{
 5258|    511|	int r = 0;
 5259|    511|	u8 *rbuf = NULL;
 5260|    511|	size_t rbuflen = 0;
 5261|       |
 5262|    511|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    511|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    511|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    511|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 511]
  |  |  ------------------
  ------------------
 5263|    511|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5264|       |
 5265|    511|	if (r < 0)
  ------------------
  |  Branch (5265:6): [True: 454, False: 57]
  ------------------
 5266|    454|		goto err;
 5267|       |
 5268|       |	/* the object is now cached, see what we have */
 5269|     57|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5270|    511|err:
 5271|    511|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    511|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    511|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    511|	int _ret = r; \
  |  |  |  |  155|    511|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 511, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    511|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    503|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 503, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  157|    511|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    511|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    511|	return _ret; \
  |  |  |  |  163|    511|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5272|    511|}
card-piv.c:piv_parse_ccc:
 5193|     57|{
 5194|     57|	int r = 0;
 5195|     57|	const u8 *body;
 5196|     57|	size_t bodylen;
 5197|     57|	unsigned int cla_out, tag_out;
 5198|       |
 5199|     57|	u8 tag;
 5200|     57|	const u8 *end;
 5201|     57|	size_t len;
 5202|       |
 5203|     57|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     57|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5204|       |
 5205|     57|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     57|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     57|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     57|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 57]
  |  |  ------------------
  ------------------
 5206|       |
 5207|     57|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5207:6): [True: 0, False: 57]
  |  Branch (5207:22): [True: 0, False: 57]
  ------------------
 5208|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 5209|      0|		goto err;
 5210|      0|	}
 5211|       |
 5212|       |	/* Outer layer is a DER tlv */
 5213|     57|	body = rbuf;
 5214|     57|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    114|#define SC_SUCCESS				0
  ------------------
  |  Branch (5214:6): [True: 0, False: 57]
  ------------------
 5215|     57|			body == NULL ||
  ------------------
  |  Branch (5215:4): [True: 0, False: 57]
  ------------------
 5216|     57|			bodylen == 0 ||
  ------------------
  |  Branch (5216:4): [True: 3, False: 54]
  ------------------
 5217|     54|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5217:4): [True: 0, False: 54]
  ------------------
 5218|      3|		sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5219|      3|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5220|      3|		goto err;
 5221|      3|	}
 5222|       |
 5223|     54|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     54|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5224|       |
 5225|       |	/* CCC  entries are simple tlv */
 5226|     54|	end = body + bodylen;
 5227|    625|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5227:9): [True: 617, False: 8]
  ------------------
 5228|    617|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5229|    617|		if (r < 0)
  ------------------
  |  Branch (5229:7): [True: 46, False: 571]
  ------------------
 5230|     46|			goto err;
 5231|    571|		switch (tag) {
  ------------------
  |  Branch (5231:11): [True: 98, False: 473]
  ------------------
 5232|     63|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|     63|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5232:3): [True: 63, False: 508]
  ------------------
 5233|     63|			if (len == 0x15) {
  ------------------
  |  Branch (5233:8): [True: 44, False: 19]
  ------------------
 5234|     44|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5234:9): [True: 10, False: 34]
  ------------------
 5235|     10|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|     10|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5236|     34|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5236:14): [True: 10, False: 24]
  ------------------
 5237|     10|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|     10|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5238|     44|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5238:9): [True: 7, False: 37]
  ------------------
 5239|      7|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|      7|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5240|     44|			}
 5241|     63|			break;
 5242|     35|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|     35|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5242:3): [True: 35, False: 536]
  ------------------
 5243|     35|			if (len == 0x10) {
  ------------------
  |  Branch (5243:8): [True: 24, False: 11]
  ------------------
 5244|     24|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5244:9): [True: 12, False: 12]
  ------------------
 5245|     12|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|     12|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5246|     24|			}
 5247|     35|			break;
 5248|    571|		}
 5249|    571|	}
 5250|       |
 5251|     57|err:
 5252|     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|     49|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5253|     57|}
card-piv.c:piv_init:
 6150|  1.11k|{
 6151|  1.11k|	int r = 0;
 6152|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6153|  1.11k|	unsigned long flags;
 6154|  1.11k|	unsigned long flags_eddsa;
 6155|  1.11k|	unsigned long flags_xeddsa;
 6156|  1.11k|	unsigned long ext_flags;
 6157|       |
 6158|  1.11k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.11k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.11k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.11k]
  |  |  ------------------
  ------------------
 6159|       |
 6160|  1.11k|	r = sc_lock(card); /* hold until match or init is complete */
 6161|  1.11k|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|  1.11k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.11k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.11k|	int _ret = (r); \
  |  |  |  |  168|  1.11k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.11k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6162|       |
 6163|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6164|  1.11k|	if (priv == NULL) {
  ------------------
  |  Branch (6164:6): [True: 0, False: 1.11k]
  ------------------
 6165|      0|		r = piv_match_card_continued(card);
 6166|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  447|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6167|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (6167:7): [True: 0, False: 0]
  |  Branch (6167:16): [True: 0, False: 0]
  ------------------
 6168|      0|			sc_log(card->ctx, "piv_match_card_continued failed card->type:%d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6169|      0|			sc_unlock(card);
 6170|      0|			piv_finish(card);
 6171|       |			/* tell sc_connect_card to try other driver */
 6172|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6173|      0|		}
 6174|      0|	}
 6175|       |
 6176|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 6177|  1.11k|	piv_load_options(card);
 6178|       |
 6179|  1.11k|	priv->pstate = PIV_STATE_INIT;
 6180|       |
 6181|  1.11k|	sc_log(card->ctx, "Max send = %zu recv = %zu card->type:%d, CI:%08x AI:%08x",
  ------------------
  |  |   71|  1.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6182|  1.11k|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6183|  1.11k|	card->cla = 0x00;
 6184|  1.11k|	if (card->name == NULL)
  ------------------
  |  Branch (6184:6): [True: 1.11k, False: 0]
  ------------------
 6185|  1.11k|		card->name = card->driver->name;
 6186|       |
 6187|  1.11k|	priv->enumtag = piv_aids[0].enumtag;
 6188|       |
 6189|       |	/* PKCS#11 may try to generate session keys, and get confused
 6190|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 6191|       |	 * piv-tool can still do this, just don't tell PKCS#11
 6192|       |	 */
 6193|       |
 6194|  1.11k|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|  1.11k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6195|       |
 6196|  1.11k|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6196:6): [True: 0, False: 1.11k]
  ------------------
 6197|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6198|      0|	}
 6199|       |
 6200|  1.11k|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  608|  1.11k|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6200:6): [True: 1.11k, False: 1]
  ------------------
 6201|  1.11k|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6202|       |
 6203|  1.11k|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  609|  1.11k|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6203:6): [True: 1.11k, False: 2]
  ------------------
 6204|  1.11k|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6205|       |
 6206|  1.11k|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  610|  1.11k|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6206:6): [True: 1.11k, False: 1]
  ------------------
 6207|  1.11k|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6208|       |
 6209|  1.11k|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  611|  1.11k|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6209:6): [True: 146, False: 972]
  ------------------
 6210|    146|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6211|       |
 6212|  1.11k|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  604|  1.11k|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6212:6): [True: 1.11k, False: 0]
  ------------------
 6213|  1.11k|		int i;
 6214|  1.11k|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|  1.11k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|  1.11k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|  1.11k|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|  1.11k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 6215|  1.11k|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|  1.11k|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|  1.11k|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 6216|  1.11k|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|  1.11k|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6217|  1.11k|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  189|  1.11k|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|  1.11k|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 6218|       |
 6219|  5.59k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6219:15): [True: 4.47k, False: 1.11k]
  ------------------
 6220|  4.47k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  4.47k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6220:8): [True: 2.23k, False: 2.23k]
  ------------------
 6221|  2.23k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  603|  4.47k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6221:11): [True: 610, False: 1.62k]
  |  Branch (6221:46): [True: 305, False: 305]
  ------------------
 6222|  1.93k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6223|  2.23k|			}
 6224|       |
 6225|  2.23k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  614|  4.47k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    270|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6225:13): [True: 270, False: 1.96k]
  |  Branch (6225:41): [True: 135, False: 135]
  ------------------
 6226|    135|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6227|       |
 6228|  2.10k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  615|  4.20k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|    136|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6228:13): [True: 136, False: 1.96k]
  |  Branch (6228:42): [True: 135, False: 1]
  ------------------
 6229|    135|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6230|  4.47k|		}
 6231|  1.11k|	}
 6232|       |
 6233|  1.11k|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  594|  1.11k|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6233:6): [True: 1.03k, False: 87]
  ------------------
 6234|  1.03k|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|  1.03k|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6235|       |
 6236|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6237|  1.11k|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|  1.11k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6238|       |
 6239|       |	/*
 6240|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6241|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6242|       |	 */
 6243|       |
 6244|       |#ifdef ENABLE_PIV_SM
 6245|       |	/*
 6246|       |	 * 800-73-4
 6247|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6248|       |	 */
 6249|       |	if (priv->csID && priv->cs != NULL) {
 6250|       |		/*
 6251|       |		 * Main point in SM and VCI is to allow contactless access
 6252|       |		 */
 6253|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6254|       |
 6255|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6256|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6257|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6258|       |			r = SC_SUCCESS; /* Users choice */
 6259|       |
 6260|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6261|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6262|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6263|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6264|       |
 6265|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6266|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6267|       |				(priv->pairing_code[0] == 0x00)) {
 6268|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6269|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6270|       |
 6271|       |		} else {
 6272|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6273|       |			r = piv_sm_open(card);
 6274|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6275|       |		}
 6276|       |
 6277|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6278|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6279|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6280|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6281|       |		}
 6282|       |
 6283|       |		/* user has wrong or no required pairing code */
 6284|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6285|       |			LOG_FUNC_RETURN(card->ctx, r);
 6286|       |
 6287|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6288|       |	}
 6289|       |#endif /* ENABLE_PIV_SM */
 6290|       |
 6291|       |	/*
 6292|       |	 * 800-73-3 cards may have a history object
 6293|       |	 * We want to process it now as this has information on what
 6294|       |	 * keys and certs. "piv like" cards may or may not have history
 6295|       |	 */
 6296|  1.11k|	piv_process_history(card);
 6297|       |
 6298|  1.11k|	priv->pstate = PIV_STATE_NORMAL;
 6299|  1.11k|	sc_unlock(card);
 6300|  1.11k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.11k|	int _ret = r; \
  |  |  |  |  155|  1.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.11k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.11k|	return _ret; \
  |  |  |  |  163|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6301|  1.11k|}
card-piv.c:piv_load_options:
 1695|  1.11k|{
 1696|  1.11k|	int r;
 1697|  1.11k|	size_t i, j;
 1698|  1.11k|	scconf_block **found_blocks, *block;
 1699|       |
 1700|       |#ifdef ENABLE_PIV_SM
 1701|       |	piv_private_data_t *priv = PIV_DATA(card);
 1702|       |	const char *option = NULL;
 1703|       |	int piv_pairing_code_found = 0;
 1704|       |	int piv_use_sm_found = 0;
 1705|       |
 1706|       |	/* pairing code is 8 decimal digits and is card specific */
 1707|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1708|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1709|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1710|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1711|       |			piv_pairing_code_found = 1;
 1712|       |		}
 1713|       |	}
 1714|       |
 1715|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1716|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1717|       |		if (!strcmp(option, "never")) {
 1718|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1719|       |			piv_use_sm_found = 1;
 1720|       |		} else if (!strcmp(option, "always")) {
 1721|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1722|       |			piv_use_sm_found = 1;
 1723|       |		} else {
 1724|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1725|       |		}
 1726|       |	}
 1727|       |#endif
 1728|       |
 1729|  2.23k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1729:14): [True: 1.11k, False: 1.11k]
  ------------------
 1730|  1.11k|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1731|  1.11k|				"card_driver", "PIV-II");
 1732|  1.11k|		if (!found_blocks)
  ------------------
  |  Branch (1732:7): [True: 0, False: 1.11k]
  ------------------
 1733|      0|			continue;
 1734|       |
 1735|  1.11k|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1735:40): [True: 0, False: 1.11k]
  ------------------
 1736|       |
 1737|       |#ifdef ENABLE_PIV_SM
 1738|       |			/*
 1739|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1740|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1741|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1742|       |			 * this security risk
 1743|       |			 * always - Use even for contact interface.
 1744|       |			 * PINS, crypto and reading of object will not show up in logs
 1745|       |			 * or over network.
 1746|       |			 */
 1747|       |
 1748|       |			if (piv_use_sm_found == 0) {
 1749|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1750|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1751|       |				if (!strcmp(option, "default")) {
 1752|       |					/* no new flags */
 1753|       |				} else if (!strcmp(option, "never")) {
 1754|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1755|       |				} else if (!strcmp(option, "always")) {
 1756|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1757|       |				} else {
 1758|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1759|       |				}
 1760|       |			}
 1761|       |
 1762|       |			/* This is really a card specific value and should not be in the conf file */
 1763|       |			if (piv_pairing_code_found == 0) {
 1764|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1765|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1766|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1767|       |				}
 1768|       |			}
 1769|       |#endif
 1770|      0|		}
 1771|  1.11k|		free(found_blocks);
 1772|  1.11k|	}
 1773|  1.11k|	r = SC_SUCCESS;
  ------------------
  |  |   28|  1.11k|#define SC_SUCCESS				0
  ------------------
 1774|  1.11k|	return r;
 1775|  1.11k|}
card-piv.c:piv_process_history:
 5329|  1.11k|{
 5330|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5331|  1.11k|	int r;
 5332|  1.11k|	int i, tmplen, tmplen2, tmplen3;
 5333|  1.11k|	int enumtag;
 5334|  1.11k|	u8 *rbuf = NULL;
 5335|  1.11k|	size_t rbuflen = 0;
 5336|  1.11k|	const u8 *body;
 5337|  1.11k|	size_t bodylen;
 5338|  1.11k|	const u8 *num;
 5339|  1.11k|	size_t numlen;
 5340|  1.11k|	const u8 *url = NULL;
 5341|  1.11k|	size_t urllen;
 5342|  1.11k|	u8 *ocfhfbuf = NULL;
 5343|  1.11k|	unsigned int cla_out, tag_out;
 5344|  1.11k|	size_t ocfhflen;
 5345|  1.11k|	const u8 *seq;
 5346|  1.11k|	const u8 *seqtag;
 5347|  1.11k|	size_t seqlen;
 5348|  1.11k|	const u8 *keyref;
 5349|  1.11k|	size_t keyreflen;
 5350|  1.11k|	const u8 *cert;
 5351|  1.11k|	size_t certlen;
 5352|  1.11k|	size_t certobjlen, i2;
 5353|  1.11k|	u8 *certobj;
 5354|  1.11k|	u8 *cp;
 5355|       |
 5356|  1.11k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.11k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.11k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.11k]
  |  |  ------------------
  ------------------
 5357|       |
 5358|  1.11k|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5359|  1.11k|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  1.11k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5359:6): [True: 170, False: 948]
  ------------------
 5360|    170|		r = 0; /* OK if not found */
 5361|  1.11k|	if (r <= 0) {
  ------------------
  |  Branch (5361:6): [True: 835, False: 283]
  ------------------
 5362|    835|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    835|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5363|    835|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5364|    835|	}
 5365|       |
 5366|       |	/* the object is now cached, see what we have */
 5367|    283|	if (rbuflen != 0) {
  ------------------
  |  Branch (5367:6): [True: 283, False: 0]
  ------------------
 5368|    283|		body = rbuf;
 5369|    283|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    566|#define SC_SUCCESS				0
  ------------------
  |  Branch (5369:7): [True: 0, False: 283]
  ------------------
 5370|    283|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5370:5): [True: 0, False: 283]
  ------------------
 5371|      0|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5372|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5373|      0|			goto err;
 5374|      0|		}
 5375|       |
 5376|    283|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5376:7): [True: 283, False: 0]
  |  Branch (5376:23): [True: 277, False: 6]
  ------------------
 5377|    277|			numlen = 0;
 5378|    277|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5379|    277|			if (num) {
  ------------------
  |  Branch (5379:8): [True: 240, False: 37]
  ------------------
 5380|    240|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5380:9): [True: 1, False: 239]
  |  Branch (5380:24): [True: 7, False: 232]
  ------------------
 5381|      8|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      8|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5382|      8|					goto err;
 5383|      8|				}
 5384|       |
 5385|    232|				priv->keysWithOnCardCerts = *num;
 5386|    232|			}
 5387|       |
 5388|    269|			numlen = 0;
 5389|    269|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5390|    269|			if (num) {
  ------------------
  |  Branch (5390:8): [True: 219, False: 50]
  ------------------
 5391|    219|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5391:9): [True: 2, False: 217]
  |  Branch (5391:24): [True: 1, False: 216]
  ------------------
 5392|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5393|      3|					goto err;
 5394|      3|				}
 5395|       |
 5396|    216|				priv->keysWithOffCardCerts = *num;
 5397|    216|			}
 5398|       |
 5399|    266|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5400|    266|			if (url) {
  ------------------
  |  Branch (5400:8): [True: 211, False: 55]
  ------------------
 5401|    211|				if (urllen > 118) {
  ------------------
  |  Branch (5401:9): [True: 0, False: 211]
  ------------------
 5402|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5403|      0|					goto err;
 5404|      0|				}
 5405|    211|				priv->offCardCertURL = calloc(1, urllen + 1);
 5406|    211|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5406:9): [True: 0, False: 211]
  ------------------
 5407|    211|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5408|    211|				memcpy(priv->offCardCertURL, url, urllen);
 5409|    211|			}
 5410|    266|		} else {
 5411|      6|			sc_log(card->ctx, "Problem with History object\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__
  |  |  ------------------
  ------------------
 5412|      6|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
 5413|      6|			goto err;
 5414|      6|		}
 5415|    283|	}
 5416|    266|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    532|#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: 211, False: 55]
  |  |  ------------------
  ------------------
 5417|    266|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5418|    266|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5419|       |
 5420|       |	/* now mark what objects are on the card */
 5421|  3.97k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5421:14): [True: 3.70k, False: 266]
  ------------------
 5422|  3.70k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|  3.97k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5423|       |
 5424|       |	/*
 5425|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5426|       |	 * we will read in and add the certs to the cache as listed on
 5427|       |	 * the card. some of the certs may be on the card as well.
 5428|       |	 *
 5429|       |	 * Get file name from url. verify that the filename is valid
 5430|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5431|       |	 * in the directory used for the  PKCS15 cache
 5432|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5433|       |	 */
 5434|       |
 5435|    266|	r = 0;
 5436|    266|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5436:6): [True: 211, False: 55]
  ------------------
 5437|    211|		char *fp;
 5438|    211|		char filename[PATH_MAX];
 5439|       |
 5440|    211|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5440:7): [True: 196, False: 15]
  ------------------
 5441|    196|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    196|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5442|    196|			goto err;
 5443|    196|		}
 5444|       |		/* find the last /  so we have the filename part */
 5445|     15|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5446|     15|		if (fp == NULL) {
  ------------------
  |  Branch (5446:7): [True: 3, False: 12]
  ------------------
 5447|      3|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5448|      3|			goto err;
 5449|      3|		}
 5450|     12|		fp++;
 5451|     12|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5451:7): [True: 5, False: 7]
  ------------------
 5452|      5|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      5|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5453|      5|			goto err;
 5454|      5|		}
 5455|    106|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5455:15): [True: 105, False: 1]
  ------------------
 5456|    105|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5456:8): [True: 6, False: 99]
  ------------------
 5457|      6|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5458|      6|				goto err;
 5459|      6|			}
 5460|    105|		}
 5461|       |
 5462|       |		/* Use the same directory as used for other OpenSC cached items */
 5463|      1|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5464|      1|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (5464:7): [True: 0, False: 1]
  ------------------
 5465|      0|			goto err;
 5466|       |#ifdef _WIN32
 5467|       |		strlcat(filename, "\\", PATH_MAX);
 5468|       |#else
 5469|      1|		strlcat(filename, "/", PATH_MAX);
 5470|      1|#endif
 5471|      1|		strlcat(filename, fp, PATH_MAX);
 5472|       |
 5473|      1|		r = piv_read_obj_from_file(card, filename,
 5474|      1|				&ocfhfbuf, &ocfhflen);
 5475|      1|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5475:7): [True: 1, False: 0]
  ------------------
 5476|      1|			r = 0;
 5477|      1|			goto err;
 5478|      1|		}
 5479|       |
 5480|       |		/*
 5481|       |		 * Its a seq of seq of a key ref and cert
 5482|       |		 */
 5483|       |
 5484|      0|		body = ocfhfbuf;
 5485|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5485:7): [True: 0, False: 0]
  ------------------
 5486|      0|				body == NULL ||
  ------------------
  |  Branch (5486:5): [True: 0, False: 0]
  ------------------
 5487|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5487:5): [True: 0, False: 0]
  ------------------
 5488|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5488:5): [True: 0, False: 0]
  ------------------
 5489|      0|			sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5490|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5491|      0|			goto err;
 5492|      0|		}
 5493|      0|		seq = body;
 5494|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5494:10): [True: 0, False: 0]
  ------------------
 5495|      0|			seqtag = seq;
 5496|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5496:8): [True: 0, False: 0]
  ------------------
 5497|      0|					seq == 0 ||
  ------------------
  |  Branch (5497:6): [True: 0, False: 0]
  ------------------
 5498|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5498:6): [True: 0, False: 0]
  ------------------
 5499|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5499:6): [True: 0, False: 0]
  ------------------
 5500|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5501|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5502|      0|				goto err;
 5503|      0|			}
 5504|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5505|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5505:8): [True: 0, False: 0]
  |  Branch (5505:19): [True: 0, False: 0]
  ------------------
 5506|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5506:7): [True: 0, False: 0]
  |  Branch (5506:25): [True: 0, False: 0]
  ------------------
 5507|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5508|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5509|      0|				goto err;
 5510|      0|			}
 5511|      0|			cert = keyref + keyreflen;
 5512|      0|			certlen = seqlen - (cert - seq);
 5513|       |
 5514|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5515|       |			/* now add the cert like another object */
 5516|       |
 5517|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5517:8): [True: 0, False: 0]
  ------------------
 5518|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5518:6): [True: 0, False: 0]
  ------------------
 5519|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5519:6): [True: 0, False: 0]
  ------------------
 5520|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5521|      0|				goto err;
 5522|      0|			}
 5523|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5524|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5525|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5525:8): [True: 0, False: 0]
  ------------------
 5526|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5527|      0|				goto err;
 5528|      0|			}
 5529|       |
 5530|      0|			certobjlen = tmplen;
 5531|      0|			certobj = malloc(certobjlen);
 5532|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5532:8): [True: 0, False: 0]
  ------------------
 5533|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5534|      0|				goto err;
 5535|      0|			}
 5536|      0|			cp = certobj;
 5537|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5537:8): [True: 0, False: 0]
  ------------------
 5538|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5538:6): [True: 0, False: 0]
  ------------------
 5539|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5539:6): [True: 0, False: 0]
  ------------------
 5540|      0|				goto err;
 5541|      0|			}
 5542|      0|			*cp++ = 0x00;
 5543|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5544|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5544:8): [True: 0, False: 0]
  ------------------
 5545|      0|				goto err;
 5546|      0|			}
 5547|       |
 5548|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5549|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5550|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5551|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5552|       |
 5553|      0|			r = piv_cache_internal_data(card, enumtag);
 5554|      0|			sc_log(card->ctx, "got internal r=%d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5555|       |
 5556|      0|			sc_log(card->ctx, "Added from off card file #%d %p:%zu 0x%02X",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5557|      0|					enumtag,
 5558|      0|					priv->obj_cache[enumtag].obj_data,
 5559|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5560|       |
 5561|      0|			bodylen -= (seqlen + seq - seqtag);
 5562|      0|			seq += seqlen;
 5563|      0|		}
 5564|      0|	}
 5565|  1.11k|err:
 5566|  1.11k|	if (ocfhfbuf)
  ------------------
  |  Branch (5566:6): [True: 0, False: 1.11k]
  ------------------
 5567|      0|		free(ocfhfbuf);
 5568|  1.11k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.11k|	int _ret = r; \
  |  |  |  |  155|  1.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    886|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 886, False: 232]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.11k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.11k|	return _ret; \
  |  |  |  |  163|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5569|  1.11k|}
card-piv.c:piv_read_obj_from_file:
 3040|      1|{
 3041|      1|	int r;
 3042|      1|	int r_tag;
 3043|      1|	int f = -1;
 3044|      1|	size_t len;
 3045|      1|	u8 tagbuf[16];
 3046|      1|	size_t rbuflen;
 3047|      1|	const u8 *body;
 3048|      1|	unsigned int cla_out, tag_out;
 3049|      1|	size_t bodylen;
 3050|       |
 3051|      1|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 3052|       |
 3053|      1|	*buf = NULL;
 3054|      1|	*buf_len = 0;
 3055|      1|	f = open(filename, O_RDONLY);
 3056|      1|	if (f < 0) {
  ------------------
  |  Branch (3056:6): [True: 1, False: 0]
  ------------------
 3057|      1|		sc_log(card->ctx, "Unable to load PIV off card file: \"%s\"", filename);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3058|      1|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3059|      1|		goto err;
 3060|      1|	}
 3061|      0|	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
 3062|      0|	if (len < 2 || len > sizeof(tagbuf)) {
  ------------------
  |  Branch (3062:6): [True: 0, False: 0]
  |  Branch (3062:17): [True: 0, False: 0]
  ------------------
 3063|      0|		sc_log(card->ctx, "Problem with \"%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__
  |  |  ------------------
  ------------------
 3064|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 3065|      0|		goto err;
 3066|      0|	}
 3067|      0|	body = tagbuf;
 3068|       |	/* accept any tag for now, just get length */
 3069|      0|	r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 3070|      0|	if ((r_tag != SC_SUCCESS && r_tag != SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              	if ((r_tag != SC_SUCCESS && r_tag != SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|      0|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (3070:7): [True: 0, False: 0]
  |  Branch (3070:30): [True: 0, False: 0]
  ------------------
 3071|      0|			body == NULL) {
  ------------------
  |  Branch (3071:4): [True: 0, False: 0]
  ------------------
 3072|      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__
  |  |  ------------------
  ------------------
 3073|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3074|      0|		goto err;
 3075|      0|	}
 3076|      0|	rbuflen = body - tagbuf + bodylen;
 3077|      0|	*buf = malloc(rbuflen);
 3078|      0|	if (!*buf) {
  ------------------
  |  Branch (3078:6): [True: 0, False: 0]
  ------------------
 3079|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3080|      0|		goto err;
 3081|      0|	}
 3082|      0|	memcpy(*buf, tagbuf, MIN(len, rbuflen)); /* copy first or only part */
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 3083|       |	/* read rest of file */
 3084|      0|	if (rbuflen > len + sizeof(tagbuf)) {
  ------------------
  |  Branch (3084:6): [True: 0, False: 0]
  ------------------
 3085|      0|		len = read(f, *buf + sizeof(tagbuf), rbuflen - sizeof(tagbuf)); /* read rest */
 3086|      0|		if (len != rbuflen - sizeof(tagbuf)) {
  ------------------
  |  Branch (3086:7): [True: 0, False: 0]
  ------------------
 3087|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 3088|      0|			free(*buf);
 3089|      0|			*buf = NULL;
 3090|      0|			goto err;
 3091|      0|		}
 3092|      0|	}
 3093|      0|	r = (int)rbuflen;
 3094|      0|	*buf_len = rbuflen;
 3095|      1|err:
 3096|      1|	if (f >= 0)
  ------------------
  |  Branch (3096:6): [True: 0, False: 1]
  ------------------
 3097|      0|		close(f);
 3098|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3099|      1|}
card-piv.c:piv_cache_internal_data:
 3298|  4.86k|{
 3299|  4.86k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  4.86k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3300|  4.86k|	const u8 *tag;
 3301|  4.86k|	const u8 *body;
 3302|  4.86k|	size_t taglen;
 3303|  4.86k|	size_t bodylen;
 3304|  4.86k|	int compressed = 0;
 3305|  4.86k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.86k|#define SC_SUCCESS				0
  ------------------
 3306|       |#ifdef ENABLE_PIV_SM
 3307|       |	u8 *cvc_start = NULL;
 3308|       |	size_t cvc_len = 0;
 3309|       |#endif
 3310|       |
 3311|       |	/* if already cached */
 3312|  4.86k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3312:6): [True: 2.35k, False: 2.50k]
  |  Branch (3312:52): [True: 2.35k, False: 0]
  ------------------
 3313|  2.35k|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3314|  2.35k|				enumtag,
 3315|  2.35k|				priv->obj_cache[enumtag].internal_obj_data,
 3316|  2.35k|				priv->obj_cache[enumtag].internal_obj_len);
 3317|  2.35k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.35k|	int _ret = r; \
  |  |  |  |  155|  2.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.35k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.35k|	} else { \
  |  |  |  |  159|      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.35k|	return _ret; \
  |  |  |  |  163|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3318|  2.35k|	}
 3319|       |
 3320|  2.50k|	body = sc_asn1_find_tag(card->ctx,
 3321|  2.50k|			priv->obj_cache[enumtag].obj_data,
 3322|  2.50k|			priv->obj_cache[enumtag].obj_len,
 3323|  2.50k|			0x53, &bodylen);
 3324|       |
 3325|  2.50k|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3325:6): [True: 0, False: 2.50k]
  |  Branch (3325:22): [True: 0, False: 2.50k]
  ------------------
 3326|  2.50k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3327|       |
 3328|       |	/* get the certificate out */
 3329|  2.50k|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  653|  2.50k|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3329:6): [True: 2.50k, False: 0]
  ------------------
 3330|       |
 3331|  2.50k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3332|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3333|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3334|  2.50k|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3334:7): [True: 1.31k, False: 1.19k]
  |  Branch (3334:14): [True: 1.27k, False: 34]
  |  Branch (3334:29): [True: 10, False: 1.26k]
  |  Branch (3334:48): [True: 12, False: 1.25k]
  ------------------
 3335|     22|			compressed = 1;
 3336|       |
 3337|       |#ifdef ENABLE_PIV_SM
 3338|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3339|       |#endif
 3340|       |
 3341|  2.50k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3342|  2.50k|		if (tag == NULL)
  ------------------
  |  Branch (3342:7): [True: 135, False: 2.36k]
  ------------------
 3343|  2.50k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    135|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    135|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    135|	int _ret = r; \
  |  |  |  |  155|    135|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 135, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    135|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    135|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 135, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    135|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    135|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    135|	return _ret; \
  |  |  |  |  163|    135|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3344|       |
 3345|  2.36k|		if (taglen == 0)
  ------------------
  |  Branch (3345:7): [True: 10, False: 2.35k]
  ------------------
 3346|  2.36k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3347|       |
 3348|  2.35k|		if (compressed) {
  ------------------
  |  Branch (3348:7): [True: 20, False: 2.33k]
  ------------------
 3349|     20|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|     20|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3350|     20|		}
 3351|       |		/* internal certificate remains compressed */
 3352|  2.35k|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3352:7): [True: 0, False: 2.35k]
  ------------------
 3353|  2.35k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3354|       |
 3355|  2.35k|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3356|  2.35k|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3357|       |
 3358|       |#ifdef ENABLE_PIV_SM
 3359|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3360|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3361|       |			/* cvc if present should be at cvc_start.
 3362|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3363|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3364|       |			 * as the size of (L) depends on the length of value
 3365|       |			 */
 3366|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3367|       |					cvc_start &&
 3368|       |					cvc_start < tag &&
 3369|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3370|       |				cvc_len = tag - cvc_start + taglen;
 3371|       |				/* decode the intermediate CVC */
 3372|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3373|       |				if (r < 0) {
 3374|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3375|       |				}
 3376|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3377|       |			}
 3378|       |		}
 3379|       |#endif /* ENABLE_PIV_SM */
 3380|       |
 3381|       |		/* convert pub key to internal */
 3382|  2.35k|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3382:13): [True: 0, False: 0]
  ------------------
 3383|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3384|      0|		if (tag == NULL)
  ------------------
  |  Branch (3384:7): [True: 0, False: 0]
  ------------------
 3385|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3386|       |
 3387|      0|		if (taglen == 0)
  ------------------
  |  Branch (3387:7): [True: 0, False: 0]
  ------------------
 3388|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3389|       |
 3390|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3390:7): [True: 0, False: 0]
  ------------------
 3391|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3392|       |
 3393|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3394|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3395|      0|	} else {
 3396|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3397|      0|	}
 3398|       |
 3399|  2.35k|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   71|  2.35k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3400|  2.35k|			enumtag,
 3401|  2.35k|			priv->obj_cache[enumtag].internal_obj_data,
 3402|  2.35k|			priv->obj_cache[enumtag].internal_obj_len);
 3403|       |
 3404|  2.35k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.35k|	int _ret = r; \
  |  |  |  |  155|  2.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.35k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.35k|	} else { \
  |  |  |  |  159|      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.35k|	return _ret; \
  |  |  |  |  163|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3405|  2.35k|}
card-piv.c:piv_finish:
 5592|  10.7k|{
 5593|  10.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  10.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5594|  10.7k|	int i;
 5595|       |
 5596|  10.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.7k]
  |  |  ------------------
  ------------------
 5597|  10.7k|	if (priv) {
  ------------------
  |  Branch (5597:6): [True: 5.92k, False: 4.80k]
  ------------------
 5598|  5.92k|		if (priv->context_specific) {
  ------------------
  |  Branch (5598:7): [True: 0, False: 5.92k]
  ------------------
 5599|      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__
  |  |  ------------------
  ------------------
 5600|      0|			priv->context_specific = 0;
 5601|      0|			sc_unlock(card);
 5602|      0|		}
 5603|  5.92k|		free(priv->aid_der.value);
 5604|  5.92k|		free(priv->al_label);
 5605|  5.92k|		if (priv->w_buf)
  ------------------
  |  Branch (5605:7): [True: 0, False: 5.92k]
  ------------------
 5606|      0|			free(priv->w_buf);
 5607|  5.92k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5607:7): [True: 211, False: 5.70k]
  ------------------
 5608|    211|			free(priv->offCardCertURL);
 5609|   361k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5609:15): [True: 355k, False: 5.92k]
  ------------------
 5610|   355k|			piv_obj_cache_free_entry(card, i, 0);
 5611|   355k|		}
 5612|   159k|		for (i = 0; i < PIV_NUM_YK_SLOT_INFO; i++) {
  ------------------
  |  |  389|   159k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (5612:15): [True: 153k, False: 5.92k]
  ------------------
 5613|   153k|			free(priv->yk_slot_info[i].pubkey.value);
 5614|   153k|		}
 5615|       |#ifdef ENABLE_PIV_SM
 5616|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5617|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5618|       |		piv_clear_sm_session(&priv->sm_session);
 5619|       |#endif /* ENABLE_PIV_SM */
 5620|       |
 5621|  5.92k|		free(priv);
 5622|       |		card->drv_data = NULL; /* priv */
 5623|  5.92k|	}
 5624|  10.7k|	return 0;
 5625|  10.7k|}
card-piv.c:piv_select_file:
 5026|  10.9k|{
 5027|  10.9k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  10.9k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5028|  10.9k|	int r;
 5029|  10.9k|	int i;
 5030|  10.9k|	const u8 *path;
 5031|  10.9k|	size_t pathlen;
 5032|  10.9k|	sc_file_t *file = NULL;
 5033|  10.9k|	u8 *rbuf = NULL;
 5034|  10.9k|	size_t rbuflen = 0;
 5035|       |
 5036|  10.9k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.9k]
  |  |  ------------------
  ------------------
 5037|       |
 5038|  10.9k|	path = in_path->value;
 5039|  10.9k|	pathlen = in_path->len;
 5040|       |
 5041|       |	/* only support single EF in current application */
 5042|       |	/*
 5043|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 5044|       |	 * select_file and read_binary. The emulation adds path emulated structures
 5045|       |	 * so piv_select_file will find it.
 5046|       |	 * there is no dir. Only direct access to emulated files
 5047|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 5048|       |	 */
 5049|       |
 5050|  10.9k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (5050:6): [True: 1.62k, False: 9.33k]
  ------------------
 5051|  1.62k|		if (pathlen > 2) {
  ------------------
  |  Branch (5051:7): [True: 1.62k, False: 0]
  ------------------
 5052|  1.62k|			path += 2;
 5053|  1.62k|			pathlen -= 2;
 5054|  1.62k|		}
 5055|  1.62k|	}
 5056|       |
 5057|  10.9k|	i = piv_find_obj_by_containerid(card, path);
 5058|       |
 5059|  10.9k|	if (i < 0)
  ------------------
  |  Branch (5059:6): [True: 1.66k, False: 9.29k]
  ------------------
 5060|  10.9k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  1.66k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.66k|	int _ret = r; \
  |  |  |  |  155|  1.66k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.66k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.66k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.66k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.66k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.66k|	return _ret; \
  |  |  |  |  163|  1.66k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5061|       |
 5062|       |	/*
 5063|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 5064|       |	 * with cece added to path to request only the cert from the cert obj
 5065|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 5066|       |	 */
 5067|  9.29k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (5067:28): [True: 9.29k, False: 0]
  |  Branch (5067:44): [True: 9.29k, False: 0]
  |  Branch (5067:63): [True: 9.29k, False: 0]
  ------------------
 5068|       |
 5069|  9.29k|	priv->selected_obj = i;
 5070|  9.29k|	priv->rwb_state = -1;
 5071|       |
 5072|       |	/* make it look like the file was found. */
 5073|       |	/* We don't want to read it now  unless we need the length */
 5074|       |
 5075|  9.29k|	if (file_out) {
  ------------------
  |  Branch (5075:6): [True: 9.29k, False: 0]
  ------------------
 5076|       |		/* we need to read it now, to get length into cache */
 5077|  9.29k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 5078|       |
 5079|  9.29k|		if (r < 0)
  ------------------
  |  Branch (5079:7): [True: 6.79k, False: 2.50k]
  ------------------
 5080|  9.29k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  6.79k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.79k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.79k|	int _ret = r; \
  |  |  |  |  155|  6.79k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.79k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.79k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.79k|	return _ret; \
  |  |  |  |  163|  6.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5081|       |
 5082|       |		/* get the cert or the pub key out and into the cache too */
 5083|  2.50k|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (5083:7): [True: 2.50k, False: 0]
  |  Branch (5083:33): [True: 0, False: 0]
  ------------------
 5084|  2.50k|			r = piv_cache_internal_data(card, i);
 5085|  2.50k|			if (r < 0)
  ------------------
  |  Branch (5085:8): [True: 145, False: 2.35k]
  ------------------
 5086|  2.50k|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    145|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    145|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    145|	int _ret = r; \
  |  |  |  |  155|    145|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 145, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    145|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    145|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 145, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    145|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    145|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    145|	return _ret; \
  |  |  |  |  163|    145|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5087|  2.50k|		}
 5088|       |
 5089|  2.35k|		file = sc_file_new();
 5090|  2.35k|		if (file == NULL)
  ------------------
  |  Branch (5090:7): [True: 0, False: 2.35k]
  ------------------
 5091|  2.35k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5092|       |
 5093|  2.35k|		file->path = *in_path;
 5094|       |		/* this could be like the FCI */
 5095|  2.35k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  2.35k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 5096|  2.35k|		file->shareable = 0;
 5097|  2.35k|		file->ef_structure = 0;
 5098|  2.35k|		if (priv->return_only_cert)
  ------------------
  |  Branch (5098:7): [True: 2.35k, False: 0]
  ------------------
 5099|  2.35k|			file->size = priv->obj_cache[i].internal_obj_len;
 5100|      0|		else
 5101|      0|			file->size = priv->obj_cache[i].obj_len;
 5102|       |
 5103|  2.35k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 5104|       |
 5105|  2.35k|		*file_out = file;
 5106|  2.35k|	}
 5107|       |
 5108|  2.35k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.35k|	int _ret = r; \
  |  |  |  |  155|  2.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.35k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.35k|	} else { \
  |  |  |  |  159|      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.35k|	return _ret; \
  |  |  |  |  163|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5109|  2.35k|}
card-piv.c:piv_find_obj_by_containerid:
 1779|  80.2k|{
 1780|  80.2k|	int i;
 1781|       |
 1782|  80.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  80.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  80.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  80.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  80.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 80.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1783|  80.2k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  80.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__
  |  |  ------------------
  ------------------
 1784|       |
 1785|  1.63M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1785:14): [True: 1.63M, False: 2.77k]
  ------------------
 1786|  1.63M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1786:7): [True: 698k, False: 936k]
  |  Branch (1786:50): [True: 77.4k, False: 620k]
  ------------------
 1787|  1.63M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  77.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  77.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  77.4k|	int _ret = r; \
  |  |  |  |  155|  77.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 76.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  76.3k|	} else { \
  |  |  |  |  159|  76.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  76.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  76.3k|	} \
  |  |  |  |  162|  77.4k|	return _ret; \
  |  |  |  |  163|  77.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1788|  1.63M|	}
 1789|       |
 1790|  2.77k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.77k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.77k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.77k|	int _ret = r; \
  |  |  |  |  155|  2.77k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.77k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.77k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.77k|	return _ret; \
  |  |  |  |  163|  2.77k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1791|  2.77k|}
card-piv.c:piv_read_binary:
 3414|  2.47k|{
 3415|  2.47k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.47k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3416|  2.47k|	int enumtag;
 3417|  2.47k|	int r;
 3418|  2.47k|	u8 *rbuf = NULL;
 3419|  2.47k|	size_t rbuflen = 0;
 3420|  2.47k|	const u8 *body;
 3421|  2.47k|	size_t bodylen;
 3422|       |
 3423|  2.47k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.47k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.47k]
  |  |  ------------------
  ------------------
 3424|  2.47k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3424:6): [True: 0, False: 2.47k]
  ------------------
 3425|  2.47k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3426|  2.47k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3427|       |
 3428|  2.47k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3428:6): [True: 2.35k, False: 115]
  ------------------
 3429|  2.35k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3430|       |
 3431|  2.35k|		if (r >= 0) {
  ------------------
  |  Branch (3431:7): [True: 2.35k, False: 0]
  ------------------
 3432|       |			/* an object with no data will be considered not found */
 3433|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3434|  2.35k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3434:8): [True: 0, False: 2.35k]
  |  Branch (3434:17): [True: 0, False: 2.35k]
  |  Branch (3434:37): [True: 2.35k, False: 0]
  |  Branch (3434:65): [True: 0, False: 2.35k]
  ------------------
 3435|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3436|      0|				goto err;
 3437|      0|			}
 3438|       |
 3439|  2.35k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3440|  2.35k|			if (body == NULL) {
  ------------------
  |  Branch (3440:8): [True: 0, False: 2.35k]
  ------------------
 3441|       |				/* if missing, assume its the body */
 3442|       |				/* DEE bug in the beta card */
 3443|      0|				sc_log(card->ctx, " ***** tag 0x53 MISSING");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3444|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3445|      0|				goto err;
 3446|      0|			}
 3447|  2.35k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3447:8): [True: 0, False: 2.35k]
  ------------------
 3448|      0|				sc_log(card->ctx, " ***** tag length > then data: %zu>%zu+%zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3449|      0|						bodylen, body - rbuf, rbuflen);
 3450|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3451|      0|				goto err;
 3452|      0|			}
 3453|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3454|  2.35k|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3454:8): [True: 2.35k, False: 0]
  |  Branch (3454:34): [True: 0, False: 0]
  ------------------
 3455|  2.35k|				r = piv_cache_internal_data(card, enumtag);
 3456|  2.35k|				if (r < 0)
  ------------------
  |  Branch (3456:9): [True: 0, False: 2.35k]
  ------------------
 3457|      0|					goto err;
 3458|  2.35k|			}
 3459|  2.35k|		}
 3460|  2.35k|		priv->rwb_state = 0;
 3461|  2.35k|	}
 3462|       |
 3463|  2.47k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3463:6): [True: 2.47k, False: 0]
  |  Branch (3463:32): [True: 0, False: 0]
  ------------------
 3464|  2.47k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3465|  2.47k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3466|  2.47k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|  2.47k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3466:7): [True: 24, False: 2.44k]
  |  Branch (3466:70): [True: 24, False: 0]
  ------------------
 3467|     24|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     24|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3468|     24|		}
 3469|  2.47k|	} else {
 3470|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3471|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3472|      0|	}
 3473|       |	/* rbuf rbuflen has pointer and length to cached data */
 3474|       |
 3475|  2.47k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3475:6): [True: 0, False: 2.47k]
  ------------------
 3476|      0|		count = rbuflen - idx;
 3477|  2.47k|	if (count <= 0) {
  ------------------
  |  Branch (3477:6): [True: 0, False: 2.47k]
  ------------------
 3478|      0|		r = 0;
 3479|      0|		priv->rwb_state = 1;
 3480|  2.47k|	} else {
 3481|  2.47k|		memcpy(buf, rbuf + idx, count);
 3482|  2.47k|		r = (int)count;
 3483|  2.47k|	}
 3484|       |
 3485|  2.47k|err:
 3486|  2.47k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.47k|	int _ret = r; \
  |  |  |  |  155|  2.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 2.47k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.47k|	} else { \
  |  |  |  |  159|  2.47k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.47k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.47k|	} \
  |  |  |  |  162|  2.47k|	return _ret; \
  |  |  |  |  163|  2.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3487|  2.47k|}
card-piv.c:piv_set_security_env:
 4761|  4.47k|{
 4762|  4.47k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  4.47k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4763|  4.47k|	int r = 0;
 4764|       |
 4765|  4.47k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.47k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.47k]
  |  |  ------------------
  ------------------
 4766|       |
 4767|  4.47k|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|  4.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4768|  4.47k|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4769|  4.47k|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4770|       |
 4771|  4.47k|	priv->operation = env->operation;
 4772|  4.47k|	priv->algorithm = env->algorithm;
 4773|       |
 4774|  4.47k|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|  4.47k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4774:6): [True: 1.07k, False: 3.40k]
  ------------------
 4775|  1.07k|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4776|  3.40k|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  3.40k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4776:13): [True: 3.40k, False: 0]
  ------------------
 4777|  3.40k|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|  3.40k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4777:7): [True: 3.40k, False: 0]
  ------------------
 4778|  3.40k|			switch (env->algorithm_ref) {
 4779|  3.27k|			case 256:
  ------------------
  |  Branch (4779:4): [True: 3.27k, False: 124]
  ------------------
 4780|  3.27k|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4781|  3.27k|				priv->key_size = 256;
 4782|  3.27k|				break;
 4783|    124|			case 384:
  ------------------
  |  Branch (4783:4): [True: 124, False: 3.27k]
  ------------------
 4784|    124|				priv->alg_id = 0x14;
 4785|    124|				priv->key_size = 384;
 4786|    124|				break;
 4787|      0|			default:
  ------------------
  |  Branch (4787:4): [True: 0, False: 3.40k]
  ------------------
 4788|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4789|  3.40k|			}
 4790|  3.40k|		} else
 4791|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4792|  3.40k|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4792:13): [True: 0, False: 0]
  ------------------
 4793|      0|		priv->alg_id = 0xE0;
 4794|      0|		priv->key_size = 255;
 4795|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4795:13): [True: 0, False: 0]
  ------------------
 4796|      0|		priv->alg_id = 0xE1;
 4797|      0|		priv->key_size = 255;
 4798|      0|	} else
 4799|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4800|  4.47k|	priv->key_ref = env->key_ref[0];
 4801|       |
 4802|  4.47k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.47k|	int _ret = r; \
  |  |  |  |  155|  4.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.47k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.47k|	return _ret; \
  |  |  |  |  163|  4.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4803|  4.47k|}
card-piv.c:piv_compute_signature:
 4931|  2.91k|{
 4932|  2.91k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.91k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4933|  2.91k|	int r;
 4934|  2.91k|	u8 *ecdata = NULL;
 4935|  2.91k|	size_t ecdatalen = 0;
 4936|  2.91k|	size_t ecpadlen = 0;
 4937|  2.91k|	size_t nLen;
 4938|  2.91k|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4939|       |
 4940|  2.91k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.91k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.91k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.91k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.91k]
  |  |  ------------------
  ------------------
 4941|       |
 4942|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4943|       |	 * Which may have leading 00 to force a positive integer
 4944|       |	 * But PKCS11 just wants 2* field_length in bytes
 4945|       |	 * So we have to strip out the integers
 4946|       |	 * and pad on left if too short.
 4947|       |	 */
 4948|       |
 4949|  2.91k|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4949:6): [True: 2.70k, False: 215]
  |  Branch (4949:30): [True: 112, False: 103]
  ------------------
 4950|  2.81k|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|  2.81k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4951|       |
 4952|       |		/* One applet is known to enforce the hash size
 4953|       |		 * must match the field_length in bytes. But Windows
 4954|       |		 * may try ECDSA without a hash when offline
 4955|       |		 * So we will pad input to hash size.
 4956|       |		 */
 4957|  2.81k|		if (priv->card_issues & CI_ENFORCES_EC_HASH_EQ_KEYSIZE &&
  ------------------
  |  |  605|  5.62k|#define CI_ENFORCES_EC_HASH_EQ_KEYSIZE	    0x00001000U /* Applet enforces hash size == EC field size for ECDSA. Windows issue */
  ------------------
  |  Branch (4957:7): [True: 0, False: 2.81k]
  ------------------
 4958|      0|				!strcmp(card->ctx->app_name, "cardmod") &&
  ------------------
  |  Branch (4958:5): [True: 0, False: 0]
  ------------------
 4959|      0|				(datalen < nLen)) {
  ------------------
  |  Branch (4959:5): [True: 0, False: 0]
  ------------------
 4960|      0|			ecpadlen = nLen - datalen;
 4961|  2.81k|		} else {
 4962|  2.81k|			ecpadlen = 0;
 4963|  2.81k|		}
 4964|       |
 4965|  2.81k|		ecdatalen = datalen + ecpadlen;
 4966|  2.81k|		ecdata = calloc(ecdatalen, sizeof(u8));
 4967|  2.81k|		if (ecdata == NULL) {
  ------------------
  |  Branch (4967:7): [True: 0, False: 2.81k]
  ------------------
 4968|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 4969|      0|			goto err;
 4970|      0|		}
 4971|  2.81k|		memcpy(ecdata + ecpadlen, data, datalen);
 4972|       |
 4973|  2.81k|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4973:7): [True: 0, False: 2.81k]
  ------------------
 4974|      0|			sc_log(card->ctx, " output too small for EC signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4975|      0|					outlen, 2 * nLen);
 4976|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4977|      0|			goto err;
 4978|      0|		}
 4979|       |
 4980|  2.81k|		r = piv_validate_general_authentication(card, ecdata, ecdatalen, rbuf, sizeof rbuf);
 4981|  2.81k|		if (r < 0)
  ------------------
  |  Branch (4981:7): [True: 2.61k, False: 203]
  ------------------
 4982|  2.61k|			goto err;
 4983|       |
 4984|    203|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4985|       |		/* Yubikey 5.7.x supports ED25519 */
 4986|    203|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4986:13): [True: 0, False: 103]
  ------------------
 4987|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4988|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4988:7): [True: 0, False: 0]
  ------------------
 4989|      0|			sc_log(card->ctx, " output too small for ED signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4990|      0|					outlen, nLen);
 4991|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4992|      0|			goto err;
 4993|      0|		}
 4994|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4995|       |
 4996|    103|	} else { /* RSA is all set */
 4997|    103|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4998|    103|	}
 4999|       |
 5000|  2.91k|err:
 5001|  2.91k|	free(ecdata);
 5002|  2.91k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.91k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.91k|	int _ret = r; \
  |  |  155|  2.91k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.91k, False: 0]
  |  |  ------------------
  |  |  156|  2.91k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.91k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.91k, False: 0]
  |  |  ------------------
  |  |  157|  2.91k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.91k|	} else { \
  |  |  159|      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.91k|	return _ret; \
  |  |  163|  2.91k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5003|  2.91k|}
card-piv.c:piv_validate_general_authentication:
 4834|  3.66k|{
 4835|  3.66k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  3.66k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4836|  3.66k|	int r, tmplen, tmplen2;
 4837|  3.66k|	u8 *p;
 4838|  3.66k|	const unsigned char *p2;
 4839|  3.66k|	size_t taglen;
 4840|  3.66k|	size_t bodylen;
 4841|  3.66k|	unsigned int cla, tag;
 4842|  3.66k|	unsigned int real_alg_id, op_tag;
 4843|       |
 4844|  3.66k|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4845|  3.66k|	size_t sbuflen = sizeof(sbuf);
 4846|  3.66k|	u8 rbuf[4096];
 4847|       |
 4848|  3.66k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.66k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.66k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.66k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.66k]
  |  |  ------------------
  ------------------
 4849|       |
 4850|       |	/* should assume large send data */
 4851|  3.66k|	p = sbuf;
 4852|  3.66k|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4853|  3.66k|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4854|  3.66k|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4854:6): [True: 0, False: 3.66k]
  |  Branch (4854:21): [True: 0, False: 3.66k]
  ------------------
 4855|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4856|      0|	}
 4857|  3.66k|	tmplen += tmplen2;
 4858|  3.66k|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|  7.32k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4858:6): [True: 74, False: 3.59k]
  ------------------
 4859|  3.59k|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|  3.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4859:4): [True: 0, False: 3.59k]
  ------------------
 4860|     74|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4861|     74|	}
 4862|  3.59k|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   50|  7.18k|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   70|    432|#define SC_ALGORITHM_EC		2
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4862:6): [True: 216, False: 3.37k]
  |  Branch (4862:53): [True: 216, False: 0]
  |  Branch (4862:91): [True: 0, False: 0]
  ------------------
 4863|    216|		op_tag = 0x85;
 4864|  3.37k|	} else {
 4865|  3.37k|		op_tag = 0x81;
 4866|  3.37k|	}
 4867|  3.59k|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4868|  3.59k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  3.59k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4868:6): [True: 0, False: 3.59k]
  ------------------
 4869|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4870|      0|	}
 4871|       |
 4872|       |	/*
 4873|       |	 * alg_id=06 is a place holder for all RSA keys.
 4874|       |	 * Derive the real alg_id based on the size of the
 4875|       |	 * the data, as we are always using raw mode.
 4876|       |	 * Non RSA keys needs some work in this area.
 4877|       |	 */
 4878|       |
 4879|  3.59k|	real_alg_id = priv->alg_id;
 4880|  3.59k|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4880:6): [True: 561, False: 3.02k]
  ------------------
 4881|    561|		switch (datalen) {
 4882|    171|		case 128:
  ------------------
  |  Branch (4882:3): [True: 171, False: 390]
  ------------------
 4883|    171|			real_alg_id = 0x06;
 4884|    171|			break;
 4885|     68|		case 256:
  ------------------
  |  Branch (4885:3): [True: 68, False: 493]
  ------------------
 4886|     68|			real_alg_id = 0x07;
 4887|     68|			break;
 4888|     64|		case 384:
  ------------------
  |  Branch (4888:3): [True: 64, False: 497]
  ------------------
 4889|     64|			real_alg_id = 0x05;
 4890|     64|			break;
 4891|     64|		case 512:
  ------------------
  |  Branch (4891:3): [True: 64, False: 497]
  ------------------
 4892|     64|			real_alg_id = 0x16;
 4893|     64|			break;
 4894|    194|		default:
  ------------------
  |  Branch (4894:3): [True: 194, False: 367]
  ------------------
 4895|    194|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  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|    194|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 194, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4896|    561|		}
 4897|    561|	}
 4898|       |	/* EC and ED alg_id was already set */
 4899|       |
 4900|  3.39k|	piv_yk_notify_touch_policy(card, priv->key_ref);
 4901|  3.39k|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4902|  3.39k|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4903|  3.39k|	if (r < 0)
  ------------------
  |  Branch (4903:6): [True: 2.92k, False: 469]
  ------------------
 4904|  2.92k|		goto err;
 4905|       |
 4906|    469|	p2 = rbuf;
 4907|    469|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4908|    469|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4908:6): [True: 128, False: 341]
  |  Branch (4908:20): [True: 135, False: 206]
  |  Branch (4908:29): [True: 106, False: 100]
  |  Branch (4908:45): [True: 86, False: 14]
  ------------------
 4909|    455|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|    455|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    455|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    455|	int _ret = (r); \
  |  |  |  |  178|    455|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 455, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    455|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    455|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    455|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    455|		goto err; \
  |  |  |  |  182|    455|	} \
  |  |  |  |  183|    455|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4910|    455|	}
 4911|       |
 4912|     14|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4913|     14|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4913:6): [True: 1, False: 13]
  |  Branch (4913:20): [True: 1, False: 12]
  |  Branch (4913:29): [True: 1, False: 11]
  |  Branch (4913:44): [True: 2, False: 9]
  ------------------
 4914|      5|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x82");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4915|      5|	}
 4916|       |
 4917|      9|	if (taglen > outlen) {
  ------------------
  |  Branch (4917:6): [True: 0, False: 9]
  ------------------
 4918|      0|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "data read longer then buffer");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4919|      0|	}
 4920|       |
 4921|      9|	memcpy(out, p2, taglen);
 4922|      9|	r = (int)taglen;
 4923|       |
 4924|  3.39k|err:
 4925|  3.39k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.39k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.39k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.39k|	int _ret = r; \
  |  |  |  |  155|  3.39k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.38k, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.16k, False: 226]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.38k|	} 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|  3.39k|	return _ret; \
  |  |  |  |  163|  3.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4926|  3.39k|}
card-piv.c:piv_yk_notify_touch_policy:
 4815|  3.39k|{
 4816|  3.39k|	u8 touch_policy;
 4817|  3.39k|	const char *title = "Touch your Yubikey to continue";
 4818|       |
 4819|  3.39k|	piv_yk_get_metadata(card, key_ref, NULL, &touch_policy, NULL);
 4820|  3.39k|	switch (touch_policy) {
  ------------------
  |  Branch (4820:10): [True: 10, False: 3.38k]
  ------------------
 4821|      9|	case 0x02:
  ------------------
  |  Branch (4821:2): [True: 9, False: 3.38k]
  ------------------
 4822|      9|		sc_notify(title, "Touching the token is required for unlocking the key");
 4823|      9|		break;
 4824|      1|	case 0x03:
  ------------------
  |  Branch (4824:2): [True: 1, False: 3.39k]
  ------------------
 4825|      1|		sc_notify(title, "Touching the token is required unlocking the key (needed again after 15 seconds)");
 4826|      1|		break;
 4827|  3.39k|	}
 4828|  3.39k|}
card-piv.c:piv_yk_get_metadata:
 4549|  29.8k|{
 4550|  29.8k|	u8 resp[3072]; /* Should be enough to fit ML-DSA-87 key */
 4551|  29.8k|	int resplen = 0;
 4552|  29.8k|	size_t i;
 4553|  29.8k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  29.8k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4554|  29.8k|	int rc;
 4555|       |
 4556|       |	/* initialize with the default behaviour */
 4557|  29.8k|	if (pin_policy)
  ------------------
  |  Branch (4557:6): [True: 2.28k, False: 27.5k]
  ------------------
 4558|  2.28k|		*pin_policy = 0x00; /* i.e. use NIST defined */
 4559|  29.8k|	if (touch_policy)
  ------------------
  |  Branch (4559:6): [True: 3.39k, False: 26.4k]
  ------------------
 4560|  3.39k|		*touch_policy = 0x00;
 4561|  29.8k|	if (info) {
  ------------------
  |  Branch (4561:6): [True: 24.1k, False: 5.68k]
  ------------------
 4562|  24.1k|		info->algorithm = 0;
 4563|  24.1k|		info->pubkey.value = NULL;
 4564|  24.1k|		info->pubkey.len = 0;
 4565|  24.1k|	}
 4566|       |
 4567|  29.8k|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4567:6): [True: 17.9k, False: 11.8k]
  ------------------
 4568|  17.9k|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4568:7): [True: 3.22k, False: 14.7k]
  ------------------
 4569|  3.22k|			sc_log(card->ctx, "Yubikey's Get metadata extension not available");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4570|  17.9k|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  17.9k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4571|  17.9k|	}
 4572|       |
 4573|  41.7k|	for (i = 0; i < (PIV_NUM_YK_SLOT_INFO - 1); i++) {
  ------------------
  |  |  389|  41.7k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (4573:14): [True: 41.7k, False: 0]
  ------------------
 4574|  41.7k|		if (priv->yk_slot_info[i].slot == 0x00)
  ------------------
  |  Branch (4574:7): [True: 11.0k, False: 30.6k]
  ------------------
 4575|       |			/* reached the last initialized entry */
 4576|  11.0k|			break;
 4577|       |
 4578|  30.6k|		if (priv->yk_slot_info[i].slot == slot) {
  ------------------
  |  Branch (4578:7): [True: 796, False: 29.8k]
  ------------------
 4579|       |			/* metadata already initialized */
 4580|    796|			if (priv->yk_slot_info[i].invalid)
  ------------------
  |  Branch (4580:8): [True: 359, False: 437]
  ------------------
 4581|       |				/* already failed don't try again */
 4582|    359|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    359|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4583|    437|			break;
 4584|    796|		}
 4585|  30.6k|	}
 4586|       |
 4587|  11.4k|	if (priv->yk_slot_info[i].slot == 0x00) {
  ------------------
  |  Branch (4587:6): [True: 11.0k, False: 437]
  ------------------
 4588|       |		/* initialize this entry */
 4589|  11.0k|		rc = piv_general_io(card, 0xF7, 0x00, slot, NULL, 0, resp, sizeof(resp));
 4590|       |
 4591|  11.0k|		if (rc >= 0) { /* set defaults */
  ------------------
  |  Branch (4591:7): [True: 1.37k, False: 9.67k]
  ------------------
 4592|  1.37k|			priv->yk_slot_info[i].slot = slot;
 4593|  1.37k|		}
 4594|       |
 4595|  11.0k|		if (rc > 2) { /* at least 1 TLV */
  ------------------
  |  Branch (4595:7): [True: 791, False: 10.2k]
  ------------------
 4596|    791|			resplen = rc;
 4597|    791|			rc = piv_yk_metadata_get_policy(card->ctx, resp, resplen,
 4598|    791|					&priv->yk_slot_info[i].policy, &priv->yk_slot_info[i].touch);
 4599|    791|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    791|#define SC_SUCCESS				0
  ------------------
  |  Branch (4599:8): [True: 28, False: 763]
  ------------------
 4600|     28|				sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4601|     28|						slot, priv->yk_slot_info[i].policy, priv->yk_slot_info[i].touch);
 4602|     28|			}
 4603|    791|			rc = piv_yk_metadata_get_pubkey_info(card->ctx, resp, resplen, &priv->yk_slot_info[i]);
 4604|    791|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    791|#define SC_SUCCESS				0
  ------------------
  |  Branch (4604:8): [True: 23, False: 768]
  ------------------
 4605|     23|				sc_log(card->ctx, "Public key for slot 0x%02X: present", slot);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4606|     23|			}
 4607|  10.2k|		} else {
 4608|  10.2k|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
 4609|  10.2k|			priv->yk_slot_info[i].invalid = 1;
 4610|  10.2k|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  10.2k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4611|  10.2k|		}
 4612|  11.0k|	} else if (priv->yk_slot_info[i].slot != slot) {
  ------------------
  |  Branch (4612:13): [True: 0, False: 437]
  ------------------
 4613|      0|		sc_log(card->ctx, "No free slot found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4614|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4615|      0|	}
 4616|       |
 4617|  1.22k|	if (pin_policy)
  ------------------
  |  Branch (4617:6): [True: 205, False: 1.02k]
  ------------------
 4618|    205|		*pin_policy = priv->yk_slot_info[i].policy;
 4619|  1.22k|	if (touch_policy)
  ------------------
  |  Branch (4619:6): [True: 460, False: 768]
  ------------------
 4620|    460|		*touch_policy = priv->yk_slot_info[i].touch;
 4621|  1.22k|	if (info) {
  ------------------
  |  Branch (4621:6): [True: 563, False: 665]
  ------------------
 4622|    563|		info->algorithm = priv->yk_slot_info[i].algorithm;
 4623|    563|		info->pubkey.value = priv->yk_slot_info[i].pubkey.value;
 4624|    563|		info->pubkey.len = priv->yk_slot_info[i].pubkey.len;
 4625|    563|	}
 4626|       |
 4627|  1.22k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.22k|#define SC_SUCCESS				0
  ------------------
 4628|  11.4k|}
card-piv.c:piv_yk_metadata_get_policy:
 4502|    791|{
 4503|    791|	size_t policylen;
 4504|    791|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4505|    791|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4505:6): [True: 60, False: 731]
  |  Branch (4505:16): [True: 28, False: 32]
  ------------------
 4506|     28|		*pin = policy[0];
 4507|     28|		*touch = policy[1];
 4508|     28|		return SC_SUCCESS;
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
 4509|    763|	} else {
 4510|    763|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   71|    763|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4511|    763|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    763|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4512|    763|	}
 4513|    791|}
card-piv.c:piv_yk_metadata_get_pubkey_info:
 4517|    791|{
 4518|    791|	size_t tag_len = 0;
 4519|    791|	const u8 *pk = NULL;
 4520|       |
 4521|       |	/*  Tag 0x01: Algorithm/type of key */
 4522|    791|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x01, &tag_len);
 4523|    791|	if (pk && tag_len == 1) {
  ------------------
  |  Branch (4523:6): [True: 137, False: 654]
  |  Branch (4523:12): [True: 52, False: 85]
  ------------------
 4524|     52|		info->algorithm = pk[0];
 4525|    739|	} else {
 4526|    739|		sc_log(ctx, "Yubikey algorithm not found");
  ------------------
  |  |   71|    739|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4527|    739|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    739|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4528|    739|	}
 4529|       |
 4530|       |	/*  Tag 0x04: Public key */
 4531|     52|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x04, &tag_len);
 4532|     52|	if (pk && tag_len > 0) {
  ------------------
  |  Branch (4532:6): [True: 26, False: 26]
  |  Branch (4532:12): [True: 23, False: 3]
  ------------------
 4533|     23|		info->pubkey.value = malloc(tag_len);
 4534|     23|		if (info->pubkey.value == NULL) {
  ------------------
  |  Branch (4534:7): [True: 0, False: 23]
  ------------------
 4535|      0|			return SC_ERROR_MEMORY_FAILURE;
  ------------------
  |  |   57|      0|#define SC_ERROR_MEMORY_FAILURE			-1207
  ------------------
 4536|      0|		}
 4537|     23|		memcpy(info->pubkey.value, pk, tag_len);
 4538|     23|		info->pubkey.len = tag_len;
 4539|     29|	} else {
 4540|     29|		sc_log(ctx, "Yubikey public key not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4541|     29|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     29|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4542|     29|	}
 4543|       |
 4544|     23|	return SC_SUCCESS;
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
 4545|     52|}
card-piv.c:piv_decipher:
 5007|    748|{
 5008|    748|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    748|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    748|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    748|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 748]
  |  |  ------------------
  ------------------
 5009|       |
 5010|    748|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|    748|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    748|	int _ret = r; \
  |  |  155|    748|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 747, False: 1]
  |  |  ------------------
  |  |  156|    747|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    716|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 716, False: 31]
  |  |  ------------------
  |  |  157|    747|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    747|	} else { \
  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  161|      1|	} \
  |  |  162|    748|	return _ret; \
  |  |  163|    748|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5011|    748|}
card-piv.c:piv_check_sw:
 6305|  50.8k|{
 6306|  50.8k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6307|       |
 6308|  50.8k|	int r;
 6309|       |#ifdef ENABLE_PIV_SM
 6310|       |	int i;
 6311|       |#endif
 6312|  50.8k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  50.8k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6313|       |
 6314|  50.8k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  50.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  50.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  50.8k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 50.8k]
  |  |  ------------------
  ------------------
 6315|       |
 6316|       |	/* may be called before piv_init has allocated priv */
 6317|  50.8k|	if (priv) {
  ------------------
  |  Branch (6317:6): [True: 50.8k, False: 0]
  ------------------
 6318|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6319|       |
 6320|  50.8k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6320:7): [True: 3.53k, False: 47.2k]
  ------------------
 6321|  3.53k|			priv->pin_cmd_verify_sw1 = sw1;
 6322|  3.53k|			priv->pin_cmd_verify_sw2 = sw2;
 6323|  47.2k|		} else {
 6324|       |			/* a command has completed and it is not verify
 6325|       |			 * If we are in a context_specific sequence, unlock
 6326|       |			 * This just decrements the extra lock count
 6327|       |			 */
 6328|  47.2k|			if (priv->context_specific) {
  ------------------
  |  Branch (6328:8): [True: 0, False: 47.2k]
  ------------------
 6329|      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__
  |  |  ------------------
  ------------------
 6330|      0|				priv->context_specific = 0;
 6331|      0|				sc_unlock(card);
 6332|      0|			}
 6333|  47.2k|		}
 6334|       |
 6335|  50.8k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  591|  50.8k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6335:7): [True: 12.3k, False: 38.4k]
  ------------------
 6336|       |
 6337|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6338|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6339|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6340|       |			 */
 6341|  12.3k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6341:8): [True: 1.46k, False: 10.8k]
  |  Branch (6341:32): [True: 40, False: 1.42k]
  ------------------
 6342|     40|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6343|     40|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6343:9): [True: 22, False: 18]
  ------------------
 6344|     22|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6345|     22|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     22|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6346|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6347|     22|				}
 6348|     40|			}
 6349|  12.3k|		}
 6350|  50.8k|	}
 6351|       |#ifdef ENABLE_PIV_SM
 6352|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6353|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6354|       |	/* we stashed the sw1 and sw2 above for verify */
 6355|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6356|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6357|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6358|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6359|       |			return piv_sm_errors[i].errorno;
 6360|       |		}
 6361|       |	}
 6362|       |#endif
 6363|  50.8k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6364|  50.8k|	return r;
 6365|  50.8k|}
card-piv.c:piv_card_ctl:
 4654|  97.9k|{
 4655|  97.9k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  97.9k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4656|  97.9k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4657|       |
 4658|  97.9k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  97.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  97.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  97.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  97.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 97.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4659|       |
 4660|  97.9k|	if (priv == NULL) {
  ------------------
  |  Branch (4660:6): [True: 0, False: 97.9k]
  ------------------
 4661|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4662|      0|	}
 4663|  97.9k|	switch (cmd) {
  ------------------
  |  Branch (4663:10): [True: 97.9k, False: 0]
  ------------------
 4664|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4664:2): [True: 0, False: 97.9k]
  ------------------
 4665|      0|		opts = (u8 *)ptr;
 4666|      0|		switch (*opts) {
  ------------------
  |  Branch (4666:11): [True: 0, False: 0]
  ------------------
 4667|      0|		case 'A':
  ------------------
  |  Branch (4667:3): [True: 0, False: 0]
  ------------------
 4668|      0|			return piv_general_external_authenticate(card,
 4669|      0|					*(opts + 1), *(opts + 2));
 4670|      0|			break;
 4671|      0|		case 'M':
  ------------------
  |  Branch (4671:3): [True: 0, False: 0]
  ------------------
 4672|      0|			return piv_general_mutual_authenticate(card,
 4673|      0|					*(opts + 1), *(opts + 2));
 4674|      0|			break;
 4675|      0|		}
 4676|      0|		break;
 4677|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4677:2): [True: 0, False: 97.9k]
  ------------------
 4678|      0|		return piv_generate_key(card,
 4679|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4680|      0|		break;
 4681|  1.11k|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4681:2): [True: 1.11k, False: 96.8k]
  ------------------
 4682|  1.11k|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4683|      0|		break;
 4684|  1.11k|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4684:2): [True: 1.11k, False: 96.8k]
  ------------------
 4685|  1.11k|		return piv_get_pin_preference(card, ptr);
 4686|      0|		break;
 4687|  69.3k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4687:2): [True: 69.3k, False: 28.6k]
  ------------------
 4688|  69.3k|		return piv_is_object_present(card, ptr);
 4689|      0|		break;
 4690|  2.28k|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4690:2): [True: 2.28k, False: 95.6k]
  ------------------
 4691|  2.28k|		return piv_yk_pin_policy(card, ptr);
 4692|      0|		break;
 4693|  24.1k|	case SC_CARDCTL_PIV_YK_GET_PUBKEY_INFO:
  ------------------
  |  Branch (4693:2): [True: 24.1k, False: 73.8k]
  ------------------
 4694|  24.1k|		return piv_yk_get_pubkey(card, ptr);
 4695|      0|		break;
 4696|  97.9k|	}
 4697|       |
 4698|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4699|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4382|  1.11k|{
 4383|  1.11k|	int r;
 4384|  1.11k|	int i;
 4385|  1.11k|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4386|  1.11k|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4387|  1.11k|	u8 *rbuf = NULL;
 4388|  1.11k|	const u8 *body;
 4389|  1.11k|	const u8 *fascn;
 4390|  1.11k|	const u8 *guid;
 4391|  1.11k|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4392|       |
 4393|  1.11k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.11k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.11k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.11k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.11k]
  |  |  ------------------
  ------------------
 4394|  1.11k|	if (card->serialnr.len) {
  ------------------
  |  Branch (4394:6): [True: 0, False: 1.11k]
  ------------------
 4395|      0|		*serial = card->serialnr;
 4396|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4397|      0|	}
 4398|       |
 4399|       |	/*
 4400|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4401|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4402|       |	 * based on RFC 4122. If GUID present and not zero
 4403|       |	 * we will use the GUID as the serial number.
 4404|       |	 */
 4405|       |
 4406|  1.11k|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4407|  1.11k|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|  1.11k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.11k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.11k|	int _ret = (r); \
  |  |  |  |  168|  1.11k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.04k, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.04k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.04k|		return _ret; \
  |  |  |  |  172|  1.04k|	} \
  |  |  |  |  173|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4408|       |
 4409|     71|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     71|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4410|     71|	if (rbuflen != 0) {
  ------------------
  |  Branch (4410:6): [True: 71, False: 0]
  ------------------
 4411|     71|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4412|     71|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4412:7): [True: 71, False: 0]
  |  Branch (4412:23): [True: 65, False: 6]
  |  Branch (4412:39): [True: 65, False: 0]
  ------------------
 4413|     65|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4414|       |
 4415|     65|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4415:8): [True: 42, False: 23]
  |  Branch (4415:17): [True: 38, False: 4]
  ------------------
 4416|    988|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4416:17): [True: 950, False: 38]
  ------------------
 4417|    950|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4417:14): [True: 776, False: 174]
  |  Branch (4417:23): [True: 37, False: 137]
  ------------------
 4418|    950|				}
 4419|     38|			}
 4420|       |
 4421|     65|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4422|       |
 4423|     65|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4423:8): [True: 14, False: 51]
  |  Branch (4423:16): [True: 8, False: 6]
  ------------------
 4424|    136|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4424:17): [True: 128, False: 8]
  ------------------
 4425|    128|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4426|    128|				}
 4427|      8|			}
 4428|     65|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   71|     65|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4429|     65|					fascn, fascnlen, guid, guidlen, gbits);
 4430|       |
 4431|     65|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4431:8): [True: 42, False: 23]
  |  Branch (4431:17): [True: 38, False: 4]
  |  Branch (4431:35): [True: 37, False: 1]
  ------------------
 4432|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4433|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4434|     37|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4434:11): [True: 7, False: 30]
  |  Branch (4434:20): [True: 5, False: 2]
  |  Branch (4434:40): [True: 3, False: 2]
  ------------------
 4435|     36|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4435:11): [True: 2, False: 1]
  |  Branch (4435:31): [True: 1, False: 1]
  ------------------
 4436|       |					/* fascnlen is 25 */
 4437|     36|					serial->len = fascnlen;
 4438|     36|					memcpy(serial->value, fascn, serial->len);
 4439|     36|					r = SC_SUCCESS;
  ------------------
  |  |   28|     36|#define SC_SUCCESS				0
  ------------------
 4440|     36|					gbits = 0; /* set to skip using guid below */
 4441|     36|				}
 4442|     37|			}
 4443|     65|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4443:8): [True: 14, False: 51]
  |  Branch (4443:16): [True: 8, False: 6]
  |  Branch (4443:33): [True: 2, False: 6]
  ------------------
 4444|      2|				serial->len = guidlen;
 4445|      2|				memcpy(serial->value, guid, serial->len);
 4446|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4447|      2|			}
 4448|     65|		}
 4449|     71|	}
 4450|       |
 4451|     71|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4451:6): [True: 34, False: 37]
  |  Branch (4451:20): [True: 33, False: 1]
  ------------------
 4452|     33|		serial->len = 16;
 4453|     33|		memset(serial->value, 0x00, serial->len);
 4454|     33|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     33|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4455|     33|	}
 4456|       |
 4457|     71|	card->serialnr = *serial;
 4458|     71|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     71|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     71|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     71|	int _ret = r; \
  |  |  |  |  155|     71|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 71, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     71|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 38]
  |  |  |  |  ------------------
  |  |  |  |  157|     71|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     71|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     71|	return _ret; \
  |  |  |  |  163|     71|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4459|     71|}
card-piv.c:piv_get_pin_preference:
 4493|  1.11k|{
 4494|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4495|       |
 4496|  1.11k|	*pin_ref = priv->pin_preference;
 4497|  1.11k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.11k|	int _ret = r; \
  |  |  |  |  155|  1.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.11k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.11k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.11k|	return _ret; \
  |  |  |  |  163|  1.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4498|  1.11k|}
card-piv.c:piv_is_object_present:
 4474|  69.3k|{
 4475|  69.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  69.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4476|  69.3k|	int r = 0;
 4477|  69.3k|	int enumtag;
 4478|       |
 4479|  69.3k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4480|  69.3k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  68.1k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4480:6): [True: 68.1k, False: 1.11k]
  |  Branch (4480:22): [True: 38.8k, False: 29.3k]
  ------------------
 4481|  38.8k|		r = 1;
 4482|       |
 4483|  69.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  69.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  69.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  69.3k|	int _ret = r; \
  |  |  |  |  155|  69.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30.4k, False: 38.8k]
  |  |  |  |  ------------------
  |  |  |  |  156|  30.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: 30.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  30.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  38.8k|	} else { \
  |  |  |  |  159|  38.8k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  38.8k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  38.8k|	} \
  |  |  |  |  162|  69.3k|	return _ret; \
  |  |  |  |  163|  69.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4484|  69.3k|}
card-piv.c:piv_yk_pin_policy:
 4632|  2.28k|{
 4633|  2.28k|	u8 slot = *ptr;
 4634|  2.28k|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL, NULL));
  ------------------
  |  |  164|  2.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.28k|	int _ret = r; \
  |  |  |  |  155|  2.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.28k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.08k, False: 205]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.28k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.28k|	} else { \
  |  |  |  |  159|      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.28k|	return _ret; \
  |  |  |  |  163|  2.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4635|  2.28k|}
card-piv.c:piv_yk_get_pubkey:
 4639|  24.1k|{
 4640|  24.1k|	int rc;
 4641|  24.1k|	u8 slot = info->slot;
 4642|       |
 4643|  24.1k|	rc = piv_yk_get_metadata(card, slot, NULL, NULL, info);
 4644|  24.1k|	LOG_TEST_RET(card->ctx, rc, "piv_yk_get_metadata failed");
  ------------------
  |  |  174|  24.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  24.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  24.1k|	int _ret = (r); \
  |  |  |  |  168|  24.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23.5k, False: 563]
  |  |  |  |  ------------------
  |  |  |  |  169|  23.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|  23.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  23.5k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  23.5k|		return _ret; \
  |  |  |  |  172|  23.5k|	} \
  |  |  |  |  173|  24.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 563]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4645|    563|	if (info->pubkey.value == NULL || info->pubkey.len == 0 || info->algorithm == 0) {
  ------------------
  |  Branch (4645:6): [True: 540, False: 23]
  |  Branch (4645:36): [True: 0, False: 23]
  |  Branch (4645:61): [True: 1, False: 22]
  ------------------
 4646|    541|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    541|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    541|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    541|	int _ret = r; \
  |  |  |  |  155|    541|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 541, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    541|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    541|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 541, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    541|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    541|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    541|	return _ret; \
  |  |  |  |  163|    541|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4647|    541|	}
 4648|       |
 4649|     22|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4650|     22|}
card-piv.c:piv_pin_cmd:
 6438|  2.59k|{
 6439|  2.59k|	int r = 0;
 6440|  2.59k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.59k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6441|       |
 6442|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6443|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6444|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6445|       |	 */
 6446|  2.59k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6447|       |
 6448|  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]
  |  |  ------------------
  ------------------
 6449|  2.59k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.59k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6450|  2.59k|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|  2.59k|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6450:6): [True: 114, False: 2.48k]
  ------------------
 6451|    114|		size_t i = 0;
 6452|    114|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6452:7): [True: 26, False: 88]
  ------------------
 6453|     26|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     26|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6454|     26|		}
 6455|    366|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6455:15): [True: 332, False: 34]
  ------------------
 6456|    332|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6456:8): [True: 54, False: 278]
  ------------------
 6457|     54|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     54|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6458|     54|			}
 6459|    332|		}
 6460|     88|	}
 6461|       |
 6462|  2.51k|	priv->pin_cmd_verify_sw1 = 0x00U;
 6463|       |
 6464|  2.51k|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|  2.51k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6464:6): [True: 2.19k, False: 320]
  ------------------
 6465|  2.19k|		data->pin1.logged_in = priv->logged_in;
 6466|  2.19k|		data->pin1.tries_left = priv->tries_left;
 6467|       |
 6468|       |		/*
 6469|       |		 * If called to check on the login state for a context specific login
 6470|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6471|       |		 */
 6472|  2.19k|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|  2.19k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6472:7): [True: 0, False: 2.19k]
  ------------------
 6473|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6474|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6475|      0|		}
 6476|       |
 6477|  2.19k|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|  2.19k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6477:7): [True: 57, False: 2.14k]
  ------------------
 6478|       |			/* Avoid status requests when the user is logged in to handle NIST
 6479|       |			 * 800-73-4 Part 2:
 6480|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6481|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6482|       |			 * PIN or OCC data must be submitted and verified every time
 6483|       |			 * immediately before a digital signature key operation.  This
 6484|       |			 * ensures cardholder participation every time the private key is
 6485|       |			 * used for digital signature generation */
 6486|     57|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6487|     57|		}
 6488|  2.19k|	}
 6489|       |
 6490|       |	/*
 6491|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6492|       |	 * to avoid any interference from other applications.
 6493|       |	 * Sc_unlock will be called at a later time after the next card command
 6494|       |	 * that should be a crypto operation. If its not then it is a error by the
 6495|       |	 * calling application.
 6496|       |	 */
 6497|  2.46k|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|  4.92k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    172|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6497:6): [True: 172, False: 2.28k]
  |  Branch (6497:40): [True: 0, False: 172]
  ------------------
 6498|      0|		priv->context_specific = 1;
 6499|      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__
  |  |  ------------------
  ------------------
 6500|      0|		r = sc_lock(card);
 6501|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6501:7): [True: 0, False: 0]
  ------------------
 6502|      0|			sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6503|      0|			return r;
 6504|      0|		}
 6505|      0|	}
 6506|       |
 6507|  2.46k|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6508|  2.46k|	r = iso_drv->ops->pin_cmd(card, data);
 6509|  2.46k|	priv->pin_cmd_verify = 0;
 6510|       |
 6511|       |	/* tell user verify not supported on contactless without VCI */
 6512|  2.46k|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6512:6): [True: 47, False: 2.41k]
  |  Branch (6512:42): [True: 25, False: 22]
  ------------------
 6513|     25|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|  2.48k|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6513:4): [True: 6, False: 19]
  ------------------
 6514|      6|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6514:4): [True: 0, False: 6]
  ------------------
 6515|      0|		sc_log(card->ctx, "Token does not support pin verify over contacless reader");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6516|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6517|      0|	}
 6518|       |
 6519|       |	/* if verify failed, release the lock */
 6520|  2.46k|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|  4.92k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6520:6): [True: 172, False: 2.28k]
  |  Branch (6520:40): [True: 127, False: 45]
  |  Branch (6520:49): [True: 0, False: 127]
  ------------------
 6521|      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__
  |  |  ------------------
  ------------------
 6522|      0|		priv->context_specific = 0;
 6523|      0|		sc_unlock(card);
 6524|      0|	}
 6525|       |
 6526|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6527|  2.46k|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  600|  4.92k|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6527:6): [True: 1.22k, False: 1.24k]
  |  Branch (6527:53): [True: 1.07k, False: 142]
  ------------------
 6528|  1.07k|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|  1.07k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6529|  1.07k|		piv_find_aid(card);
 6530|       |
 6531|  1.07k|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6532|  1.07k|		r = iso_drv->ops->pin_cmd(card, data);
 6533|  1.07k|		priv->pin_cmd_verify = 0;
 6534|  1.07k|	}
 6535|       |
 6536|       |	/* If verify worked, we are logged_in */
 6537|  2.46k|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|  2.46k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6537:6): [True: 172, False: 2.28k]
  ------------------
 6538|    172|		if (r >= 0)
  ------------------
  |  Branch (6538:7): [True: 46, False: 126]
  ------------------
 6539|     46|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     46|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6540|    126|		else
 6541|    126|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|    126|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6542|    172|	}
 6543|       |
 6544|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6545|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6546|       |
 6547|  2.46k|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|  2.46k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6547:6): [True: 2.14k, False: 320]
  ------------------
 6548|  2.14k|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  595|  2.14k|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6548:7): [True: 7, False: 2.13k]
  ------------------
 6549|      7|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6550|      7|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6551|  2.13k|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  592|  4.26k|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6551:14): [True: 664, False: 1.47k]
  ------------------
 6552|    664|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6552:5): [True: 18, False: 646]
  ------------------
 6553|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6554|     18|			r = piv_check_protected_objects(card);
 6555|     18|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (6555:8): [True: 2, False: 16]
  ------------------
 6556|      2|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      2|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6557|     16|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     16|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6557:13): [True: 15, False: 1]
  ------------------
 6558|     15|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  595|     15|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6558:9): [True: 8, False: 7]
  ------------------
 6559|       |
 6560|      8|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6561|      8|				} else {
 6562|      7|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      7|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6563|      7|				}
 6564|     15|				r = SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
 6565|     15|			}
 6566|     18|		}
 6567|  2.14k|		priv->logged_in = data->pin1.logged_in;
 6568|  2.14k|		priv->tries_left = data->pin1.tries_left;
 6569|  2.14k|	}
 6570|       |
 6571|  2.46k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.46k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6572|  2.46k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.46k|	int _ret = r; \
  |  |  |  |  155|  2.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.33k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.33k, False: 124]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.46k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.46k|	return _ret; \
  |  |  |  |  163|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6573|  2.46k|}
card-piv.c:piv_check_protected_objects:
 6369|     18|{
 6370|     18|	int r = 0;
 6371|     18|	int i;
 6372|     18|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     18|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6373|     18|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6374|     18|	u8 *rbuf;
 6375|     18|	size_t buf_len;
 6376|     18|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6377|       |
 6378|     18|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     18|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     18|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     18|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     18|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6379|       |	/*
 6380|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6381|       |	 * We will test for a protected object using GET DATA.
 6382|       |	 *
 6383|       |	 * Based on observations, of cards using the GET DATA APDU,
 6384|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6385|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6386|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6387|       |	 * about the state of the PIN and we will try the next object.
 6388|       |	 *
 6389|       |	 * If we can't determine the security state from this process,
 6390|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6391|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6392|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6393|       |	 * so we will have an object to test.
 6394|       |	 *
 6395|       |	 * We save the object's number to use in the future.
 6396|       |	 *
 6397|       |	 */
 6398|     18|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6398:6): [True: 15, False: 3]
  ------------------
 6399|     44|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6399:15): [True: 36, False: 8]
  ------------------
 6400|     36|			buf_len = sizeof(buf);
 6401|     36|			rbuf = buf;
 6402|     36|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6403|     36|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     34|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6403:8): [True: 2, False: 34]
  |  Branch (6403:18): [True: 5, False: 29]
  ------------------
 6404|       |
 6405|       |				/* we can use this object next time if needed */
 6406|      7|				priv->object_test_verify = protected_objects[i];
 6407|      7|				break;
 6408|      7|			}
 6409|     36|		}
 6410|     15|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6410:7): [True: 8, False: 7]
  ------------------
 6411|       |			/*
 6412|       |			 * none of the objects returned acceptable sw1, sw2
 6413|       |			 */
 6414|      8|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6415|      8|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  595|      8|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6416|      8|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      8|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6417|      8|		}
 6418|     15|	} else {
 6419|       |		/* use the one object we found earlier. Test is security status has changed */
 6420|      3|		buf_len = sizeof(buf);
 6421|      3|		rbuf = buf;
 6422|      3|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6423|      3|	}
 6424|     18|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|     18|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6424:6): [True: 1, False: 17]
  ------------------
 6425|      1|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6426|     17|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|     17|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6426:11): [True: 6, False: 11]
  ------------------
 6427|      6|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      6|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6428|     11|	else if (r > 0)
  ------------------
  |  Branch (6428:11): [True: 2, False: 9]
  ------------------
 6429|      2|		r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 6430|       |
 6431|     18|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6432|     18|			card->type, priv->card_issues, r, priv->alg_ids);
 6433|     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|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6434|     18|}
card-piv.c:piv_card_reader_lock_obtained:
 6612|  15.1k|{
 6613|  15.1k|	int r = 0;
 6614|  15.1k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6615|  15.1k|	size_t templen = sizeof(temp);
 6616|  15.1k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  447|  15.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6617|       |
 6618|  15.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.1k]
  |  |  ------------------
  ------------------
 6619|       |
 6620|       |	/* We have a PCSC transaction and sc_lock */
 6621|  15.1k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6621:6): [True: 5.92k, False: 9.26k]
  |  Branch (6621:22): [True: 1.11k, False: 8.14k]
  ------------------
 6622|  7.03k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  14.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:103): [True: 1.11k, False: 5.92k]
  |  |  ------------------
  ------------------
 6623|  7.03k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6624|  7.03k|		r = 0; /* do nothing, piv_match will take care of it */
 6625|  7.03k|		goto err;
 6626|  7.03k|	}
 6627|       |
 6628|  8.14k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  8.14k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6629|       |
 6630|       |	/* make sure our application is active */
 6631|       |
 6632|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6633|       |	/* If not try selecting AID */
 6634|       |
 6635|       |	/* but if card does not support DISCOVERY object we can not use it */
 6636|  8.14k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  597|  8.14k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6636:6): [True: 3.93k, False: 4.20k]
  ------------------
 6637|  3.93k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  3.93k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6638|  4.20k|	} else {
 6639|  4.20k|		r = piv_find_discovery(card);
 6640|       |#ifdef ENABLE_PIV_SM
 6641|       |		/*
 6642|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6643|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6644|       |		 * Discovery object can be read with contact or contactless
 6645|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6646|       |		 * sm.c will close the SM connectrion, and set defer
 6647|       |		 */
 6648|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6649|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6650|       |			piv_sm_open(card);
 6651|       |			r = piv_find_discovery(card);
 6652|       |		}
 6653|       |#endif /* ENABLE_PIV_SM */
 6654|  4.20k|	}
 6655|       |
 6656|  8.14k|	if (r < 0) {
  ------------------
  |  Branch (6656:6): [True: 8.12k, False: 15]
  ------------------
 6657|  8.12k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  598|  8.12k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6657:7): [True: 0, False: 8.12k]
  |  Branch (6657:24): [True: 7.68k, False: 441]
  ------------------
 6658|  7.68k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6659|  7.68k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  7.68k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6660|  7.68k|		} else {
 6661|    441|			r = 0; /* can't do anything with this card, hope there was no interference */
 6662|    441|		}
 6663|  8.12k|	}
 6664|       |
 6665|  8.14k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6665:6): [True: 7.09k, False: 1.04k]
  ------------------
 6666|  7.09k|		goto err;
 6667|       |
 6668|  1.04k|	if (was_reset > 0)
  ------------------
  |  Branch (6668:6): [True: 0, False: 1.04k]
  ------------------
 6669|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6670|       |
 6671|  1.04k|	r = 0;
 6672|       |
 6673|  15.1k|err:
 6674|  15.1k|	if (priv)
  ------------------
  |  Branch (6674:6): [True: 9.26k, False: 5.92k]
  ------------------
 6675|  9.26k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  9.26k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6676|  15.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  15.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.1k|	int _ret = r; \
  |  |  |  |  155|  15.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.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|  7.09k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.09k, False: 8.08k]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.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|  15.1k|	return _ret; \
  |  |  |  |  163|  15.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6677|  15.1k|}

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

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

sc_get_sc_hsm_driver:
 2003|  16.9k|{
 2004|  16.9k|	return sc_get_driver();
 2005|  16.9k|}
card-sc-hsm.c:sc_get_driver:
 1967|  16.9k|{
 1968|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1969|       |
 1970|  16.9k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1970:6): [True: 1, False: 16.9k]
  ------------------
 1971|      1|		iso_ops = iso_drv->ops;
 1972|       |
 1973|  16.9k|	sc_hsm_ops                   = *iso_drv->ops;
 1974|  16.9k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1975|  16.9k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1976|  16.9k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1977|  16.9k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1978|  16.9k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1979|  16.9k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1980|  16.9k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1981|  16.9k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1982|  16.9k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1983|  16.9k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1984|  16.9k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1985|  16.9k|	sc_hsm_ops.init              = sc_hsm_init;
 1986|  16.9k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1987|  16.9k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1988|  16.9k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1989|  16.9k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1990|       |
 1991|       |	/* no record oriented file services */
 1992|  16.9k|	sc_hsm_ops.read_record       = NULL;
 1993|  16.9k|	sc_hsm_ops.write_record      = NULL;
 1994|  16.9k|	sc_hsm_ops.append_record     = NULL;
 1995|  16.9k|	sc_hsm_ops.update_record     = NULL;
 1996|       |
 1997|  16.9k|	return &sc_hsm_drv;
 1998|  16.9k|}
card-sc-hsm.c:sc_hsm_match_card:
  267|  6.40k|{
  268|  6.40k|	sc_path_t path;
  269|  6.40k|	int i, r, type = 0;
  270|  6.40k|	sc_file_t *file = NULL;
  271|       |
  272|  6.40k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  273|  6.40k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (273:6): [True: 278, False: 6.12k]
  |  Branch (273:16): [True: 277, False: 1]
  ------------------
  274|    277|		card->type = type;
  275|    277|		return 1;
  276|    277|	}
  277|       |
  278|  6.13k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  6.13k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  279|  6.13k|	r = sc_hsm_select_file(card, &path, &file);
  280|  6.13k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.13k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.13k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.13k|	int _ret = (r); \
  |  |  |  |  168|  6.13k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.78k, False: 347]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.78k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.78k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.78k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.78k|		return _ret; \
  |  |  |  |  172|  5.78k|	} \
  |  |  |  |  173|  6.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 347]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|       |
  282|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  283|    347|	if (file != NULL) {
  ------------------
  |  Branch (283:6): [True: 347, False: 0]
  ------------------
  284|    347|		size_t sz = file->prop_attr_len;
  285|    347|		sc_file_free(file);
  286|    347|		if (sz < 2) {
  ------------------
  |  Branch (286:7): [True: 345, False: 2]
  ------------------
  287|    345|			return 0;
  288|    345|		}
  289|    347|	}
  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|    347|}
card-sc-hsm.c:sc_hsm_select_file:
  247|  8.50k|{
  248|  8.50k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  249|  8.50k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  149|  10.1k|{
  150|  10.1k|	int rv;
  151|  10.1k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  152|  10.1k|	sc_file_t *file = NULL;
  153|  10.1k|	sc_path_t cpath;
  154|  10.1k|	size_t card_max_recv_size = card->max_recv_size;
  155|  10.1k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  156|       |
  157|  10.1k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (157:6): [True: 1.34k, False: 8.78k]
  ------------------
  158|  1.34k|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  159|  1.34k|		sc_file_free(file);
  160|  1.34k|		return rv;
  161|  1.34k|	}
  162|       |
  163|  8.78k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  8.78k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (163:6): [True: 103, False: 8.68k]
  |  Branch (163:49): [True: 0, False: 103]
  ------------------
  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|  8.78k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  17.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (180:6): [True: 7.32k, False: 1.45k]
  ------------------
  181|  1.45k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.91k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (181:8): [True: 1.35k, False: 103]
  ------------------
  182|  1.35k|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (182:8): [True: 0, False: 1.35k]
  ------------------
  183|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (183:8): [True: 0, False: 0]
  ------------------
  184|  1.45k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.91k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:8): [True: 1.35k, False: 103]
  ------------------
  185|  1.35k|				&& in_path->len == 0
  ------------------
  |  Branch (185:8): [True: 0, False: 1.35k]
  ------------------
  186|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  7.32k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (187:8): [True: 0, False: 0]
  ------------------
  188|  7.32k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (188:7): [True: 6.13k, False: 1.19k]
  |  Branch (188:16): [True: 902, False: 297]
  |  Branch (188:41): [True: 0, False: 297]
  ------------------
  189|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  190|  7.03k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|  7.03k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  191|  7.03k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  192|  7.03k|			card->max_recv_size = card_max_recv_size;
  193|  7.03k|			card->reader->max_recv_size = reader_max_recv_size;
  194|  7.03k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  7.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.03k|	int _ret = (r); \
  |  |  |  |  168|  7.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.44k, False: 591]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.44k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.44k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.44k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.44k|		return _ret; \
  |  |  |  |  172|  6.44k|	} \
  |  |  |  |  173|  7.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 591]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    591|			if (priv) {
  ------------------
  |  Branch (196:8): [True: 244, False: 347]
  ------------------
  197|    244|				sc_file_free(priv->dffcp);
  198|       |				// Cache the FCP returned when selecting the applet
  199|    244|				sc_file_dup(&priv->dffcp, *file_out);
  200|    244|			}
  201|    591|		} else {
  202|    297|			sc_file_dup(file_out, priv->dffcp);
  203|    297|			rv = SC_SUCCESS;
  ------------------
  |  |   28|    297|#define SC_SUCCESS				0
  ------------------
  204|    297|		}
  205|    888|		return rv;
  206|  7.32k|	}
  207|       |
  208|  1.45k|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (208:6): [True: 1.45k, False: 0]
  |  Branch (208:29): [True: 834, False: 621]
  |  Branch (208:60): [True: 827, False: 7]
  ------------------
  209|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  210|    827|		if (in_path->len == 2) {
  ------------------
  |  Branch (210:7): [True: 1, False: 826]
  ------------------
  211|      1|			file = sc_file_new();
  212|      1|			if (file == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 1]
  ------------------
  213|      1|				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|      1|			file->path = *in_path;
  215|      1|			file->id = 0x3F00;
  216|      1|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      1|#define SC_FILE_TYPE_DF			0x04
  ------------------
  217|      1|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      1|#define SC_FILE_MAGIC			0x14426950
  ------------------
  218|       |
  219|      1|			*file_out = file;
  220|      1|			return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  221|    826|		} else {
  222|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  223|    826|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    826|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  224|    826|			sc_path_t truncated;
  225|    826|			memcpy(&truncated, in_path, sizeof truncated);
  226|    826|			truncated.len = in_path->len - 2;
  227|    826|			memcpy(truncated.value, in_path->value+2, truncated.len);
  228|    826|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  229|    826|			card->max_recv_size = card_max_recv_size;
  230|    826|			card->reader->max_recv_size = reader_max_recv_size;
  231|    826|			return rv;
  232|    826|		}
  233|    827|	}
  234|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  235|    628|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    628|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  236|    628|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  237|    628|	card->max_recv_size = card_max_recv_size;
  238|    628|	card->reader->max_recv_size = reader_max_recv_size;
  239|    628|	return rv;
  240|  1.45k|}
card-sc-hsm.c:sc_hsm_read_binary:
  799|    666|{
  800|    666|	sc_context_t *ctx = card->ctx;
  801|    666|	sc_apdu_t apdu;
  802|    666|	u8 cmdbuff[4];
  803|    666|	int r;
  804|       |
  805|    666|	if (idx > 0xffff) {
  ------------------
  |  Branch (805:6): [True: 0, False: 666]
  ------------------
  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|    666|	cmdbuff[0] = 0x54;
  811|    666|	cmdbuff[1] = 0x02;
  812|    666|	cmdbuff[2] = (idx >> 8) & 0xFF;
  813|    666|	cmdbuff[3] = idx & 0xFF;
  814|       |
  815|    666|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (815:6): [True: 0, False: 666]
  ------------------
  816|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  817|    666|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    666|#define SC_APDU_CASE_4			0x24
  ------------------
  818|    666|	apdu.data = cmdbuff;
  819|    666|	apdu.datalen = 4;
  820|    666|	apdu.lc = 4;
  821|    666|	apdu.le = count;
  822|    666|	apdu.resplen = count;
  823|    666|	apdu.resp = buf;
  824|       |
  825|    666|	r = sc_transmit_apdu(card, &apdu);
  826|    666|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    666|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    666|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    666|	int _ret = (r); \
  |  |  |  |  168|    666|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 661]
  |  |  |  |  ------------------
  |  |  |  |  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|    666|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 661]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    661|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  829|    661|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    661|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (829:6): [True: 582, False: 79]
  ------------------
  830|    582|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    582|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    582|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    582|	int _ret = (r); \
  |  |  |  |  168|    582|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 77, False: 505]
  |  |  |  |  ------------------
  |  |  |  |  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|    582|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 505]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|    582|	}
  832|       |
  833|    584|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    584|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    584|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    584|	int _ret = r; \
  |  |  |  |  155|    584|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 566]
  |  |  |  |  ------------------
  |  |  |  |  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|    566|	} else { \
  |  |  |  |  159|    566|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    566|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    566|	} \
  |  |  |  |  162|    584|	return _ret; \
  |  |  |  |  163|    584|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    584|}
card-sc-hsm.c:sc_hsm_set_security_env:
 1004|  1.72k|{
 1005|  1.72k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1006|       |
 1007|  1.72k|	priv->env = env;
 1008|       |
 1009|  1.72k|	switch(env->algorithm) {
 1010|  1.72k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|  1.72k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1010:2): [True: 1.72k, False: 0]
  ------------------
 1011|  1.72k|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  111|  1.72k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  1.72k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  1.72k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1011:7): [True: 0, False: 1.72k]
  ------------------
 1012|      0|			if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1) {
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1012:8): [True: 0, False: 0]
  ------------------
 1013|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA1;
  ------------------
  |  |   41|      0|#define ALGO_RSA_PKCS1_SHA1	0x31		/* RSA signature with SHA-1 hash and PKCS#1 V1.5 padding */
  ------------------
 1014|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256) {
  ------------------
  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (1014:15): [True: 0, False: 0]
  ------------------
 1015|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA256;
  ------------------
  |  |   42|      0|#define ALGO_RSA_PKCS1_SHA256	0x33		/* RSA signature with SHA-256 hash and PKCS#1 V1.5 padding */
  ------------------
 1016|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA384) {
  ------------------
  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (1016:15): [True: 0, False: 0]
  ------------------
 1017|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA384;
  ------------------
  |  |   43|      0|#define ALGO_RSA_PKCS1_SHA384	0x34		/* RSA signature with SHA-384 hash and PKCS#1 V1.5 padding */
  ------------------
 1018|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA512) {
  ------------------
  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (1018:15): [True: 0, False: 0]
  ------------------
 1019|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA512;
  ------------------
  |  |   44|      0|#define ALGO_RSA_PKCS1_SHA512	0x35		/* RSA signature with SHA-512 hash and PKCS#1 V1.5 padding */
  ------------------
 1020|      0|			} else {
 1021|      0|				priv->algorithm = ALGO_RSA_PKCS1;
  ------------------
  |  |   40|      0|#define ALGO_RSA_PKCS1		0x30		/* RSA signature with DigestInfo input and PKCS#1 V1.5 padding */
  ------------------
 1022|      0|			}
 1023|  1.72k|		} else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  107|  1.72k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1023:14): [True: 745, False: 979]
  ------------------
 1024|    745|			if ((env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) &&
  ------------------
  |  |  142|    745|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1024:8): [True: 0, False: 745]
  ------------------
 1025|      0|					(((env->algorithm_flags & SC_ALGORITHM_MGF1_HASHES) >> 8) != (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES))) {
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              					(((env->algorithm_flags & SC_ALGORITHM_MGF1_HASHES) >> 8) != (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES))) {
  ------------------
  |  |  142|      0|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1025:6): [True: 0, False: 0]
  ------------------
 1026|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1027|      0|			}
 1028|    745|			priv->algorithm = ALGO_RSA_PSS;
  ------------------
  |  |   46|    745|#define ALGO_RSA_PSS	    0x40 /* RSA signature with external hash and PKCS#1 PSS padding*/
  ------------------
 1029|    979|		} else {
 1030|    979|			if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|    979|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1030:8): [True: 234, False: 745]
  ------------------
 1031|    234|				priv->algorithm = ALGO_RSA_DECRYPT;
  ------------------
  |  |   39|    234|#define ALGO_RSA_DECRYPT	0x21		/* RSA decrypt */
  ------------------
 1032|    745|			} else {
 1033|    745|				priv->algorithm = ALGO_RSA_RAW;
  ------------------
  |  |   38|    745|#define ALGO_RSA_RAW		0x20		/* RSA signature with external padding */
  ------------------
 1034|    745|			}
 1035|    979|		}
 1036|  1.72k|		break;
 1037|  1.72k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1037:2): [True: 0, False: 1.72k]
  ------------------
 1038|      0|		if (env->operation == SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1038:7): [True: 0, False: 0]
  ------------------
 1039|      0|			priv->algorithm = ALGO_EC_DH;
  ------------------
  |  |   58|      0|#define ALGO_EC_DH     0x80 /* ECDH key derivation */
  ------------------
 1040|      0|		} else if (env->algorithm_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 */
  |  |  ------------------
  ------------------
  |  Branch (1040:14): [True: 0, False: 0]
  ------------------
 1041|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
 1042|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA1) {
  ------------------
  |  |  176|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  |  Branch (1042:14): [True: 0, False: 0]
  ------------------
 1043|      0|			priv->algorithm = ALGO_EC_SHA1;
  ------------------
  |  |   53|      0|#define ALGO_EC_SHA1   0x71 /* ECDSA signature with SHA-1 hash */
  ------------------
 1044|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA224) {
  ------------------
  |  |  177|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|      0|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
  |  Branch (1044:14): [True: 0, False: 0]
  ------------------
 1045|      0|			priv->algorithm = ALGO_EC_SHA224;
  ------------------
  |  |   54|      0|#define ALGO_EC_SHA224 0x72 /* ECDSA signature with SHA-224 hash */
  ------------------
 1046|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA256) {
  ------------------
  |  |  178|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  |  Branch (1046:14): [True: 0, False: 0]
  ------------------
 1047|      0|			priv->algorithm = ALGO_EC_SHA256;
  ------------------
  |  |   55|      0|#define ALGO_EC_SHA256 0x73 /* ECDSA signature with SHA-256 hash */
  ------------------
 1048|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA384) {
  ------------------
  |  |  179|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
  |  Branch (1048:14): [True: 0, False: 0]
  ------------------
 1049|      0|			priv->algorithm = ALGO_EC_SHA384;
  ------------------
  |  |   56|      0|#define ALGO_EC_SHA384 0x74 /* ECDSA signature with SHA-384 hash */
  ------------------
 1050|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA512) {
  ------------------
  |  |  180|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  |  Branch (1050:14): [True: 0, False: 0]
  ------------------
 1051|      0|			priv->algorithm = ALGO_EC_SHA512;
  ------------------
  |  |   57|      0|#define ALGO_EC_SHA512 0x75 /* ECDSA signature with SHA-512 hash */
  ------------------
 1052|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW) {
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (1052:14): [True: 0, False: 0]
  ------------------
 1053|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
 1054|      0|		} else {
 1055|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1056|      0|		}
 1057|      0|		break;
 1058|      0|	default:
  ------------------
  |  Branch (1058:2): [True: 0, False: 1.72k]
  ------------------
 1059|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1060|      0|		break;
 1061|  1.72k|	}
 1062|  1.72k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.72k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.72k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1063|  1.72k|}
card-sc-hsm.c:sc_hsm_compute_signature:
 1086|  1.49k|{
 1087|  1.49k|	int r;
 1088|  1.49k|	sc_apdu_t apdu;
 1089|  1.49k|	u8 rbuf[514];
 1090|  1.49k|	sc_hsm_private_data_t *priv;
 1091|       |
 1092|  1.49k|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1092:6): [True: 0, False: 1.49k]
  |  Branch (1092:22): [True: 0, False: 1.49k]
  |  Branch (1092:38): [True: 0, False: 1.49k]
  ------------------
 1093|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1094|      0|	}
 1095|  1.49k|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1096|       |
 1097|  1.49k|	if (priv->env == NULL) {
  ------------------
  |  Branch (1097:6): [True: 0, False: 1.49k]
  ------------------
 1098|      0|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1099|      0|	}
 1100|       |
 1101|  1.49k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x68, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|  1.49k|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|  1.49k|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|  1.49k|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1102|  1.49k|	apdu.cla = 0x80;
 1103|  1.49k|	apdu.resp = rbuf;
 1104|  1.49k|	apdu.resplen = sizeof(rbuf);
 1105|  1.49k|	apdu.le = 512;
 1106|       |
 1107|  1.49k|	apdu.data = data;
 1108|  1.49k|	apdu.lc = datalen;
 1109|  1.49k|	apdu.datalen = datalen;
 1110|  1.49k|	r = sc_transmit_apdu(card, &apdu);
 1111|       |
 1112|  1.49k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.49k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.49k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.49k|	int _ret = (r); \
  |  |  |  |  168|  1.49k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 233, False: 1.25k]
  |  |  |  |  ------------------
  |  |  |  |  169|    233|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    233|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    233|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    233|		return _ret; \
  |  |  |  |  172|    233|	} \
  |  |  |  |  173|  1.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1113|  1.25k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1113:6): [True: 132, False: 1.12k]
  |  Branch (1113:26): [True: 112, False: 20]
  ------------------
 1114|    112|		int len;
 1115|       |
 1116|    112|		if ((priv->algorithm & 0xF0) == ALGO_EC_RAW) {
  ------------------
  |  |   52|    112|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
  |  Branch (1116:7): [True: 0, False: 112]
  ------------------
 1117|      0|			len = sc_hsm_decode_ecdsa_signature(card, apdu.resp, apdu.resplen, out, outlen, priv->env->key_size_bits);
 1118|      0|			if (len < 0) {
  ------------------
  |  Branch (1118:8): [True: 0, False: 0]
  ------------------
 1119|      0|				LOG_FUNC_RETURN(card->ctx, 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1120|      0|			}
 1121|    112|		} else {
 1122|    112|			len = (int)(apdu.resplen > outlen ? outlen : apdu.resplen);
  ------------------
  |  Branch (1122:16): [True: 0, False: 112]
  ------------------
 1123|    112|			memcpy(out, apdu.resp, len);
 1124|    112|		}
 1125|    112|		LOG_FUNC_RETURN(card->ctx, len);
  ------------------
  |  |  164|    112|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    112|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    112|	int _ret = r; \
  |  |  |  |  155|    112|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 46, False: 66]
  |  |  |  |  ------------------
  |  |  |  |  156|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  157|     46|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     66|	} else { \
  |  |  |  |  159|     66|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     66|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     66|	} \
  |  |  |  |  162|    112|	return _ret; \
  |  |  |  |  163|    112|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1126|    112|	}
 1127|  1.14k|	LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  1.14k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.14k|	int _ret = r; \
  |  |  |  |  155|  1.14k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.14k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.14k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.14k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.14k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.14k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.14k|	return _ret; \
  |  |  |  |  163|  1.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|  1.14k|}
card-sc-hsm.c:sc_hsm_decipher:
 1133|    222|{
 1134|    222|	int r;
 1135|    222|	size_t len;
 1136|    222|	sc_apdu_t apdu;
 1137|    222|	u8 rbuf[514];
 1138|    222|	sc_hsm_private_data_t *priv;
 1139|       |
 1140|    222|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1140:6): [True: 0, False: 222]
  |  Branch (1140:22): [True: 0, False: 222]
  |  Branch (1140:40): [True: 0, False: 222]
  ------------------
 1141|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1142|      0|	}
 1143|    222|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    222|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    222|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    222|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    222|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 222]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|    222|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1145|       |
 1146|    222|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x62, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|    222|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|    222|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|    222|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1147|    222|	apdu.cla = 0x80;
 1148|    222|	apdu.resp = rbuf;
 1149|    222|	apdu.resplen = sizeof(rbuf);
 1150|    222|	apdu.le = 512;
 1151|       |
 1152|    222|	apdu.data = (u8 *)crgram;
 1153|    222|	apdu.lc = crgram_len;
 1154|    222|	apdu.datalen = crgram_len;
 1155|       |
 1156|    222|	r = sc_transmit_apdu(card, &apdu);
 1157|       |
 1158|    222|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    222|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    222|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    222|	int _ret = (r); \
  |  |  |  |  168|    222|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36, False: 186]
  |  |  |  |  ------------------
  |  |  |  |  169|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     36|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     36|		return _ret; \
  |  |  |  |  172|     36|	} \
  |  |  |  |  173|    222|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 186]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1159|    186|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1159:6): [True: 56, False: 130]
  |  Branch (1159:26): [True: 51, False: 5]
  ------------------
 1160|     51|		if (priv->algorithm == ALGO_EC_DH) {
  ------------------
  |  |   58|     51|#define ALGO_EC_DH     0x80 /* ECDH key derivation */
  ------------------
  |  Branch (1160:7): [True: 0, False: 51]
  ------------------
 1161|       |			//
 1162|       |			// The SmartCard-HSM returns the point result of the DH operation
 1163|       |			// with a leading '04'
 1164|      0|			if (apdu.resplen <= 0)
  ------------------
  |  Branch (1164:8): [True: 0, False: 0]
  ------------------
 1165|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1166|      0|			len = apdu.resplen - 1 > outlen ? outlen : apdu.resplen - 1;
  ------------------
  |  Branch (1166:10): [True: 0, False: 0]
  ------------------
 1167|      0|			memcpy(out, apdu.resp + 1, len);
 1168|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|     51|		} else {
 1170|     51|			len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1170:10): [True: 0, False: 51]
  ------------------
 1171|     51|			memcpy(out, apdu.resp, len);
 1172|     51|			LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  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|     47|	} else { \
  |  |  |  |  159|     47|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     47|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     47|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1173|     51|		}
 1174|     51|	}
 1175|    135|	else
 1176|    186|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|    135|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    135|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    135|	int _ret = r; \
  |  |  |  |  155|    135|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 135, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    135|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    135|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 135, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    135|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    135|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    135|	return _ret; \
  |  |  |  |  163|    135|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1177|    186|}
card-sc-hsm.c:sc_hsm_init:
 1802|    279|{
 1803|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1804|       |	char expanded_val[PATH_MAX];
 1805|       |	size_t expanded_len = PATH_MAX;
 1806|       |#endif
 1807|    279|	int flags,ext_flags;
 1808|    279|	sc_file_t *file = NULL;
 1809|    279|	sc_path_t path;
 1810|    279|	sc_hsm_private_data_t *priv = NULL;
 1811|       |
 1812|    279|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    279|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    279|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    279|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    279|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1813|       |
 1814|    279|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    279|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  107|    279|#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|    279|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1815|    279|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  134|    279|#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|    279|#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|    279|#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|    279|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1816|    279|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  146|    279|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  147|    279|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  148|    279|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1817|       |
 1818|    279|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1819|    279|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1820|    279|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1821|    279|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1822|    279|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1823|       |
 1824|    279|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|    279|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1825|    279|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|    279|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1826|    279|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|    279|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    279|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1827|    279|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  176|    279|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    279|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1828|    279|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  177|    279|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|    279|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1829|    279|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  178|    279|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    279|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1830|    279|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  179|    279|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|    279|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1831|    279|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  180|    279|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|    279|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1832|    279|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    279|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1833|       |
 1834|    279|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  198|    279|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1835|    279|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  200|    279|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1836|    279|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  201|    279|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1837|    279|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  202|    279|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1838|    279|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    279|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1839|    279|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1840|    279|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1841|    279|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1842|    279|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1843|    279|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1844|    279|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1845|    279|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1846|       |
 1847|    279|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    279|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|    279|#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|    279|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1848|       |
 1849|       |	// APDU Size limits
 1850|       |	//   JCOP 2.4.1r3           1462
 1851|       |	//   JCOP 2.4.2r3           1454
 1852|       |	//   JCOP 3                 1232
 1853|       |	//   JCOP 4                 1454
 1854|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1855|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1856|       |	//
 1857|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1858|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1859|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1860|       |	// class 3 APDU
 1861|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1862|       |
 1863|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1864|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1865|    279|	card->max_send_size = 1232 - 9;
 1866|       |	// Assume that card supports sending with extended length APDU and without limit
 1867|    279|	card->max_recv_size = 0;
 1868|       |
 1869|    279|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1869:6): [True: 0, False: 279]
  ------------------
 1870|    279|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1870:7): [True: 277, False: 2]
  ------------------
 1871|    277|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1872|    277|	} else {
 1873|       |		// Adjust to the limits set by the reader
 1874|      2|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1874:7): [True: 2, False: 0]
  ------------------
 1875|      2|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1875:8): [True: 2, False: 0]
  ------------------
 1876|      2|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1877|       |
 1878|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1879|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1880|      0|		}
 1881|       |
 1882|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1882:7): [True: 0, False: 0]
  ------------------
 1883|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1883:8): [True: 0, False: 0]
  ------------------
 1884|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1885|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1886|      0|		}
 1887|      0|	}
 1888|       |
 1889|    277|	priv = card->drv_data;
 1890|    277|	if (!priv) {
  ------------------
  |  Branch (1890:6): [True: 277, False: 0]
  ------------------
 1891|    277|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1892|    277|		if (!priv)
  ------------------
  |  Branch (1892:7): [True: 0, False: 277]
  ------------------
 1893|    277|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1894|    277|		card->drv_data = priv;
 1895|    277|	}
 1896|       |
 1897|    277|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    277|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1898|    277|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    554|#define SC_SUCCESS				0
  ------------------
  |  Branch (1898:6): [True: 53, False: 224]
  ------------------
 1899|     53|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1899:7): [True: 53, False: 0]
  |  Branch (1899:15): [True: 5, False: 48]
  |  Branch (1899:34): [True: 4, False: 1]
  ------------------
 1900|      4|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1901|      4|		u8 type = 0xFF;
 1902|      4|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1903|      4|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1904|      4|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1905|      4|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1906|      4|		char *p = "SmartCard-HSM";
 1907|      4|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1907:7): [True: 3, False: 1]
  ------------------
 1908|      3|			type = file->prop_attr[file->prop_attr_len - 3];
 1909|      3|		}
 1910|      4|		switch (type) {
 1911|      1|			case 0x00:
  ------------------
  |  Branch (1911:4): [True: 1, False: 3]
  ------------------
 1912|      1|				p = p00;
 1913|      1|				break;
 1914|      1|			case 0x01:
  ------------------
  |  Branch (1914:4): [True: 1, False: 3]
  ------------------
 1915|      1|				p = p01;
 1916|      1|				break;
 1917|      2|			default:
  ------------------
  |  Branch (1917:4): [True: 2, False: 2]
  ------------------
 1918|      2|				break;
 1919|      4|		}
 1920|      4|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1921|      4|		card->name = card_name;
 1922|       |
 1923|      4|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1923:7): [True: 1, False: 3]
  ------------------
 1924|      1|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  563|      1|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1925|      1|		}
 1926|      4|	}
 1927|    277|	sc_file_free(file);
 1928|       |
 1929|    277|	priv->EF_C_DevAut = NULL;
 1930|    277|	priv->EF_C_DevAut_len = 0;
 1931|       |
 1932|    277|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1933|    277|	EAC_init();
 1934|       |#ifdef _WIN32
 1935|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1936|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1937|       |		EAC_set_cvc_default_dir(expanded_val);
 1938|       |#else
 1939|    277|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    277|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1940|    277|#endif
 1941|    277|#endif
 1942|       |
 1943|    277|	return 0;
 1944|    277|}
card-sc-hsm.c:sc_hsm_finish:
 1949|    277|{
 1950|    277|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1951|    277|#ifdef ENABLE_SM
 1952|    277|	sc_sm_stop(card);
 1953|    277|#endif
 1954|    277|	if (priv) {
  ------------------
  |  Branch (1954:6): [True: 277, False: 0]
  ------------------
 1955|    277|		free(priv->serialno);
 1956|    277|		sc_file_free(priv->dffcp);
 1957|    277|		free(priv->EF_C_DevAut);
 1958|    277|	}
 1959|    277|	free(priv);
 1960|       |
 1961|    277|	return SC_SUCCESS;
  ------------------
  |  |   28|    277|#define SC_SUCCESS				0
  ------------------
 1962|    277|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1773|    168|{
 1774|    168|	switch (cmd) {
  ------------------
  |  Branch (1774:10): [True: 168, False: 0]
  ------------------
 1775|    168|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1775:2): [True: 168, False: 0]
  ------------------
 1776|    168|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1777|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1777:2): [True: 0, False: 168]
  ------------------
 1778|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1779|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1779:2): [True: 0, False: 168]
  ------------------
 1780|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1781|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1781:2): [True: 0, False: 168]
  ------------------
 1782|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1783|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1783:2): [True: 0, False: 168]
  ------------------
 1784|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1785|      0|	case SC_CARDCTL_SC_HSM_MANAGE_KEY_DOMAIN:
  ------------------
  |  Branch (1785:2): [True: 0, False: 168]
  ------------------
 1786|      0|		return sc_hsm_manage_key_domain(card, (sc_cardctl_sc_hsm_key_domain_t *)ptr);
 1787|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1787:2): [True: 0, False: 168]
  ------------------
 1788|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1789|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1789:2): [True: 0, False: 168]
  ------------------
 1790|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1791|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1791:2): [True: 0, False: 168]
  ------------------
 1792|      0|		return sc_hsm_register_public_key(card, ptr);
 1793|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1793:2): [True: 0, False: 168]
  ------------------
 1794|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1795|    168|	}
 1796|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1797|    168|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1195|    168|{
 1196|    168|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1197|       |
 1198|    168|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    168|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    168|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    168|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    168|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 168]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|       |
 1200|    168|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1200:6): [True: 168, False: 0]
  |  Branch (1200:25): [True: 0, False: 168]
  ------------------
 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|    168|	if (!priv->serialno) {
  ------------------
  |  Branch (1210:6): [True: 168, False: 0]
  ------------------
 1211|    168|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    168|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1212|    168|	}
 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|    525|{
  621|    525|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|    525|	sc_apdu_t apdu;
  623|    525|	u8 cmdbuff[16];
  624|    525|#ifdef ENABLE_SM
  625|    525|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|    525|#endif
  627|    525|	int r;
  628|    525|	int cmd = data->cmd;
  629|    525|	size_t pin2_len = data->pin2.len;
  630|       |
  631|    525|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|    525|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 525]
  ------------------
  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|    525|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    525|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 525]
  ------------------
  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|    525|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    525|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 525]
  ------------------
  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|    525|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|    525|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 525]
  ------------------
  655|    525|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 525, 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|    525|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  418|    525|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 33, False: 492]
  ------------------
  658|     33|		struct sc_pin_cmd_data check_sm_pin_data;
  659|     33|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|     33|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     33|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|     33|		check_sm_pin_data.pin_type = data->pin_type;
  662|     33|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|     33|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     33|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|     33|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|     33|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 33]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  668|      0|		}
  669|     33|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|     66|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|     33|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 33]
  |  Branch (669:46): [True: 33, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|     33|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  174|     33|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     33|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     33|	int _ret = (r); \
  |  |  |  |  168|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     33|		return _ret; \
  |  |  |  |  172|     33|	} \
  |  |  |  |  173|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|     33|					sc_hsm_perform_chip_authentication(card),
  673|     33|					"Could not perform chip authentication");
  674|     33|		}
  675|     33|	}
  676|    492|#endif
  677|       |
  678|    492|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    492|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 492]
  ------------------
  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|    492|	} else {
  684|    492|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  415|    492|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 492]
  |  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|    492|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  416|    492|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 492]
  |  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|    492|#ifdef ENABLE_SM
  714|    492|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|    492|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 492, False: 0]
  ------------------
  715|    492|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|    492|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 492]
  ------------------
  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|    492|#endif
  723|       |
  724|    492|		data->pin1.offset = 5;
  725|    492|		data->pin2.offset = 5;
  726|       |
  727|    492|		r = (*iso_ops->pin_cmd)(card, data);
  728|    492|		data->apdu = NULL;
  729|    492|	}
  730|    492|	LOG_TEST_RET(card->ctx, r, "Verification failed");
  ------------------
  |  |  174|    492|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    492|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    492|	int _ret = (r); \
  |  |  |  |  168|    492|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 317, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  169|    317|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    317|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    317|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    317|		return _ret; \
  |  |  |  |  172|    317|	} \
  |  |  |  |  173|    492|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|    175|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|    175|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (732:6): [True: 0, False: 175]
  ------------------
  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|    175|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    175|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    175|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    175|	int _ret = r; \
  |  |  |  |  155|    175|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 175, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    175|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  157|    175|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    175|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    175|	return _ret; \
  |  |  |  |  163|    175|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|    175|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  492|     33|{
  493|     33|	int r, protocol;
  494|     33|	sc_path_t path;
  495|     33|	u8 all_certs[1024];
  496|     33|	EAC_CTX *ctx = NULL;
  497|     33|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  498|     33|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  499|     33|	BUF_MEM *comp_pub_key = NULL;
  500|     33|	sc_cvc_t cvc_device, cvc_issuer;
  501|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  502|     33|	sc_pkcs15_card_t p15card;
  503|     33|	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|     33|	p15card.card = card;
  507|       |
  508|     33|	memset(&cvc_device, 0, sizeof(cvc_device));
  509|     33|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  510|       |
  511|       |
  512|     33|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (512:6): [True: 5, False: 28]
  |  Branch (512:27): [True: 5, False: 0]
  ------------------
  513|      5|		all_certs_len = priv->EF_C_DevAut_len;
  514|      5|		cert = priv->EF_C_DevAut;
  515|     28|	} else {
  516|       |		/* get issuer and device certificate from the card */
  517|     28|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|     28|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  518|     28|		if (r < 0)
  ------------------
  |  Branch (518:7): [True: 0, False: 28]
  ------------------
  519|      0|			goto err;
  520|     28|		r = sc_select_file(card, &path, NULL);
  521|     28|		if (r < 0)
  ------------------
  |  Branch (521:7): [True: 14, False: 14]
  ------------------
  522|     14|			goto err;
  523|     14|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  524|     14|		if (r < 0)
  ------------------
  |  Branch (524:7): [True: 5, False: 9]
  ------------------
  525|      5|			goto err;
  526|      9|		if (r == 0) {
  ------------------
  |  Branch (526:7): [True: 3, False: 6]
  ------------------
  527|      3|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      3|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  528|      3|			goto err;
  529|      3|		}
  530|       |
  531|      6|		all_certs_len = r;
  532|       |
  533|       |		/* save EF_C_DevAut for further use */
  534|      6|		cert = realloc(priv->EF_C_DevAut, all_certs_len);
  535|      6|		if (cert) {
  ------------------
  |  Branch (535:7): [True: 6, False: 0]
  ------------------
  536|      6|			memcpy((unsigned char *) cert, all_certs, all_certs_len);
  537|      6|			priv->EF_C_DevAut = (unsigned char *) cert;
  538|      6|			priv->EF_C_DevAut_len = all_certs_len;
  539|      6|		}
  540|       |
  541|      6|		cert = all_certs;
  542|      6|	}
  543|     11|	left = all_certs_len;
  544|       |
  545|     11|	device_cert = cert;
  546|     11|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_device);
  547|     11|	if (r < 0)
  ------------------
  |  Branch (547:6): [True: 11, False: 0]
  ------------------
  548|     11|		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|     33|err:
  599|     33|	if (r < 0)
  ------------------
  |  Branch (599:6): [True: 33, False: 0]
  ------------------
  600|     33|		EAC_CTX_clear_free(ctx);
  601|     33|	if (comp_pub_key)
  ------------------
  |  Branch (601:6): [True: 0, False: 33]
  ------------------
  602|      0|		BUF_MEM_free(comp_pub_key);
  603|     33|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  604|     33|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  605|       |
  606|     33|	return r;
  607|      0|}

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

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

sc_get_srbeid_driver:
  305|  16.9k|{
  306|       |	/* Save ISO ops for delegation, then override what we handle. */
  307|  16.9k|	iso_ops = sc_get_iso7816_driver()->ops;
  308|  16.9k|	srbeid_ops = *iso_ops;
  309|  16.9k|	srbeid_ops.match_card = srbeid_match_card;
  310|  16.9k|	srbeid_ops.init = srbeid_init;
  311|  16.9k|	srbeid_ops.select_file = srbeid_select_file;
  312|  16.9k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  313|  16.9k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  314|  16.9k|	srbeid_ops.decipher = srbeid_decipher;
  315|       |
  316|  16.9k|	return &srbeid_drv;
  317|  16.9k|}
card-srbeid.c:srbeid_match_card:
   72|  7.85k|{
   73|  7.85k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  7.85k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|    551|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|    551|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 551, False: 7.30k]
  |  Branch (74:16): [True: 302, False: 249]
  ------------------
   75|    302|		card->name = srbeid_atrs[i].name;
   76|    302|		return 1;
   77|    302|	}
   78|  7.55k|	return 0;
   79|  7.85k|}
card-srbeid.c:srbeid_init:
   83|    302|{
   84|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|       |
   86|    302|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    302|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
   87|       |
   88|       |	/* Keep the card's own PKCS#1 signing, and add raw RSA on top: that gives
   89|       |	 * CKM_RSA_X_509 and makes 2048-bit decrypt work (OpenSC does the padding). */
   90|    302|	_sc_card_add_rsa_alg(card, 2048,
   91|    302|			SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_RAW |
  ------------------
  |  |  109|    302|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              			SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_RAW |
  ------------------
  |  |  102|    302|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   92|    302|					SC_ALGORITHM_RSA_HASH_NONE,
  ------------------
  |  |  133|    302|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   93|    302|			0);
   94|       |
   95|    302|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    302|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    302|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    302|	int _ret = r; \
  |  |  |  |  155|    302|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 302, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    302|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  157|    302|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    302|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    302|	return _ret; \
  |  |  |  |  163|    302|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   96|    302|}
card-srbeid.c:srbeid_select_file:
  112|  3.10k|{
  113|  3.10k|	sc_apdu_t apdu;
  114|  3.10k|	u8 fci[16];
  115|  3.10k|	sc_file_t *file;
  116|  3.10k|	int r;
  117|       |
  118|  3.10k|	if (in_path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  3.10k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (118:6): [True: 671, False: 2.43k]
  ------------------
  119|    671|		return iso_ops->select_file(card, in_path, file_out);
  120|       |
  121|       |	/* AID-only path (path.len==0, path.aid.len>0): PKCS#15 layer wants
  122|       |	 * to select the applet before a PIN or key operation. */
  123|  2.43k|	if (in_path->len == 0 && in_path->aid.len > 0)
  ------------------
  |  Branch (123:6): [True: 740, False: 1.69k]
  |  Branch (123:27): [True: 740, False: 0]
  ------------------
  124|    740|		return iso7816_select_aid(card, in_path->aid.value,
  125|    740|				in_path->aid.len, NULL, NULL);
  126|       |
  127|  1.69k|	if (in_path->len != 2)
  ------------------
  |  Branch (127:6): [True: 906, False: 788]
  ------------------
  128|  1.69k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    906|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    906|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    906|	int _ret = r; \
  |  |  |  |  155|    906|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 906, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    906|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    906|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 906, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    906|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    906|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    906|	return _ret; \
  |  |  |  |  163|    906|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  129|       |
  130|    788|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|    788|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  131|    788|	apdu.data = in_path->value;
  132|    788|	apdu.datalen = 2;
  133|    788|	apdu.lc = 2;
  134|    788|	apdu.resp = fci;
  135|    788|	apdu.resplen = sizeof(fci);
  136|    788|	apdu.le = 10;
  137|       |
  138|    788|	r = sc_transmit_apdu(card, &apdu);
  139|    788|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    788|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    788|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    788|	int _ret = (r); \
  |  |  |  |  168|    788|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 759]
  |  |  |  |  ------------------
  |  |  |  |  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|    788|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 759]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|    759|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  141|    759|	LOG_TEST_RET(card->ctx, r, "SELECT FILE 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: 238, False: 521]
  |  |  |  |  ------------------
  |  |  |  |  169|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    238|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    238|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    238|		return _ret; \
  |  |  |  |  172|    238|	} \
  |  |  |  |  173|    759|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 521]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  142|       |
  143|    521|	if (apdu.resplen < 4)
  ------------------
  |  Branch (143:6): [True: 53, False: 468]
  ------------------
  144|    521|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  145|       |
  146|    468|	if (file_out) {
  ------------------
  |  Branch (146:6): [True: 381, False: 87]
  ------------------
  147|    381|		file = sc_file_new();
  148|    381|		if (!file)
  ------------------
  |  Branch (148:7): [True: 0, False: 381]
  ------------------
  149|    381|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|    381|		file->id = ((unsigned)in_path->value[0] << 8) | in_path->value[1];
  152|    381|		file->path = *in_path;
  153|    381|		file->size = ((size_t)fci[2] << 8) | (size_t)fci[3];
  154|    381|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    381|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  155|    381|		*file_out = file;
  156|    381|	}
  157|       |
  158|    468|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    468|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    468|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    468|	int _ret = r; \
  |  |  |  |  155|    468|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 468, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    468|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 468]
  |  |  |  |  ------------------
  |  |  |  |  157|    468|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    468|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    468|	return _ret; \
  |  |  |  |  163|    468|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|    468|}
card-srbeid.c:srbeid_set_security_env:
  177|    544|{
  178|    544|	sc_apdu_t apdu;
  179|    544|	u8 mse_data[7];
  180|    544|	unsigned key_ref;
  181|    544|	u8 p2;
  182|    544|	int r;
  183|       |
  184|    544|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    544|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    544|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    544|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    544|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 544]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|    544|	(void)se_num;
  186|       |
  187|       |	/* Extract key FID. */
  188|    544|	if ((env->flags & SC_SEC_ENV_FILE_REF_PRESENT) && env->file_ref.len >= 2) {
  ------------------
  |  |   57|    544|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (188:6): [True: 0, False: 544]
  |  Branch (188:52): [True: 0, False: 0]
  ------------------
  189|      0|		key_ref = ((unsigned)env->file_ref.value[0] << 8) | (unsigned)env->file_ref.value[1];
  190|    544|	} else if ((env->flags & SC_SEC_ENV_KEY_REF_PRESENT) && env->key_ref_len >= 1) {
  ------------------
  |  |   58|    544|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (190:13): [True: 544, False: 0]
  |  Branch (190:58): [True: 544, False: 0]
  ------------------
  191|    544|		key_ref = CE_KEYS_BASE_FID | (unsigned)env->key_ref[0];
  ------------------
  |  |   33|    544|#define CE_KEYS_BASE_FID 0x6000u
  ------------------
  192|    544|	} else {
  193|      0|		sc_log(card->ctx, "srbeid: set_security_env: no 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__
  |  |  ------------------
  ------------------
  194|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  195|      0|	}
  196|       |
  197|       |	/* Determine MSE SET template from operation type. */
  198|    544|	switch (env->operation) {
  199|    291|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    291|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (199:2): [True: 291, False: 253]
  ------------------
  200|    291|		p2 = 0xB6;
  201|    291|		break;
  202|    253|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    253|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (202:2): [True: 253, False: 291]
  ------------------
  203|    253|		p2 = 0xB8;
  204|    253|		break;
  205|      0|	default:
  ------------------
  |  Branch (205:2): [True: 0, False: 544]
  ------------------
  206|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  207|    544|	}
  208|       |
  209|       |	/* MSE SET: tag 0x80 = algorithm, tag 0x84 = key ref (2 bytes BE).
  210|       |	 * The algorithm byte tells the card to pad (PKCS#1) or not (raw RSA). */
  211|    544|	mse_data[0] = 0x80;
  212|    544|	mse_data[1] = 0x01;
  213|    544|	mse_data[2] = (env->algorithm_flags & SC_ALGORITHM_RSA_RAW)
  ------------------
  |  |  102|    544|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (213:16): [True: 399, False: 145]
  ------------------
  214|    544|				      ? CE_MSE_ALG_RSA_RAW
  ------------------
  |  |   37|    399|#define CE_MSE_ALG_RSA_RAW   0x00u /* raw RSA; OpenSC pads */
  ------------------
  215|    544|				      : CE_MSE_ALG_RSA_PKCS1;
  ------------------
  |  |   36|    689|#define CE_MSE_ALG_RSA_PKCS1 0x02u /* card adds PKCS#1 padding */
  ------------------
  216|    544|	mse_data[3] = 0x84;
  217|    544|	mse_data[4] = 0x02;
  218|    544|	mse_data[5] = (u8)((key_ref >> 8) & 0xFF);
  219|    544|	mse_data[6] = (u8)(key_ref & 0xFF);
  220|       |
  221|    544|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, p2);
  ------------------
  |  |  293|    544|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  222|    544|	apdu.data = mse_data;
  223|    544|	apdu.datalen = sizeof(mse_data);
  224|    544|	apdu.lc = sizeof(mse_data);
  225|       |
  226|    544|	r = sc_transmit_apdu(card, &apdu);
  227|    544|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    544|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    544|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    544|	int _ret = (r); \
  |  |  |  |  168|    544|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 519]
  |  |  |  |  ------------------
  |  |  |  |  169|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     25|		return _ret; \
  |  |  |  |  172|     25|	} \
  |  |  |  |  173|    544|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 519]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  228|    519|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  229|    519|	LOG_TEST_RET(card->ctx, r, "MSE SET failed");
  ------------------
  |  |  174|    519|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    519|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    519|	int _ret = (r); \
  |  |  |  |  168|    519|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  169|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    232|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    232|		return _ret; \
  |  |  |  |  172|    232|	} \
  |  |  |  |  173|    519|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 287]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  230|       |
  231|    287|	sc_log(card->ctx, "srbeid: set_security_env: key_ref=0x%04x p2=0x%02x algo=0x%02x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|    287|			key_ref, p2, mse_data[2]);
  233|    287|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    287|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    287|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    287|	int _ret = r; \
  |  |  |  |  155|    287|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 287, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    287|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  157|    287|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    287|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    287|	return _ret; \
  |  |  |  |  163|    287|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    287|}
card-srbeid.c:srbeid_compute_signature:
  282|    138|{
  283|    138|	return srbeid_pso(card, 0x9E, data, datalen, out, outlen);
  284|    138|}
card-srbeid.c:srbeid_pso:
  243|    291|{
  244|    291|	sc_apdu_t apdu;
  245|    291|	u8 resp[256];
  246|    291|	u8 p2 = 0x00;
  247|    291|	int r;
  248|       |
  249|    291|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    291|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    291|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    291|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    291|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 291]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  250|       |
  251|    291|	if (datalen == 0 || datalen > sizeof(resp))
  ------------------
  |  Branch (251:6): [True: 23, False: 268]
  |  Branch (251:22): [True: 52, False: 216]
  ------------------
  252|    291|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     75|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     75|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     75|	int _ret = r; \
  |  |  |  |  155|     75|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 75, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     75|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 75, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     75|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     75|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     75|	return _ret; \
  |  |  |  |  163|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  253|       |
  254|    216|	if (datalen > SC_MAX_APDU_DATA_SIZE) {
  ------------------
  |  |   35|    216|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (254:6): [True: 79, False: 137]
  ------------------
  255|     79|		p2 = data[0];
  256|     79|		++data;
  257|     79|		--datalen;
  258|     79|	}
  259|       |
  260|    216|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, p1, p2);
  ------------------
  |  |  294|    216|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  261|    216|	apdu.data = data;
  262|    216|	apdu.datalen = apdu.lc = datalen;
  263|    216|	apdu.resp = resp;
  264|    216|	apdu.resplen = sizeof(resp);
  265|    216|	apdu.le = sizeof(resp);
  266|       |
  267|    216|	r = sc_transmit_apdu(card, &apdu);
  268|    216|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    216|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    216|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    216|	int _ret = (r); \
  |  |  |  |  168|    216|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 198]
  |  |  |  |  ------------------
  |  |  |  |  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|    216|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 198]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|    198|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  270|    198|	LOG_TEST_RET(card->ctx, r, "PSO failed");
  ------------------
  |  |  174|    198|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    198|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    198|	int _ret = (r); \
  |  |  |  |  168|    198|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 66, False: 132]
  |  |  |  |  ------------------
  |  |  |  |  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|    198|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 132]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|       |
  272|    132|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (272:6): [True: 0, False: 132]
  ------------------
  273|    132|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  274|    132|	memcpy(out, resp, apdu.resplen);
  275|    132|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 63, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  156|     63|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 63]
  |  |  |  |  ------------------
  |  |  |  |  157|     63|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|     69|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     69|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     69|	} \
  |  |  |  |  162|    132|	return _ret; \
  |  |  |  |  163|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  276|    132|}
card-srbeid.c:srbeid_decipher:
  295|    149|{
  296|    149|	int r = srbeid_pso(card, 0x80, crgram, crgram_len, out, outlen);
  297|       |
  298|    149|	if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    149|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (298:6): [True: 4, False: 145]
  ------------------
  299|      4|		r = srbeid_pso(card, 0x9E, crgram, crgram_len, out, outlen);
  300|    149|	return r;
  301|    149|}

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

sc_get_tcos_driver:
  720|  16.9k|{
  721|  16.9k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  722|       |
  723|  16.9k|	if (iso_ops == NULL) iso_ops = iso_drv->ops;
  ------------------
  |  Branch (723:6): [True: 1, False: 16.9k]
  ------------------
  724|  16.9k|	tcos_ops = *iso_drv->ops;
  725|       |
  726|  16.9k|	tcos_ops.match_card           = tcos_match_card;
  727|  16.9k|	tcos_ops.init                 = tcos_init;
  728|  16.9k|	tcos_ops.finish               = tcos_finish;
  729|  16.9k|	tcos_ops.create_file          = tcos_create_file;
  730|  16.9k|	tcos_ops.set_security_env     = tcos_set_security_env;
  731|  16.9k|	tcos_ops.select_file          = tcos_select_file;
  732|  16.9k|	tcos_ops.list_files           = tcos_list_files;
  733|  16.9k|	tcos_ops.delete_file          = tcos_delete_file;
  734|  16.9k|	tcos_ops.compute_signature    = tcos_compute_signature;
  735|  16.9k|	tcos_ops.decipher             = tcos_decipher;
  736|  16.9k|	tcos_ops.restore_security_env = tcos_restore_security_env;
  737|  16.9k|	tcos_ops.card_ctl             = tcos_card_ctl;
  738|       |
  739|  16.9k|	return &tcos_drv;
  740|  16.9k|}
card-tcos.c:tcos_match_card:
   77|  13.5k|{
   78|  13.5k|	int i;
   79|       |
   80|  13.5k|	i = _sc_match_atr(card, tcos_atrs, &card->type);
   81|  13.5k|	if (i < 0)
  ------------------
  |  Branch (81:6): [True: 12.4k, False: 1.08k]
  ------------------
   82|  12.4k|		return 0;
   83|  1.08k|	return 1;
   84|  13.5k|}
card-tcos.c:tcos_init:
   88|  1.08k|{
   89|  1.08k|	unsigned long flags;
   90|       |
   91|  1.08k|	tcos_data *data = malloc(sizeof(tcos_data));
   92|  1.08k|	if (!data) return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  |  Branch (92:6): [True: 0, False: 1.08k]
  ------------------
   93|       |
   94|  1.08k|	card->name = "TCOS";
   95|  1.08k|	card->drv_data = (void *)data;
   96|  1.08k|	card->cla = 0x00;
   97|       |
   98|  1.08k|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|  1.08k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   99|  1.08k|	flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|  1.08k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  1.08k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  1.08k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  100|  1.08k|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|  1.08k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  101|       |
  102|  1.08k|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  103|  1.08k|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  104|  1.08k|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  105|       |
  106|  1.08k|	if (card->type == SC_CARD_TYPE_TCOS_V3) {
  ------------------
  |  Branch (106:6): [True: 432, False: 648]
  ------------------
  107|    432|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    432|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  108|    432|		_sc_card_add_rsa_alg(card, 1280, flags, 0);
  109|    432|		_sc_card_add_rsa_alg(card, 1536, flags, 0);
  110|    432|		_sc_card_add_rsa_alg(card, 1792, flags, 0);
  111|    432|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  112|    432|	}
  113|       |
  114|  1.08k|	return 0;
  115|  1.08k|}
card-tcos.c:tcos_finish:
   70|  1.08k|{
   71|  1.08k|	free(card->drv_data);
   72|  1.08k|	return 0;
   73|  1.08k|}
card-tcos.c:tcos_set_security_env:
  474|    284|{
  475|    284|	sc_context_t *ctx;
  476|    284|	sc_apdu_t apdu;
  477|    284|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE], *p;
  478|    284|	int r, default_key, tcos3;
  479|    284|	tcos_data *data;
  480|       |
  481|    284|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (481:6): [True: 0, False: 284]
  |  Branch (481:22): [True: 0, False: 284]
  ------------------
  482|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  483|    284|	ctx = card->ctx;
  484|    284|	tcos3=(card->type==SC_CARD_TYPE_TCOS_V3);
  485|    284|	data=(tcos_data *)card->drv_data;
  486|       |
  487|    284|	if (se_num || (env->operation!=SC_SEC_OPERATION_DECIPHER && env->operation!=SC_SEC_OPERATION_SIGN)) {
  ------------------
  |  |   47|    568|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
              	if (se_num || (env->operation!=SC_SEC_OPERATION_DECIPHER && env->operation!=SC_SEC_OPERATION_SIGN)) {
  ------------------
  |  |   48|    174|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (487:6): [True: 0, False: 284]
  |  Branch (487:17): [True: 174, False: 110]
  |  Branch (487:62): [True: 0, False: 174]
  ------------------
  488|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  489|      0|	}
  490|    284|	if(!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT))
  ------------------
  |  |   58|    284|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (490:5): [True: 0, False: 284]
  ------------------
  491|      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__
  |  |  ------------------
  ------------------
  492|    284|			"No Key-Reference in SecEnvironment\n");
  493|    284|	else
  494|    284|		sc_log(ctx, "Key-Reference %02X (len=%zu)", env->key_ref[0], env->key_ref_len);
  ------------------
  |  |   71|    284|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  495|       |	/* Key-Reference 0x80 ?? */
  496|    284|	default_key= !(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len==1 && env->key_ref[0]==0x80);
  ------------------
  |  |   58|    284|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (496:15): [True: 0, False: 284]
  |  Branch (496:62): [True: 284, False: 0]
  |  Branch (496:85): [True: 47, False: 237]
  ------------------
  497|    284|	sc_log(ctx, "TCOS3:%d PKCS1 type 01:%d PKCS1 type 02: %d\n", tcos3,
  ------------------
  |  |   71|    284|#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)
  |  |  ------------------
  |  |  |  |  497|    568|	sc_log(ctx, "TCOS3:%d PKCS1 type 01:%d PKCS1 type 02: %d\n", tcos3,
  |  |  |  |  498|    568|			!!(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01),
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|    284|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |  499|    568|			!!(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02));
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    284|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  498|    284|			!!(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01),
  499|    284|			!!(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02));
  500|       |
  501|    284|	data->pad_flags = env->algorithm_flags;
  502|    284|	data->next_sign = default_key;
  503|       |
  504|    284|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, tcos3 ? 0x41 : 0xC1, 0xB8);
  ------------------
  |  |  293|    284|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (504:58): [True: 174, False: 110]
  ------------------
  505|    284|	p = sbuf;
  506|    284|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|    284|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (506:6): [True: 284, False: 0]
  ------------------
  507|    284|		*p++ = (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC) ? 0x83 : 0x84;
  ------------------
  |  |   59|    284|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (507:10): [True: 0, False: 284]
  ------------------
  508|    284|		*p++ = env->key_ref_len;
  509|    284|		memcpy(p, env->key_ref, env->key_ref_len);
  510|    284|		p += env->key_ref_len;
  511|    284|	}
  512|    284|	apdu.data = sbuf;
  513|    284|	apdu.lc = apdu.datalen = (p - sbuf);
  514|       |
  515|    284|	r=sc_transmit_apdu(card, &apdu);
  516|    284|	if (r) {
  ------------------
  |  Branch (516:6): [True: 18, False: 266]
  ------------------
  517|     18|		sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  518|     18|			"%s: APDU transmit failed", sc_strerror(r));
  519|     18|		return r;
  520|     18|	}
  521|    266|	if (apdu.sw1==0x6A && (apdu.sw2==0x81 || apdu.sw2==0x88)) {
  ------------------
  |  Branch (521:6): [True: 15, False: 251]
  |  Branch (521:25): [True: 1, False: 14]
  |  Branch (521:43): [True: 2, False: 12]
  ------------------
  522|      3|		sc_log(ctx,
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|      3|			"Detected Signature-Only key\n");
  524|      3|		if (env->operation==SC_SEC_OPERATION_SIGN && default_key) return SC_SUCCESS;
  ------------------
  |  |   48|      6|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
              		if (env->operation==SC_SEC_OPERATION_SIGN && default_key) return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (524:7): [True: 2, False: 1]
  |  Branch (524:48): [True: 1, False: 1]
  ------------------
  525|      3|	}
  526|    265|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    265|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    265|	int _ret = r; \
  |  |  155|    265|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 265, False: 0]
  |  |  ------------------
  |  |  156|    265|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 45, False: 220]
  |  |  ------------------
  |  |  157|    265|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    265|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    265|	return _ret; \
  |  |  163|    265|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  527|    265|}
card-tcos.c:tcos_select_file:
  336|  15.7k|{
  337|  15.7k|	sc_context_t *ctx;
  338|  15.7k|	sc_apdu_t apdu;
  339|  15.7k|	sc_file_t *file=NULL;
  340|  15.7k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE], pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  341|  15.7k|	int r;
  342|  15.7k|	size_t pathlen;
  343|       |
  344|  15.7k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (344:6): [True: 0, False: 15.7k]
  |  Branch (344:22): [True: 0, False: 15.7k]
  ------------------
  345|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  346|  15.7k|	ctx=card->ctx;
  347|  15.7k|	memcpy(path, in_path->value, in_path->len);
  348|  15.7k|	pathlen = in_path->len;
  349|       |
  350|  15.7k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0x04);
  ------------------
  |  |  294|  15.7k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  351|       |
  352|  15.7k|	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: 15.7k]
  ------------------
  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: 15.7k]
  ------------------
  357|      0|		apdu.p1 = 9;
  358|      0|		break;
  359|  2.34k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  2.34k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (359:2): [True: 2.34k, False: 13.3k]
  ------------------
  360|  2.34k|		apdu.p1 = 4;
  361|  2.34k|		break;
  362|  13.3k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  13.3k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (362:2): [True: 13.3k, False: 2.34k]
  ------------------
  363|  13.3k|		apdu.p1 = 8;
  364|  13.3k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) path += 2, pathlen -= 2;
  ------------------
  |  Branch (364:7): [True: 13.3k, False: 0]
  |  Branch (364:23): [True: 4.34k, False: 9.01k]
  ------------------
  365|  13.3k|		if (pathlen == 0) apdu.p1 = 0;
  ------------------
  |  Branch (365:7): [True: 0, False: 13.3k]
  ------------------
  366|  13.3k|		break;
  367|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (367:2): [True: 0, False: 15.7k]
  ------------------
  368|      0|		apdu.p1 = 3;
  369|      0|		pathlen = 0;
  370|      0|		break;
  371|      0|	default:
  ------------------
  |  Branch (371:2): [True: 0, False: 15.7k]
  ------------------
  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|  15.7k|	}
  374|  15.7k|	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: 15.7k]
  ------------------
  375|       |
  376|  15.7k|	apdu.lc = pathlen;
  377|  15.7k|	apdu.data = path;
  378|  15.7k|	apdu.datalen = pathlen;
  379|       |
  380|  15.7k|	if (file_out != NULL) {
  ------------------
  |  Branch (380:6): [True: 5.02k, False: 10.6k]
  ------------------
  381|  5.02k|		apdu.resp = buf;
  382|  5.02k|		apdu.resplen = sizeof(buf);
  383|  5.02k|		apdu.le = 256;
  384|  10.6k|	} else {
  385|  10.6k|		apdu.resplen = 0;
  386|  10.6k|		apdu.le = 0;
  387|  10.6k|		apdu.p2 = 0x0C;
  388|  10.6k|		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|  21.3k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (388:14): [True: 0, False: 10.6k]
  ------------------
  389|  10.6k|	}
  390|       |
  391|  15.7k|	r = sc_transmit_apdu(card, &apdu);
  392|  15.7k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  15.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  15.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  15.7k|	int _ret = (r); \
  |  |  |  |  168|  15.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 69, False: 15.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     69|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     69|		return _ret; \
  |  |  |  |  172|     69|	} \
  |  |  |  |  173|  15.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  393|  15.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  394|  15.6k|	if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  13.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  13.9k|	int _ret = r; \
  |  |  155|  13.9k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 13.9k, False: 0]
  |  |  ------------------
  |  |  156|  13.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|  12.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 12.5k, False: 1.43k]
  |  |  ------------------
  |  |  157|  13.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  13.9k|	} else { \
  |  |  159|      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.9k|	return _ret; \
  |  |  163|  13.9k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (394:6): [True: 12.5k, False: 3.13k]
  |  Branch (394:11): [True: 1.43k, False: 1.69k]
  ------------------
  395|       |
  396|  1.69k|	if (apdu.resplen < 1 || apdu.resp[0] != 0x62) {
  ------------------
  |  Branch (396:6): [True: 136, False: 1.56k]
  |  Branch (396:26): [True: 123, False: 1.43k]
  ------------------
  397|    259|		sc_log(ctx, "received invalid template %02X\n", apdu.resp[0]);
  ------------------
  |  |   71|    259|#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|    259|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  399|    259|	}
  400|       |
  401|  1.43k|	file = sc_file_new();
  402|  1.43k|	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: 1.43k]
  ------------------
  403|  1.43k|	*file_out = file;
  404|  1.43k|	file->path = *in_path;
  405|       |
  406|  1.43k|	iso_ops->process_fci(card, file, apdu.resp, apdu.resplen);
  407|       |
  408|  1.43k|	parse_sec_attr(card, file, file->sec_attr, file->sec_attr_len);
  409|       |
  410|  1.43k|	return 0;
  411|  1.43k|}
card-tcos.c:parse_sec_attr:
  271|  1.43k|{
  272|  1.43k|	unsigned int op;
  273|       |
  274|       |	/* list directory is not covered by ACLs - so always add an entry */
  275|  1.43k|	sc_file_add_acl_entry (file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|  1.43k|#define SC_AC_OP_LIST_FILES		6
  ------------------
  276|  1.43k|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|  1.43k|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|  1.43k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  277|       |	/* FIXME: check for what LOCK is used */
  278|  1.43k|	sc_file_add_acl_entry (file, SC_AC_OP_LOCK,
  ------------------
  |  |  167|  1.43k|#define SC_AC_OP_LOCK			1
  ------------------
  279|  1.43k|                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|  1.43k|#define SC_AC_NONE			0x00000000
  ------------------
                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|  1.43k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  280|  3.43k|	for (; len >= 6; len -= 6, buf += 6) {
  ------------------
  |  Branch (280:9): [True: 1.99k, False: 1.43k]
  ------------------
  281|       |		/* FIXME: temporary hacks */
  282|  1.99k|		if (!memcmp(buf, "\xa4\x00\x00\x00\xff\xff", 6)) {/* select */
  ------------------
  |  Branch (282:7): [True: 19, False: 1.97k]
  ------------------
  283|     19|			sc_file_add_acl_entry (file, SC_AC_OP_SELECT,
  ------------------
  |  |  166|     19|#define SC_AC_OP_SELECT			0
  ------------------
  284|     19|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     19|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     19|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  285|  1.97k|		} else if (!memcmp(buf, "\xb0\x00\x00\x00\xff\xff", 6)) {/*read*/
  ------------------
  |  Branch (285:14): [True: 34, False: 1.94k]
  ------------------
  286|     34|			sc_file_add_acl_entry (file, SC_AC_OP_READ,
  ------------------
  |  |  188|     34|#define SC_AC_OP_READ			22
  ------------------
  287|     34|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     34|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     34|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  288|  1.94k|		} else if (!memcmp(buf, "\xd6\x00\x00\x00\xff\xff", 6)) {/*upd*/
  ------------------
  |  Branch (288:14): [True: 34, False: 1.90k]
  ------------------
  289|     34|			sc_file_add_acl_entry (file, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|     34|#define SC_AC_OP_UPDATE			23
  ------------------
  290|     34|                                               SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     34|#define SC_AC_NONE			0x00000000
  ------------------
                                                             SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     34|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  291|  1.90k|		} else if (!memcmp(buf, "\x60\x00\x00\x00\xff\xff", 6)) {/*adm */
  ------------------
  |  Branch (291:14): [True: 18, False: 1.89k]
  ------------------
  292|     18|			sc_file_add_acl_entry (file, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     18|#define SC_AC_OP_WRITE			24
  ------------------
  293|     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
  ------------------
  294|     18|			sc_file_add_acl_entry (file, SC_AC_OP_CREATE,
  ------------------
  |  |  169|     18|#define SC_AC_OP_CREATE			3
  ------------------
  295|     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
  ------------------
  296|     18|			sc_file_add_acl_entry (file, SC_AC_OP_INVALIDATE,
  ------------------
  |  |  171|     18|#define SC_AC_OP_INVALIDATE		5
  ------------------
  297|     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
  ------------------
  298|     18|			sc_file_add_acl_entry (file, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     18|#define SC_AC_OP_REHABILITATE		4
  ------------------
  299|     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
  ------------------
  300|  1.89k|		} else {
  301|       |			/* the first byte tells use the command or the
  302|       |			   command group.  We have to mask bit 0
  303|       |			   because this one distinguish between AND/OR
  304|       |			   combination of PINs*/
  305|  1.89k|			op = map_operations (buf[0]);
  306|  1.89k|			if (op == (unsigned int)-1) {
  ------------------
  |  Branch (306:8): [True: 307, False: 1.58k]
  ------------------
  307|    307|				sc_log(card->ctx,
  ------------------
  |  |   71|    307|#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|    307|					"Unknown security command byte %02x\n",
  309|    307|					buf[0]);
  310|    307|				continue;
  311|    307|			}
  312|  1.58k|			if (!buf[1])
  ------------------
  |  Branch (312:8): [True: 140, False: 1.44k]
  ------------------
  313|    140|				sc_file_add_acl_entry (file, op,
  314|    140|                                                       SC_AC_NONE,
  ------------------
  |  |  150|    140|#define SC_AC_NONE			0x00000000
  ------------------
  315|    140|                                                       SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    140|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  316|  1.44k|			else
  317|  1.44k|				sc_file_add_acl_entry (file, op,
  318|  1.44k|                                                       SC_AC_CHV, buf[1]);
  ------------------
  |  |  151|  1.44k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  319|       |
  320|  1.58k|			if (!buf[2] && !buf[3])
  ------------------
  |  Branch (320:8): [True: 175, False: 1.40k]
  |  Branch (320:19): [True: 68, False: 107]
  ------------------
  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|  1.51k|			else
  325|  1.51k|				sc_file_add_acl_entry (file, op,
  326|  1.51k|                                                       SC_AC_TERM,
  ------------------
  |  |  152|  1.51k|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  327|  1.51k|                                                       (buf[2]<<8)|buf[3]);
  328|  1.58k|		}
  329|  1.99k|	}
  330|  1.43k|}
card-tcos.c:map_operations:
  236|  1.89k|{
  237|  1.89k|	unsigned int op = (unsigned int)-1;
  238|       |
  239|  1.89k|	switch ( (commandbyte & 0xfe) ) {
  ------------------
  |  Branch (239:11): [True: 1.58k, False: 307]
  ------------------
  240|     67|		case 0xe2: /* append record */   op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|     67|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (240:3): [True: 67, False: 1.82k]
  ------------------
  241|     82|		case 0x24: /* change password */ op = SC_AC_OP_UPDATE; break;
  ------------------
  |  |  189|     82|#define SC_AC_OP_UPDATE			23
  ------------------
  |  Branch (241:3): [True: 82, False: 1.80k]
  ------------------
  242|     73|		case 0xe0: /* create */          op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     73|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (242:3): [True: 73, False: 1.81k]
  ------------------
  243|     67|		case 0xe4: /* delete */          op = SC_AC_OP_DELETE; break;
  ------------------
  |  |  168|     67|#define SC_AC_OP_DELETE			2
  ------------------
  |  Branch (243:3): [True: 67, False: 1.82k]
  ------------------
  244|     73|		case 0xe8: /* exclude sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     73|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (244:3): [True: 73, False: 1.81k]
  ------------------
  245|    116|		case 0x82: /* external auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|    116|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (245:3): [True: 116, False: 1.77k]
  ------------------
  246|     69|		case 0xe6: /* include sfi */     op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     69|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (246:3): [True: 69, False: 1.82k]
  ------------------
  247|     70|		case 0x88: /* internal auth */   op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     70|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (247:3): [True: 70, False: 1.82k]
  ------------------
  248|    131|		case 0x04: /* invalidate */      op = SC_AC_OP_INVALIDATE; break;
  ------------------
  |  |  171|    131|#define SC_AC_OP_INVALIDATE		5
  ------------------
  |  Branch (248:3): [True: 131, False: 1.75k]
  ------------------
  249|     81|		case 0x2a: /* perform sec. op */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     81|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (249:3): [True: 81, False: 1.80k]
  ------------------
  250|     72|		case 0xb0: /* read binary */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     72|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (250:3): [True: 72, False: 1.81k]
  ------------------
  251|     68|		case 0xb2: /* read record */     op = SC_AC_OP_READ; break;
  ------------------
  |  |  188|     68|#define SC_AC_OP_READ			22
  ------------------
  |  Branch (251:3): [True: 68, False: 1.82k]
  ------------------
  252|     71|		case 0x44: /* rehabilitate */    op = SC_AC_OP_REHABILITATE; break;
  ------------------
  |  |  170|     71|#define SC_AC_OP_REHABILITATE		4
  ------------------
  |  Branch (252:3): [True: 71, False: 1.81k]
  ------------------
  253|     75|		case 0xa4: /* select */          op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     75|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (253:3): [True: 75, False: 1.81k]
  ------------------
  254|     70|		case 0xee: /* set permanent */   op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|     70|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (254:3): [True: 70, False: 1.82k]
  ------------------
  255|     70|		case 0x2c: /* unblock password */op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     70|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (255:3): [True: 70, False: 1.82k]
  ------------------
  256|     84|		case 0xd6: /* update binary */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     84|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (256:3): [True: 84, False: 1.80k]
  ------------------
  257|     67|		case 0xdc: /* update record */   op = SC_AC_OP_WRITE; break;
  ------------------
  |  |  190|     67|#define SC_AC_OP_WRITE			24
  ------------------
  |  Branch (257:3): [True: 67, False: 1.82k]
  ------------------
  258|     68|		case 0x20: /* verify password */ op = SC_AC_OP_SELECT; break;
  ------------------
  |  |  166|     68|#define SC_AC_OP_SELECT			0
  ------------------
  |  Branch (258:3): [True: 68, False: 1.82k]
  ------------------
  259|    109|		case 0x60: /* admin group */     op = SC_AC_OP_CREATE; break;
  ------------------
  |  |  169|    109|#define SC_AC_OP_CREATE			3
  ------------------
  |  Branch (259:3): [True: 109, False: 1.78k]
  ------------------
  260|  1.89k|	}
  261|  1.89k|	return op;
  262|  1.89k|}
card-tcos.c:tcos_compute_signature:
  537|    140|{
  538|    140|	size_t dlen = datalen;
  539|    140|	sc_apdu_t apdu;
  540|    140|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  541|    140|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  542|    140|	int tcos3, r;
  543|       |
  544|    140|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (544:6): [True: 0, False: 140]
  |  Branch (544:22): [True: 0, False: 140]
  |  Branch (544:38): [True: 0, False: 140]
  ------------------
  545|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  546|      0|	}
  547|       |
  548|    140|	tcos3 = (card->type == SC_CARD_TYPE_TCOS_V3);
  549|       |
  550|       |	// We can sign (key length / 8) bytes
  551|    140|	if (datalen > 256) {
  ------------------
  |  Branch (551:6): [True: 17, False: 123]
  ------------------
  552|     17|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  553|     17|	}
  554|       |
  555|    123|	if (((tcos_data *)card->drv_data)->next_sign) {
  ------------------
  |  Branch (555:6): [True: 20, False: 103]
  ------------------
  556|     20|		if (datalen > 48) {
  ------------------
  |  Branch (556:7): [True: 18, False: 2]
  ------------------
  557|     18|			sc_log(card->ctx, "Data to be signed is too long (TCOS supports max. 48 bytes)\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  558|     18|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     18|	int _ret = r; \
  |  |  155|     18|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  ------------------
  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  ------------------
  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     18|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     18|	return _ret; \
  |  |  163|     18|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  559|     18|		}
  560|      2|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|      2|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  561|      2|		memcpy(sbuf, data, datalen);
  562|      2|		dlen = datalen;
  563|    103|	} else {
  564|    103|		size_t keylen = tcos3 ? 256 : 128;
  ------------------
  |  Branch (564:19): [True: 78, False: 25]
  ------------------
  565|       |
  566|    103|		if (datalen > keylen) {
  ------------------
  |  Branch (566:7): [True: 3, False: 100]
  ------------------
  567|      3|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      3|	int _ret = r; \
  |  |  155|      3|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  ------------------
  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  ------------------
  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      3|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      3|	return _ret; \
  |  |  163|      3|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  568|      3|		}
  569|       |
  570|    100|		sc_format_apdu(card, &apdu, keylen > 255 ? SC_APDU_CASE_4_EXT : SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  299|     78|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|     78|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     78|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
              		sc_format_apdu(card, &apdu, keylen > 255 ? SC_APDU_CASE_4_EXT : SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     22|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (570:31): [True: 78, False: 22]
  ------------------
  571|    100|		memset(sbuf, 0xff, sizeof(sbuf));
  572|    100|		sbuf[0] = 0x02;
  573|    100|		sbuf[1] = 0x00;
  574|    100|		sbuf[2] = 0x01;
  575|    100|		sbuf[keylen - datalen] = 0x00;
  576|    100|		memcpy(sbuf + keylen - datalen + 1, data, datalen);
  577|    100|		dlen = keylen + 1;
  578|    100|	}
  579|    102|	apdu.resp = rbuf;
  580|    102|	apdu.resplen = sizeof(rbuf);
  581|    102|	apdu.le = tcos3 ? 256 : 128;
  ------------------
  |  Branch (581:12): [True: 78, False: 24]
  ------------------
  582|    102|	apdu.data = sbuf;
  583|    102|	apdu.lc = apdu.datalen = dlen;
  584|       |
  585|    102|	r = sc_transmit_apdu(card, &apdu);
  586|    102|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    102|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    102|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    102|	int _ret = (r); \
  |  |  |  |  168|    102|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 89]
  |  |  |  |  ------------------
  |  |  |  |  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|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 89]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  587|     89|	if (tcos3 && apdu.p1 == 0x80 && apdu.sw1 == 0x6A && apdu.sw2 == 0x87) {
  ------------------
  |  Branch (587:6): [True: 65, False: 24]
  |  Branch (587:15): [True: 65, False: 0]
  |  Branch (587:34): [True: 9, False: 56]
  |  Branch (587:54): [True: 2, False: 7]
  ------------------
  588|      2|		size_t keylen = 128;
  589|       |
  590|      2|		if (datalen > keylen) {
  ------------------
  |  Branch (590:7): [True: 1, False: 1]
  ------------------
  591|      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]
  |  |  ------------------
  ------------------
  592|      1|		}
  593|       |
  594|      1|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|      1|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  595|      1|		memset(sbuf, 0xff, sizeof(sbuf));
  596|      1|		sbuf[0] = 0x02;
  597|      1|		sbuf[1] = 0x00;
  598|      1|		sbuf[2] = 0x01;
  599|      1|		sbuf[keylen - datalen] = 0x00;
  600|      1|		memcpy(sbuf + keylen - datalen + 1, data, datalen);
  601|      1|		dlen = keylen + 1;
  602|       |
  603|      1|		apdu.resp = rbuf;
  604|      1|		apdu.resplen = sizeof(rbuf);
  605|      1|		apdu.le = 128;
  606|      1|		apdu.data = sbuf;
  607|      1|		apdu.lc = apdu.datalen = dlen;
  608|      1|		r = sc_transmit_apdu(card, &apdu);
  609|      1|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  610|      1|	}
  611|     88|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (611:6): [True: 55, False: 33]
  |  Branch (611:26): [True: 42, False: 13]
  ------------------
  612|     42|		size_t len = apdu.resplen>outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (612:16): [True: 0, False: 42]
  ------------------
  613|     42|		memcpy(out, apdu.resp, len);
  614|     42|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|     42|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     42|	int _ret = r; \
  |  |  155|     42|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 15, False: 27]
  |  |  ------------------
  |  |  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|     27|	} else { \
  |  |  159|     27|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     27|			"returning with: %d\n", _ret); \
  |  |  161|     27|	} \
  |  |  162|     42|	return _ret; \
  |  |  163|     42|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  615|     42|	}
  616|     46|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     46|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     46|	int _ret = r; \
  |  |  155|     46|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 46, False: 0]
  |  |  ------------------
  |  |  156|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 46, False: 0]
  |  |  ------------------
  |  |  157|     46|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     46|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     46|	return _ret; \
  |  |  163|     46|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  617|     46|}
card-tcos.c:tcos_decipher:
  621|     81|{
  622|     81|	sc_context_t *ctx;
  623|     81|	sc_apdu_t apdu;
  624|     81|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  625|     81|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|     81|	tcos_data *data;
  627|     81|	int tcos3, r;
  628|       |
  629|     81|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (629:6): [True: 0, False: 81]
  |  Branch (629:22): [True: 0, False: 81]
  |  Branch (629:40): [True: 0, False: 81]
  ------------------
  630|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  631|      0|	}
  632|     81|	ctx = card->ctx;
  633|     81|	tcos3 = (card->type == SC_CARD_TYPE_TCOS_V3);
  634|     81|	data = (tcos_data *)card->drv_data;
  635|       |
  636|     81|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     81|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     81|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     81|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     81|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  637|     81|	sc_log(ctx, "TCOS3:%d PKCS1 type 02:%d\n", tcos3,
  ------------------
  |  |   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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  637|     81|	sc_log(ctx, "TCOS3:%d PKCS1 type 02:%d\n", tcos3,
  |  |  |  |  638|     81|			!!(data->pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02));
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|     81|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|     81|			!!(data->pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02));
  639|       |
  640|     81|	sc_format_apdu(card, &apdu, crgram_len > 255 ? SC_APDU_CASE_4_EXT : SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  299|     40|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|     40|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     40|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
              	sc_format_apdu(card, &apdu, crgram_len > 255 ? SC_APDU_CASE_4_EXT : SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     41|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (640:30): [True: 40, False: 41]
  ------------------
  641|     81|	apdu.resp = rbuf;
  642|     81|	apdu.resplen = sizeof(rbuf);
  643|     81|	apdu.le = crgram_len;
  644|       |
  645|     81|	apdu.data = sbuf;
  646|     81|	apdu.lc = apdu.datalen = crgram_len + 1;
  647|     81|	sbuf[0] = tcos3 ? 0x00 : ((data->pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) ? 0x81 : 0x02);
  ------------------
  |  |  110|     44|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (647:12): [True: 37, False: 44]
  |  Branch (647:28): [True: 0, False: 44]
  ------------------
  648|     81|	if (sizeof sbuf - 1 < crgram_len)
  ------------------
  |  Branch (648:6): [True: 29, False: 52]
  ------------------
  649|     29|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     29|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  650|     52|	memcpy(sbuf + 1, crgram, crgram_len);
  651|       |
  652|     52|	r = sc_transmit_apdu(card, &apdu);
  653|     52|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     52|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     52|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     52|	int _ret = (r); \
  |  |  |  |  168|     52|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  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|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  654|       |
  655|     37|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     37|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     37|	int _ret = r; \
  |  |  155|     37|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 37, False: 0]
  |  |  ------------------
  |  |  156|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 14, False: 23]
  |  |  ------------------
  |  |  157|     37|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     37|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     37|	return _ret; \
  |  |  163|     37|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  656|     37|}
card-tcos.c:tcos_card_ctl:
  708|  1.08k|{
  709|  1.08k|	switch (cmd) {
  ------------------
  |  Branch (709:10): [True: 1.08k, False: 0]
  ------------------
  710|      0|	case SC_CARDCTL_TCOS_SETPERM:
  ------------------
  |  Branch (710:2): [True: 0, False: 1.08k]
  ------------------
  711|      0|		return tcos_setperm(card, !!ptr);
  712|  1.08k|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (712:2): [True: 1.08k, False: 0]
  ------------------
  713|  1.08k|		return tcos_get_serialnr(card, (sc_serial_number_t *)ptr);
  714|  1.08k|	}
  715|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  716|  1.08k|}
card-tcos.c:tcos_get_serialnr:
  681|  1.08k|{
  682|  1.08k|	int r;
  683|       |
  684|  1.08k|	if (!serial)
  ------------------
  |  Branch (684:6): [True: 0, False: 1.08k]
  ------------------
  685|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  686|       |
  687|       |	/* see if we have cached serial number */
  688|  1.08k|	if (card->serialnr.len) {
  ------------------
  |  Branch (688:6): [True: 1, False: 1.08k]
  ------------------
  689|      1|		memcpy(serial, &card->serialnr, sizeof(*serial));
  690|      1|		return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  691|      1|	}
  692|       |
  693|  1.08k|	card->serialnr.len = sizeof card->serialnr.value;
  694|  1.08k|	r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
  695|  1.08k|	if (r < 0) {
  ------------------
  |  Branch (695:6): [True: 512, False: 572]
  ------------------
  696|    512|		card->serialnr.len = 0;
  697|    512|		return r;
  698|    512|	}
  699|       |
  700|       |	/* copy and return serial number */
  701|    572|	memcpy(serial, &card->serialnr, sizeof(*serial));
  702|       |
  703|    572|	return SC_SUCCESS;
  ------------------
  |  |   28|    572|#define SC_SUCCESS				0
  ------------------
  704|  1.08k|}

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

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

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

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

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

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

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

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

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

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

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

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

iso7816_fixup_transceive_length:
   35|  59.1k|{
   36|  59.1k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (36:6): [True: 0, False: 59.1k]
  |  Branch (36:22): [True: 0, False: 59.1k]
  ------------------
   37|      0|		return;
   38|      0|	}
   39|       |
   40|  59.1k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (40:6): [True: 421, False: 58.7k]
  ------------------
   41|       |		/* The lower layers will automatically do chaining */
   42|    421|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    421|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   43|    421|	}
   44|       |
   45|  59.1k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (45:6): [True: 2.22k, False: 56.9k]
  ------------------
   46|       |		/* The lower layers will automatically do a GET RESPONSE, if possible.
   47|       |		 * All other workarounds must be carried out by the upper layers. */
   48|  2.22k|		apdu->le = sc_get_max_recv_size(card);
   49|  2.22k|	}
   50|  59.1k|}
encode_do_data:
  176|  15.8k|{
  177|  15.8k|	unsigned char offset_buffer[2];
  178|  15.8k|	size_t offset_buffer_len = sizeof offset_buffer;
  179|  15.8k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  180|  15.8k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  181|       |
  182|  15.8k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (182:6): [True: 0, False: 15.8k]
  ------------------
  183|  15.8k|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "Offset beyond 0xFFFF not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|  15.8k|	offset_buffer[0] = (u8) (idx >> 8);
  185|  15.8k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  186|  15.8k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  187|       |
  188|  15.8k|	if (data && data_len) {
  ------------------
  |  Branch (188:6): [True: 0, False: 15.8k]
  |  Branch (188:14): [True: 0, False: 0]
  ------------------
  189|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  190|  15.8k|	} else {
  191|  15.8k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  192|  15.8k|	}
  193|       |
  194|  15.8k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  15.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  15.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  15.8k|	int _ret = (r); \
  |  |  |  |  168|  15.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  15.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|  15.8k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  196|  15.8k|			"sc_asn1_encode() failed");
  197|       |
  198|  15.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.8k|#define SC_SUCCESS				0
  ------------------
  199|  15.8k|}
decode_do_data:
  204|  13.2k|{
  205|  13.2k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  206|  13.2k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  207|       |
  208|  13.2k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  209|  13.2k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  210|       |
  211|  13.2k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  13.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.2k|	int _ret = (r); \
  |  |  |  |  168|  13.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.47k, False: 11.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.47k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.47k|		return _ret; \
  |  |  |  |  172|  1.47k|	} \
  |  |  |  |  173|  13.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  212|  11.8k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  213|  11.8k|			"sc_asn1_decode() failed");
  214|       |
  215|  11.8k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  11.8k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (215:6): [True: 10.4k, False: 1.36k]
  ------------------
  216|  10.4k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  10.4k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  217|       |
  218|  1.36k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.36k|#define SC_SUCCESS				0
  ------------------
  219|  11.8k|}
iso7816_build_pin_apdu:
 1182|  8.90k|{
 1183|  8.90k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1184|  8.90k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  8.90k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1185|       |
 1186|  8.90k|	switch (data->pin_type) {
 1187|  8.90k|	case SC_AC_CHV:
  ------------------
  |  |  151|  8.90k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1187:2): [True: 8.90k, False: 0]
  ------------------
 1188|       |		/* fall through */
 1189|  8.90k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  8.90k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1189:2): [True: 0, False: 8.90k]
  ------------------
 1190|  8.90k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  8.90k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1190:2): [True: 0, False: 8.90k]
  ------------------
 1191|  8.90k|		break;
 1192|      0|	default:
  ------------------
  |  Branch (1192:2): [True: 0, False: 8.90k]
  ------------------
 1193|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1194|  8.90k|	}
 1195|       |
 1196|  8.90k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|  8.90k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1196:6): [True: 1.40k, False: 7.50k]
  ------------------
 1197|  1.40k|		pad = 1;
 1198|  8.90k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|  8.90k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1198:6): [True: 0, False: 8.90k]
  ------------------
 1199|      0|		use_pin_pad = 1;
 1200|       |
 1201|  8.90k|	data->pin1.offset = 5;
 1202|       |
 1203|  8.90k|	switch (data->cmd) {
 1204|  1.09k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|  1.09k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1204:2): [True: 1.09k, False: 7.81k]
  ------------------
 1205|  1.09k|		ins = 0x20;
 1206|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1207|  1.09k|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1207:7): [True: 0, False: 1.09k]
  |  Branch (1207:30): [True: 0, False: 0]
  ------------------
 1208|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1209|  1.09k|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1209:7): [True: 21, False: 1.07k]
  ------------------
 1210|     21|			return r;
 1211|  1.07k|		len = r;
 1212|  1.07k|		break;
 1213|    274|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|    274|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1213:2): [True: 274, False: 8.62k]
  ------------------
 1214|    274|		ins = 0x24;
 1215|    274|		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 (1215:7): [True: 268, False: 6]
  |  Branch (1215:31): [True: 0, False: 6]
  |  Branch (1215:46): [True: 0, False: 0]
  ------------------
 1216|    268|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1216:8): [True: 12, False: 256]
  ------------------
 1217|     12|				return r;
 1218|    256|			len += r;
 1219|    256|		}
 1220|      6|		else {
 1221|       |			/* implicit test */
 1222|      6|			p1 = 1;
 1223|      6|		}
 1224|       |
 1225|    262|		data->pin2.offset = data->pin1.offset + len;
 1226|    262|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1226:7): [True: 13, False: 249]
  ------------------
 1227|     13|			return r;
 1228|       |		/* Special case - where provided the old PIN on the command line
 1229|       |		 * but expect the new one to be entered on the keypad.
 1230|       |		 */
 1231|    249|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1231:7): [True: 243, False: 6]
  |  Branch (1231:25): [True: 0, False: 243]
  ------------------
 1232|      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__
  |  |  ------------------
  ------------------
 1233|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1234|      0|		};
 1235|    249|		len += r;
 1236|    249|		break;
 1237|    341|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|    341|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1237:2): [True: 341, False: 8.56k]
  ------------------
 1238|    341|		ins = 0x2C;
 1239|    341|		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 (1239:7): [True: 335, False: 6]
  |  Branch (1239:31): [True: 0, False: 6]
  |  Branch (1239:46): [True: 0, False: 0]
  ------------------
 1240|    335|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1240:8): [True: 7, False: 328]
  ------------------
 1241|      7|				return r;
 1242|    328|			len += r;
 1243|    328|		} else {
 1244|      6|			p1 |= 0x02;
 1245|      6|		}
 1246|       |
 1247|    334|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1247:7): [True: 334, False: 0]
  |  Branch (1247:30): [True: 0, False: 0]
  ------------------
 1248|    334|			data->pin2.offset = data->pin1.offset + len;
 1249|    334|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1249:8): [True: 12, False: 322]
  ------------------
 1250|     12|				return r;
 1251|    322|			len += r;
 1252|    322|		} else {
 1253|      0|			p1 |= 0x01;
 1254|      0|		}
 1255|    322|		if (p1 == 0x03) {
  ------------------
  |  Branch (1255:7): [True: 0, False: 322]
  ------------------
 1256|       |			/* No data to send or to receive */
 1257|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1258|      0|		}
 1259|    322|		break;
 1260|  7.19k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|  7.19k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1260:2): [True: 7.19k, False: 1.70k]
  ------------------
 1261|  7.19k|		ins = 0x20;
 1262|       |		/* No data to send or to receive */
 1263|  7.19k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  7.19k|#define SC_APDU_CASE_1			0x01
  ------------------
 1264|  7.19k|		break;
 1265|      0|	default:
  ------------------
  |  Branch (1265:2): [True: 0, False: 8.90k]
  ------------------
 1266|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1267|  8.90k|	}
 1268|       |
 1269|  8.83k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1270|  8.83k|	apdu->lc = len;
 1271|  8.83k|	apdu->datalen = len;
 1272|  8.83k|	apdu->data = buf;
 1273|  8.83k|	apdu->resplen = 0;
 1274|       |
 1275|  8.83k|	return 0;
 1276|  8.90k|}
iso7816_select_aid:
 1394|  23.7k|{
 1395|  23.7k|	struct sc_context *ctx = card->ctx;
 1396|  23.7k|	struct sc_apdu apdu;
 1397|  23.7k|	int rv;
 1398|       |
 1399|  23.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  23.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  23.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  23.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 23.7k]
  |  |  ------------------
  ------------------
 1400|       |
 1401|  23.7k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  8.53k|#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|  15.2k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1401:30): [True: 8.53k, False: 15.2k]
  |  Branch (1401:102): [True: 8.53k, False: 15.2k]
  ------------------
 1402|  23.7k|	apdu.lc = reqlen;
 1403|  23.7k|	apdu.data = req;
 1404|  23.7k|	apdu.datalen = reqlen;
 1405|  23.7k|	apdu.resp = resp;
 1406|  23.7k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1406:17): [True: 8.53k, False: 15.2k]
  ------------------
 1407|  23.7k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1407:12): [True: 8.53k, False: 15.2k]
  ------------------
 1408|       |
 1409|  23.7k|	rv = sc_transmit_apdu(card, &apdu);
 1410|  23.7k|	if (resplen)
  ------------------
  |  Branch (1410:6): [True: 15.2k, False: 8.53k]
  ------------------
 1411|  15.2k|		*resplen = apdu.resplen;
 1412|  23.7k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  23.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  23.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  23.7k|	int _ret = (r); \
  |  |  |  |  168|  23.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 225, False: 23.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    225|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    225|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    225|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    225|		return _ret; \
  |  |  |  |  172|    225|	} \
  |  |  |  |  173|  23.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1413|       |
 1414|  23.5k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1415|  23.5k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  23.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  23.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  23.5k|	int _ret = r; \
  |  |  |  |  155|  23.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  23.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|  17.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.4k, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  |  157|  23.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  23.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|  23.5k|	return _ret; \
  |  |  |  |  163|  23.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|  23.5k|}
sc_get_iso7816_driver:
 1484|   648k|{
 1485|   648k|	return &iso_driver;
 1486|   648k|}
iso7816.c:no_match:
 1430|  7.91k|{
 1431|  7.91k|	return 0;
 1432|  7.91k|}
iso7816.c:iso7816_read_record:
  224|  33.3k|{
  225|  33.3k|	struct sc_apdu apdu;
  226|  33.3k|	int r;
  227|       |	/* XXX maybe use some bigger buffer */
  228|  33.3k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  229|  33.3k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  230|  33.3k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  231|       |
  232|  33.3k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (232:6): [True: 28, False: 33.3k]
  ------------------
  233|  33.3k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|       |
  235|  33.3k|	if (idx == 0) {
  ------------------
  |  Branch (235:6): [True: 17.5k, False: 15.8k]
  ------------------
  236|  17.5k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  17.5k|#define SC_APDU_CASE_2			0x22
  ------------------
  237|  17.5k|		apdu.le = count;
  238|  17.5k|		apdu.resplen = count;
  239|  17.5k|		apdu.resp = buf;
  240|  17.5k|	} else {
  241|  15.8k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  242|  15.8k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  15.8k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  15.8k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  15.8k|	int _ret = (r); \
  |  |  |  |  178|  15.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 15.8k]
  |  |  |  |  ------------------
  |  |  |  |  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|  15.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 15.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|       |
  244|  15.8k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  15.8k|#define SC_APDU_CASE_4			0x24
  ------------------
  245|  15.8k|		apdu.lc = encoded_data_len;
  246|  15.8k|		apdu.datalen = encoded_data_len;
  247|  15.8k|		apdu.data = encoded_data;
  248|  15.8k|		apdu.le = sizeof resp;
  249|  15.8k|		apdu.resplen = sizeof resp;
  250|  15.8k|		apdu.resp = resp;
  251|  15.8k|	}
  252|  33.3k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  33.3k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  253|  33.3k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  33.3k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (253:6): [True: 33.3k, False: 0]
  ------------------
  254|  33.3k|		apdu.p2 |= 0x04;
  255|       |
  256|  33.3k|	iso7816_fixup_transceive_length(card, &apdu);
  257|  33.3k|	r = sc_transmit_apdu(card, &apdu);
  258|  33.3k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  33.3k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  33.3k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  33.3k|	int _ret = (r); \
  |  |  |  |  178|  33.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.13k, False: 32.2k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.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|  1.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.13k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.13k|		goto err; \
  |  |  |  |  182|  1.13k|	} \
  |  |  |  |  183|  33.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 32.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|  32.2k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  260|  32.2k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  32.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  32.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  32.2k|	int _ret = (r); \
  |  |  |  |  178|  32.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.89k, False: 29.3k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.89k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.89k|		goto err; \
  |  |  |  |  182|  2.89k|	} \
  |  |  |  |  183|  32.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 29.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  261|       |
  262|  29.3k|	if (idx == 0) {
  ------------------
  |  Branch (262:6): [True: 16.0k, False: 13.2k]
  ------------------
  263|  16.0k|		r = (int)apdu.resplen;
  264|  16.0k|	} else {
  265|  13.2k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  266|  13.2k|				&decoded_data, &decoded_data_len);
  267|  13.2k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  13.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.2k|	int _ret = (r); \
  |  |  |  |  178|  13.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11.9k, False: 1.36k]
  |  |  |  |  ------------------
  |  |  |  |  179|  11.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  11.9k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  11.9k|		goto err; \
  |  |  |  |  182|  11.9k|	} \
  |  |  |  |  183|  13.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.36k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|  1.36k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (268:7): [True: 1.15k, False: 215]
  ------------------
  269|  1.15k|			count = decoded_data_len;
  270|  1.15k|		}
  271|  1.36k|		memcpy(buf, decoded_data, count);
  272|  1.36k|		r = (int)count;
  273|  1.36k|	}
  274|       |
  275|  33.3k|err:
  276|  33.3k|	free(encoded_data);
  277|  33.3k|	free(decoded_data);
  278|  33.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  33.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  33.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  33.3k|	int _ret = r; \
  |  |  |  |  155|  33.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.2k, False: 16.0k]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.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|  15.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.9k, False: 1.33k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.2k|	} else { \
  |  |  |  |  159|  16.0k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.0k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.0k|	} \
  |  |  |  |  162|  33.3k|	return _ret; \
  |  |  |  |  163|  33.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|  33.3k|}
iso7816.c:iso7816_select_file:
  628|  52.5k|{
  629|  52.5k|	struct sc_context *ctx;
  630|  52.5k|	struct sc_apdu apdu;
  631|  52.5k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  632|  52.5k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  633|  52.5k|	int r, pathtype;
  634|  52.5k|	size_t pathlen;
  635|  52.5k|	int select_mf = 0;
  636|  52.5k|	struct sc_file *file = NULL;
  637|  52.5k|	const u8 *buffer;
  638|  52.5k|	size_t buffer_len;
  639|  52.5k|	unsigned int cla, tag;
  640|       |
  641|  52.5k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (641:6): [True: 0, False: 52.5k]
  |  Branch (641:22): [True: 0, False: 52.5k]
  ------------------
  642|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  643|      0|	}
  644|  52.5k|	ctx = card->ctx;
  645|  52.5k|	memcpy(path, in_path->value, in_path->len);
  646|  52.5k|	pathlen = in_path->len;
  647|  52.5k|	pathtype = in_path->type;
  648|       |
  649|  52.5k|	if (in_path->aid.len) {
  ------------------
  |  Branch (649:6): [True: 1.82k, False: 50.6k]
  ------------------
  650|  1.82k|		if (!pathlen) {
  ------------------
  |  Branch (650:7): [True: 1.38k, False: 443]
  ------------------
  651|  1.38k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  652|  1.38k|			pathlen = in_path->aid.len;
  653|  1.38k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.38k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  654|  1.38k|		} else {
  655|       |			/* First, select the application */
  656|    443|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    443|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  657|    443|			apdu.data = in_path->aid.value;
  658|    443|			apdu.datalen = in_path->aid.len;
  659|    443|			apdu.lc = in_path->aid.len;
  660|       |
  661|    443|			r = sc_transmit_apdu(card, &apdu);
  662|    443|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    443|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    443|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    443|	int _ret = (r); \
  |  |  |  |  168|    443|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 440]
  |  |  |  |  ------------------
  |  |  |  |  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|    443|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 440]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  663|    440|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  664|    440|			if (r)
  ------------------
  |  Branch (664:8): [True: 338, False: 102]
  ------------------
  665|    440|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    338|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    338|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    338|	int _ret = r; \
  |  |  |  |  155|    338|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 338, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    338|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    338|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 338, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    338|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    338|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    338|	return _ret; \
  |  |  |  |  163|    338|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|       |
  667|    102|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    204|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (667:8): [True: 102, False: 0]
  ------------------
  668|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (668:9): [True: 0, False: 0]
  ------------------
  669|    102|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    102|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  670|    102|		}
  671|  1.82k|	}
  672|       |
  673|  52.1k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  52.1k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  674|       |
  675|  52.1k|	switch (pathtype) {
  676|  10.9k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  10.9k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (676:2): [True: 10.9k, False: 41.1k]
  ------------------
  677|  10.9k|		apdu.p1 = 0;
  678|  10.9k|		if (pathlen != 2)
  ------------------
  |  Branch (678:7): [True: 0, False: 10.9k]
  ------------------
  679|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  680|  10.9k|		break;
  681|  23.0k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  23.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (681:2): [True: 23.0k, False: 29.1k]
  ------------------
  682|  23.0k|		apdu.p1 = 4;
  683|  23.0k|		break;
  684|  17.8k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  17.8k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (684:2): [True: 17.8k, False: 34.3k]
  ------------------
  685|  17.8k|		apdu.p1 = 8;
  686|  17.8k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (686:7): [True: 17.7k, False: 64]
  |  Branch (686:23): [True: 12.3k, False: 5.44k]
  ------------------
  687|  12.3k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (687:8): [True: 3.71k, False: 8.63k]
  ------------------
  688|  3.71k|				select_mf = 1;
  689|  3.71k|				apdu.p1 = 0;
  690|  3.71k|				break;
  691|  3.71k|			}
  692|  8.63k|			path += 2;
  693|  8.63k|			pathlen -= 2;
  694|  8.63k|		}
  695|  14.1k|		break;
  696|  14.1k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    102|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (696:2): [True: 102, False: 52.0k]
  ------------------
  697|    102|		apdu.p1 = 9;
  698|    102|		break;
  699|    170|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    170|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (699:2): [True: 170, False: 52.0k]
  ------------------
  700|    170|		apdu.p1 = 3;
  701|    170|		pathlen = 0;
  702|    170|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    170|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  703|    170|		break;
  704|      0|	default:
  ------------------
  |  Branch (704:2): [True: 0, False: 52.1k]
  ------------------
  705|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  706|  52.1k|	}
  707|  52.1k|	apdu.lc = pathlen;
  708|  52.1k|	apdu.data = path;
  709|  52.1k|	apdu.datalen = pathlen;
  710|       |
  711|  52.1k|	if (file_out != NULL) {
  ------------------
  |  Branch (711:6): [True: 33.9k, False: 18.2k]
  ------------------
  712|  33.9k|		apdu.p2 = 0;		/* first record, return FCI */
  713|  33.9k|		apdu.resp = buf;
  714|  33.9k|		apdu.resplen = sizeof(buf);
  715|  33.9k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (715:13): [True: 1.07k, False: 32.8k]
  ------------------
  716|  33.9k|	}
  717|  18.2k|	else {
  718|  18.2k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  719|  18.2k|		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|  36.5k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (719:14): [True: 0, False: 18.2k]
  ------------------
  720|  18.2k|	}
  721|       |
  722|  52.1k|	r = sc_transmit_apdu(card, &apdu);
  723|  52.1k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  52.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  52.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  52.1k|	int _ret = (r); \
  |  |  |  |  168|  52.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 412, False: 51.7k]
  |  |  |  |  ------------------
  |  |  |  |  169|    412|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    412|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    412|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    412|		return _ret; \
  |  |  |  |  172|    412|	} \
  |  |  |  |  173|  52.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 51.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|  51.7k|	if (file_out == NULL) {
  ------------------
  |  Branch (724:6): [True: 18.2k, False: 33.5k]
  ------------------
  725|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  726|  18.2k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  727|  18.2k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (727:7): [True: 123, False: 18.1k]
  |  Branch (727:27): [True: 22, False: 101]
  ------------------
  728|     22|			apdu.p2 = 0x00;
  729|     22|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  |  Branch (729:8): [True: 12, False: 10]
  ------------------
  730|     12|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  731|     22|		}
  732|  18.2k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (732:7): [True: 0, False: 18.2k]
  ------------------
  733|  18.2k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  734|  18.2k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  18.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.2k|	int _ret = r; \
  |  |  |  |  155|  18.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.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|  13.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.1k, False: 5.12k]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.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|  18.2k|	return _ret; \
  |  |  |  |  163|  18.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  735|  18.2k|	}
  736|       |
  737|  33.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  738|  33.5k|	if (r)
  ------------------
  |  Branch (738:6): [True: 18.0k, False: 15.4k]
  ------------------
  739|  33.5k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  18.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.0k|	int _ret = r; \
  |  |  |  |  155|  18.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  18.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  18.0k|	return _ret; \
  |  |  |  |  163|  18.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  740|       |
  741|  15.4k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (741:6): [True: 15.4k, False: 0]
  |  Branch (741:18): [True: 2.86k, False: 12.5k]
  ------------------
  742|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  743|  2.86k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.33k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (743:7): [True: 525, False: 2.33k]
  |  Branch (743:20): [True: 1.33k, False: 1.00k]
  ------------------
  744|  1.86k|			file = sc_file_new();
  745|  1.86k|			if (file == NULL)
  ------------------
  |  Branch (745:8): [True: 0, False: 1.86k]
  ------------------
  746|  1.86k|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|  1.86k|			file->path = *in_path;
  748|       |
  749|  1.86k|			*file_out = file;
  750|  1.86k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.86k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.86k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.86k|	int _ret = r; \
  |  |  |  |  155|  1.86k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.86k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.86k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.86k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.86k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.86k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.86k|	return _ret; \
  |  |  |  |  163|  1.86k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  751|  1.86k|		}
  752|  2.86k|	}
  753|       |
  754|  13.5k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (754:6): [True: 1.06k, False: 12.5k]
  ------------------
  755|  13.5k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.06k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.06k|	int _ret = r; \
  |  |  |  |  155|  1.06k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.06k|	} else { \
  |  |  |  |  159|      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.06k|	return _ret; \
  |  |  |  |  163|  1.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  756|  12.5k|	switch (apdu.resp[0]) {
  757|  11.3k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  11.3k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (757:2): [True: 11.3k, False: 1.14k]
  ------------------
  758|  12.1k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  12.1k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (758:2): [True: 828, False: 11.6k]
  ------------------
  759|  12.1k|		file = sc_file_new();
  760|  12.1k|		if (file == NULL)
  ------------------
  |  Branch (760:7): [True: 0, False: 12.1k]
  ------------------
  761|  12.1k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|  12.1k|		file->path = *in_path;
  763|  12.1k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (763:7): [True: 0, False: 12.1k]
  ------------------
  764|      0|			sc_file_free(file);
  765|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  766|      0|		}
  767|  12.1k|		buffer = apdu.resp;
  768|  12.1k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  769|  12.1k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  12.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (769:7): [True: 11.2k, False: 900]
  ------------------
  770|  11.2k|			card->ops->process_fci(card, file, buffer, buffer_len);
  771|  12.1k|		*file_out = file;
  772|  12.1k|		break;
  773|     86|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (773:2): [True: 86, False: 12.4k]
  ------------------
  774|     86|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     86|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     86|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     86|	int _ret = r; \
  |  |  |  |  155|     86|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 86, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     86|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     86|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 86, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     86|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     86|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     86|	return _ret; \
  |  |  |  |  163|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  775|    232|	default:
  ------------------
  |  Branch (775:2): [True: 232, False: 12.2k]
  ------------------
  776|    232|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    232|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    232|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    232|	int _ret = r; \
  |  |  |  |  155|    232|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 232, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 232, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    232|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    232|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    232|	return _ret; \
  |  |  |  |  163|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  777|  12.5k|	}
  778|       |
  779|  12.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  12.1k|#define SC_SUCCESS				0
  ------------------
  780|  12.5k|}
iso7816.c:iso7816_get_response:
  903|  40.4k|{
  904|  40.4k|	struct sc_apdu apdu = {0};
  905|  40.4k|	int r;
  906|  40.4k|	size_t rlen;
  907|       |
  908|       |	/* request at most max_recv_size bytes */
  909|  40.4k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (909:6): [True: 506, False: 39.9k]
  ------------------
  910|    506|		rlen = sc_get_max_recv_size(card);
  911|  39.9k|	else
  912|  39.9k|		rlen = *count;
  913|       |
  914|  40.4k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  40.4k|#define SC_APDU_CASE_2			0x22
  ------------------
  915|  40.4k|	apdu.le      = rlen;
  916|  40.4k|	apdu.resplen = rlen;
  917|  40.4k|	apdu.resp    = buf;
  918|       |	/* don't call GET RESPONSE recursively */
  919|  40.4k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  40.4k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  920|       |
  921|  40.4k|	r = sc_transmit_apdu(card, &apdu);
  922|  40.4k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  40.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  40.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  40.4k|	int _ret = (r); \
  |  |  |  |  168|  40.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 489, False: 39.9k]
  |  |  |  |  ------------------
  |  |  |  |  169|    489|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    489|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    489|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    489|		return _ret; \
  |  |  |  |  172|    489|	} \
  |  |  |  |  173|  40.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 39.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  923|       |
  924|  39.9k|	*count = apdu.resplen;
  925|       |
  926|  39.9k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (926:6): [True: 9.63k, False: 30.3k]
  ------------------
  927|  9.63k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  9.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.63k|	int _ret = r; \
  |  |  |  |  155|  9.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  3.90k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.90k, False: 5.73k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.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|  9.63k|	return _ret; \
  |  |  |  |  163|  9.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|  9.63k|	}
  929|  30.3k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (929:6): [True: 19.5k, False: 10.8k]
  |  Branch (929:26): [True: 19.2k, False: 264]
  ------------------
  930|  19.2k|		r = 0;					/* no more data to read */
  931|  11.0k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (931:11): [True: 6.24k, False: 4.82k]
  ------------------
  932|  6.24k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (932:7): [True: 1.60k, False: 4.63k]
  ------------------
  933|  4.82k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (933:11): [True: 920, False: 3.90k]
  |  Branch (933:31): [True: 815, False: 105]
  ------------------
  934|    815|		r = 0; /* Le not reached but file/record ended */
  935|  4.00k|	else
  936|  4.00k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  937|       |
  938|  30.3k|	return r;
  939|  39.9k|}
iso7816.c:iso7816_restore_security_env:
 1075|     38|{
 1076|     38|	struct sc_apdu apdu;
 1077|     38|	int r;
 1078|       |
 1079|     38|	if (card == NULL) {
  ------------------
  |  Branch (1079:6): [True: 0, False: 38]
  ------------------
 1080|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1081|      0|	}
 1082|       |
 1083|     38|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
  ------------------
  |  |  291|     38|#define SC_APDU_CASE_1			0x01
  ------------------
 1084|       |
 1085|     38|	r = sc_transmit_apdu(card, &apdu);
 1086|     38|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 10, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|     28|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1088|     28|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 11, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  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|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1089|       |
 1090|     17|	return r;
 1091|     28|}
iso7816.c:iso7816_set_security_env:
  980|  1.45k|{
  981|  1.45k|	struct sc_apdu apdu;
  982|  1.45k|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  983|  1.45k|	u8 *p;
  984|  1.45k|	int r, locked = 0;
  985|       |
  986|  1.45k|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (986:6): [True: 0, False: 1.45k]
  |  Branch (986:22): [True: 0, False: 1.45k]
  ------------------
  987|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  988|      0|	}
  989|  1.45k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|  1.45k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  990|  1.45k|	switch (env->operation) {
  991|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (991:2): [True: 0, False: 1.45k]
  ------------------
  992|      0|		apdu.p2 = 0xA4;
  993|      0|		break;
  994|    340|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    340|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (994:2): [True: 340, False: 1.11k]
  ------------------
  995|    340|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|    340|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (995:2): [True: 0, False: 1.45k]
  ------------------
  996|    340|		apdu.p2 = 0xB8;
  997|    340|		break;
  998|  1.11k|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|  1.11k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (998:2): [True: 1.11k, False: 340]
  ------------------
  999|  1.11k|		apdu.p2 = 0xB6;
 1000|  1.11k|		break;
 1001|      0|	default:
  ------------------
  |  Branch (1001:2): [True: 0, False: 1.45k]
  ------------------
 1002|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1003|  1.45k|	}
 1004|  1.45k|	p = sbuf;
 1005|  1.45k|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|  1.45k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1005:6): [True: 999, False: 454]
  ------------------
 1006|    999|		*p++ = 0x80;	/* algorithm reference */
 1007|    999|		*p++ = 0x01;
 1008|    999|		*p++ = env->algorithm_ref & 0xFF;
 1009|    999|	}
 1010|  1.45k|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|  1.45k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1010:6): [True: 0, False: 1.45k]
  ------------------
 1011|      0|		if (env->file_ref.len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (1011:7): [True: 0, False: 0]
  ------------------
 1012|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1013|      0|		if (sizeof(sbuf) - (p - sbuf) < env->file_ref.len + 2)
  ------------------
  |  Branch (1013:7): [True: 0, False: 0]
  ------------------
 1014|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1015|       |
 1016|      0|		*p++ = 0x81;
 1017|      0|		*p++ = (u8) env->file_ref.len;
 1018|      0|		memcpy(p, env->file_ref.value, env->file_ref.len);
 1019|      0|		p += env->file_ref.len;
 1020|      0|	}
 1021|  1.45k|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|  1.45k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1021:6): [True: 1.45k, False: 0]
  ------------------
 1022|  1.45k|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1022:7): [True: 0, False: 1.45k]
  ------------------
 1023|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1024|       |
 1025|  1.45k|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|  1.45k|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1025:7): [True: 0, False: 1.45k]
  ------------------
 1026|      0|			*p++ = 0x83;
 1027|  1.45k|		else
 1028|  1.45k|			*p++ = 0x84;
 1029|  1.45k|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|  1.45k|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1029:7): [True: 0, False: 1.45k]
  ------------------
 1030|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1031|  1.45k|		*p++ = env->key_ref_len & 0xFF;
 1032|  1.45k|		memcpy(p, env->key_ref, env->key_ref_len);
 1033|  1.45k|		p += env->key_ref_len;
 1034|  1.45k|	}
 1035|  1.45k|	r = (int)(p - sbuf);
 1036|  1.45k|	apdu.lc = r;
 1037|  1.45k|	apdu.datalen = r;
 1038|  1.45k|	apdu.data = sbuf;
 1039|  1.45k|	if (se_num > 0) {
  ------------------
  |  Branch (1039:6): [True: 0, False: 1.45k]
  ------------------
 1040|      0|		r = sc_lock(card);
 1041|      0|		LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1042|      0|		locked = 1;
 1043|      0|	}
 1044|  1.45k|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1044:6): [True: 1.45k, False: 0]
  ------------------
 1045|  1.45k|		r = sc_transmit_apdu(card, &apdu);
 1046|  1.45k|		if (r) {
  ------------------
  |  Branch (1046:7): [True: 19, False: 1.43k]
  ------------------
 1047|     19|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(r));
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1048|     19|			goto err;
 1049|     19|		}
 1050|  1.43k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1051|  1.43k|		if (r) {
  ------------------
  |  Branch (1051:7): [True: 1.07k, False: 362]
  ------------------
 1052|  1.07k|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   71|  1.07k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1053|  1.07k|			goto err;
 1054|  1.07k|		}
 1055|  1.43k|	}
 1056|    362|	if (se_num <= 0) {
  ------------------
  |  Branch (1056:6): [True: 362, False: 0]
  ------------------
 1057|    362|		r = SC_SUCCESS;
  ------------------
  |  |   28|    362|#define SC_SUCCESS				0
  ------------------
 1058|    362|		goto err;
 1059|    362|	}
 1060|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1061|      0|	r = sc_transmit_apdu(card, &apdu);
 1062|      0|	sc_unlock(card);
 1063|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1064|       |
 1065|      0|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
 1066|  1.45k|err:
 1067|  1.45k|	if (locked)
  ------------------
  |  Branch (1067:6): [True: 0, False: 1.45k]
  ------------------
 1068|      0|		sc_unlock(card);
 1069|  1.45k|	return r;
 1070|      0|}
iso7816.c:iso7816_decipher:
 1137|     26|{
 1138|     26|	int r;
 1139|     26|	struct sc_apdu apdu;
 1140|     26|	u8 *sbuf = NULL;
 1141|       |
 1142|     26|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1142:6): [True: 0, False: 26]
  |  Branch (1142:22): [True: 0, False: 26]
  |  Branch (1142:40): [True: 0, False: 26]
  ------------------
 1143|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1144|      0|	}
 1145|     26|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     26|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     26|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     26|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     26|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|     26|	sc_log(card->ctx, "ISO7816 decipher: in-len %zu, out-len %zu", crgram_len, outlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1147|       |
 1148|     26|	sbuf = malloc(crgram_len + 1);
 1149|     26|	if (sbuf == NULL)
  ------------------
  |  Branch (1149:6): [True: 0, False: 26]
  ------------------
 1150|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1151|       |
 1152|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1153|       |	 * P1:  0x80  Resp: Plain value
 1154|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1155|     26|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     26|#define SC_APDU_CASE_4			0x24
  ------------------
 1156|     26|	apdu.resp    = out;
 1157|     26|	apdu.resplen = outlen;
 1158|     26|	apdu.le      = outlen;
 1159|       |
 1160|     26|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1161|     26|	memcpy(sbuf + 1, crgram, crgram_len);
 1162|     26|	apdu.data = sbuf;
 1163|     26|	apdu.lc = crgram_len + 1;
 1164|     26|	apdu.datalen = crgram_len + 1;
 1165|       |
 1166|     26|	iso7816_fixup_transceive_length(card, &apdu);
 1167|     26|	r = sc_transmit_apdu(card, &apdu);
 1168|     26|	sc_mem_clear(sbuf, crgram_len + 1);
 1169|     26|	free(sbuf);
 1170|     26|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     26|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     26|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     26|	int _ret = (r); \
  |  |  |  |  168|     26|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  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|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1171|       |
 1172|     22|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1172:6): [True: 15, False: 7]
  |  Branch (1172:26): [True: 11, False: 4]
  ------------------
 1173|     22|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|	} else { \
  |  |  |  |  159|      7|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      7|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      7|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1174|     11|	else
 1175|     22|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1176|     22|}
iso7816.c:iso7816_compute_signature:
 1098|    127|{
 1099|    127|	int r;
 1100|    127|	struct sc_apdu apdu;
 1101|       |
 1102|    127|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1102:6): [True: 0, False: 127]
  |  Branch (1102:22): [True: 0, False: 127]
  |  Branch (1102:38): [True: 0, False: 127]
  ------------------
 1103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1104|      0|	}
 1105|    127|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    127|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    127|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    127|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    127|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1106|    127|	sc_log(card->ctx, "ISO7816 compute signature: in-len %zu, out-len %zu", datalen, outlen);
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1107|       |
 1108|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1109|       |	 * P1:  0x9E  Resp: Digital Signature
 1110|       |	 * P2:  0x9A  Cmd: Input for Digital Signature */
 1111|    127|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  303|    127|#define SC_APDU_CASE_4			0x24
  ------------------
 1112|    127|	apdu.resp = out;
 1113|    127|	apdu.resplen = outlen;
 1114|    127|	apdu.le = outlen;
 1115|       |
 1116|    127|	apdu.data = data;
 1117|    127|	apdu.lc = datalen;
 1118|    127|	apdu.datalen = datalen;
 1119|       |
 1120|    127|	iso7816_fixup_transceive_length(card, &apdu);
 1121|    127|	r = sc_transmit_apdu(card, &apdu);
 1122|    127|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    127|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    127|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    127|	int _ret = (r); \
  |  |  |  |  168|    127|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  169|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     36|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     36|		return _ret; \
  |  |  |  |  172|     36|	} \
  |  |  |  |  173|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1123|     91|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1123:6): [True: 67, False: 24]
  |  Branch (1123:26): [True: 47, False: 20]
  ------------------
 1124|     91|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 28, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|     19|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     19|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     19|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1125|       |
 1126|     44|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1127|     44|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     44|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     44|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     44|	int _ret = (r); \
  |  |  |  |  168|     44|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 44, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     44|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     44|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     44|		return _ret; \
  |  |  |  |  172|     44|	} \
  |  |  |  |  173|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|       |
 1129|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|      0|}
iso7816.c:iso7816_check_sw:
  110|   492k|{
  111|   492k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  112|   492k|	int i;
  113|       |
  114|       |	/* Handle special cases here */
  115|   492k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (115:6): [True: 444, False: 492k]
  ------------------
  116|    444|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    444|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  117|    444|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    444|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  118|    444|	}
  119|   492k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (119:6): [True: 184k, False: 307k]
  |  Branch (119:21): [True: 177k, False: 6.67k]
  ------------------
  120|   177k|		return SC_SUCCESS;
  ------------------
  |  |   28|   177k|#define SC_SUCCESS				0
  ------------------
  121|   314k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (121:6): [True: 834, False: 313k]
  |  Branch (121:22): [True: 156, False: 678]
  ------------------
  122|    156|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|    156|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  123|    156|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    156|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  124|    156|	}
  125|  12.8M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (125:14): [True: 12.8M, False: 34.6k]
  ------------------
  126|  12.8M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (126:7): [True: 279k, False: 12.5M]
  ------------------
  127|   279k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   279k|#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|   279k|			return iso7816_errors[i].errorno;
  129|   279k|		}
  130|  12.8M|	}
  131|       |
  132|  34.6k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  34.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  133|  34.6k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  34.6k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  134|   314k|}
iso7816.c:iso7816_process_fci:
  430|  9.48k|{
  431|  9.48k|	struct sc_context *ctx = card->ctx;
  432|  9.48k|	const unsigned char *p, *end;
  433|  9.48k|	unsigned int cla = 0, tag = 0;
  434|  9.48k|	size_t length;
  435|       |
  436|  9.48k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.48k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  437|       |
  438|  9.48k|	for (p = buf, length = buflen, end = buf + buflen;
  439|  27.5k|			p < end;
  ------------------
  |  Branch (439:4): [True: 23.8k, False: 3.65k]
  ------------------
  440|  23.8k|			p += length, length = end - p) {
  441|       |
  442|  23.8k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  23.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:7): [True: 4.03k, False: 19.8k]
  ------------------
  443|  19.8k|				|| p == NULL) {
  ------------------
  |  Branch (443:8): [True: 1.79k, False: 18.0k]
  ------------------
  444|  5.82k|			break;
  445|  5.82k|		}
  446|  18.0k|		switch (cla | tag) {
  ------------------
  |  Branch (446:11): [True: 13.6k, False: 4.41k]
  ------------------
  447|  1.92k|			case 0x81:
  ------------------
  |  Branch (447:4): [True: 1.92k, False: 16.0k]
  ------------------
  448|  1.92k|				if (file->size != 0) {
  ------------------
  |  Branch (448:9): [True: 105, False: 1.82k]
  ------------------
  449|       |					/* don't overwrite existing file size excluding structural information */
  450|    105|					break;
  451|    105|				}
  452|       |				/* fall through */
  453|  3.76k|			case 0x80:
  ------------------
  |  Branch (453:4): [True: 1.94k, False: 16.0k]
  ------------------
  454|       |				/* determine the file size */
  455|  3.76k|				file->size = 0;
  456|  3.76k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (456:9): [True: 3.76k, False: 0]
  |  Branch (456:14): [True: 3.72k, False: 39]
  ------------------
  457|  3.72k|					size_t size = 0, i;
  458|  12.5k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (458:18): [True: 8.82k, False: 3.72k]
  ------------------
  459|  8.82k|						size <<= 8;
  460|  8.82k|						size |= p[i];
  461|  8.82k|					}
  462|  3.72k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  3.72k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (462:10): [True: 569, False: 3.15k]
  ------------------
  463|    569|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    569|#define MAX_FILE_SIZE 65535
  ------------------
  464|    569|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   71|    569|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  465|  3.15k|					} else {
  466|  3.15k|						file->size = size;
  467|  3.15k|					}
  468|  3.72k|				}
  469|       |
  470|  3.76k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  3.76k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  471|  3.76k|				break;
  472|       |
  473|  1.95k|			case 0x82:
  ------------------
  |  Branch (473:4): [True: 1.95k, False: 16.0k]
  ------------------
  474|  1.95k|				if (length > 0) {
  ------------------
  |  Branch (474:9): [True: 1.67k, False: 277]
  ------------------
  475|  1.67k|					unsigned char byte = p[0];
  476|  1.67k|					const char *type;
  477|       |
  478|  1.67k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (478:24): [True: 343, False: 1.33k]
  ------------------
  479|  1.67k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  3.35k|#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: 343, False: 1.33k]
  |  |  ------------------
  ------------------
  480|  1.67k|					file->ef_structure = byte & 0x07;
  481|  1.67k|					switch ((byte >> 3) & 7) {
  482|    851|						case 0:
  ------------------
  |  Branch (482:7): [True: 851, False: 824]
  ------------------
  483|    851|							type = "working EF";
  484|    851|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    851|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  485|    851|							break;
  486|    232|						case 1:
  ------------------
  |  Branch (486:7): [True: 232, False: 1.44k]
  ------------------
  487|    232|							type = "internal EF";
  488|    232|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    232|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  489|    232|							break;
  490|    295|						case 7:
  ------------------
  |  Branch (490:7): [True: 295, False: 1.38k]
  ------------------
  491|    295|							type = "DF";
  492|    295|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    295|#define SC_FILE_TYPE_DF			0x04
  ------------------
  493|    295|							break;
  494|    297|						default:
  ------------------
  |  Branch (494:7): [True: 297, False: 1.37k]
  ------------------
  495|    297|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    297|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  496|    297|							type = "unknown";
  497|    297|							break;
  498|  1.67k|					}
  499|  1.67k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  1.67k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  500|  1.67k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  1.67k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  501|  1.67k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  1.67k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  502|       |
  503|       |					/* if possible, get additional information for non-DFs */
  504|  1.67k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  1.67k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (504:10): [True: 1.38k, False: 295]
  ------------------
  505|       |						/* max. record length for fixed- & variable-sized records */
  506|  1.38k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (506:11): [True: 574, False: 806]
  |  Branch (506:25): [True: 440, False: 134]
  ------------------
  507|    440|							file->record_length = (length > 3)
  ------------------
  |  Branch (507:30): [True: 328, False: 112]
  ------------------
  508|    440|								? bebytes2ushort(p+2)
  509|    440|								: p[2];
  510|    440|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   71|    440|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  511|    440|						}
  512|       |
  513|       |						/* number of records */
  514|  1.38k|						if (length > 4) {
  ------------------
  |  Branch (514:11): [True: 241, False: 1.13k]
  ------------------
  515|    241|							file->record_count = (length > 5)
  ------------------
  |  Branch (515:29): [True: 78, False: 163]
  ------------------
  516|    241|								? bebytes2ushort(p+4)
  517|    241|								: p[4];
  518|    241|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   71|    241|#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|    241|						}
  520|  1.38k|					}
  521|       |
  522|  1.67k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  1.67k|#define SC_SUCCESS				0
  ------------------
  |  Branch (522:10): [True: 0, False: 1.67k]
  ------------------
  523|      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__
  |  |  ------------------
  ------------------
  524|  1.67k|				}
  525|  1.95k|				break;
  526|       |
  527|  1.95k|			case 0x83:
  ------------------
  |  Branch (527:4): [True: 1.13k, False: 16.8k]
  ------------------
  528|  1.13k|				if (length == 2) {
  ------------------
  |  Branch (528:9): [True: 831, False: 301]
  ------------------
  529|    831|					file->id = (p[0] << 8) | p[1];
  530|    831|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    831|#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|    831|				}
  532|  1.13k|				break;
  533|       |
  534|    668|			case 0x84:
  ------------------
  |  Branch (534:4): [True: 668, False: 17.3k]
  ------------------
  535|    668|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (535:9): [True: 461, False: 207]
  |  Branch (535:23): [True: 443, False: 18]
  ------------------
  536|    443|					memcpy(file->name, p, length);
  537|    443|					file->namelen = length;
  538|       |
  539|    443|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    443|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    443|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|    443|					if (!file->type)
  ------------------
  |  Branch (540:10): [True: 272, False: 171]
  ------------------
  541|    272|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    272|#define SC_FILE_TYPE_DF			0x04
  ------------------
  542|    443|				}
  543|    668|				break;
  544|       |
  545|    975|			case 0x85:
  ------------------
  |  Branch (545:4): [True: 975, False: 17.0k]
  ------------------
  546|  1.28k|			case 0xA5:
  ------------------
  |  Branch (546:4): [True: 311, False: 17.7k]
  ------------------
  547|  1.28k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.28k|#define SC_SUCCESS				0
  ------------------
  |  Branch (547:9): [True: 0, False: 1.28k]
  ------------------
  548|      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__
  |  |  ------------------
  ------------------
  549|      0|				}
  550|  1.28k|				break;
  551|       |
  552|  1.25k|			case 0x86:
  ------------------
  |  Branch (552:4): [True: 1.25k, False: 16.7k]
  ------------------
  553|  1.25k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (553:9): [True: 0, False: 1.25k]
  ------------------
  554|      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__
  |  |  ------------------
  ------------------
  555|      0|				}
  556|  1.25k|				break;
  557|       |
  558|    412|			case 0x88:
  ------------------
  |  Branch (558:4): [True: 412, False: 17.6k]
  ------------------
  559|    412|				if (length == 1) {
  ------------------
  |  Branch (559:9): [True: 113, False: 299]
  ------------------
  560|    113|					file->sid = *p;
  561|    113|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   71|    113|#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|    113|				}
  563|    412|				break;
  564|       |
  565|  1.52k|			case 0x8A:
  ------------------
  |  Branch (565:4): [True: 1.52k, False: 16.4k]
  ------------------
  566|  1.52k|				if (length == 1) {
  ------------------
  |  Branch (566:9): [True: 1.19k, False: 326]
  ------------------
  567|  1.19k|					switch (p[0]) {
  568|     67|						case 0:
  ------------------
  |  Branch (568:7): [True: 67, False: 1.13k]
  ------------------
  569|     67|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     67|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  570|     67|							break;
  571|     69|						case 1:
  ------------------
  |  Branch (571:7): [True: 69, False: 1.12k]
  ------------------
  572|     69|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     69|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  573|     69|							break;
  574|     67|						case 3:
  ------------------
  |  Branch (574:7): [True: 67, False: 1.13k]
  ------------------
  575|     67|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     67|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  576|     67|							break;
  577|     68|						case 4:
  ------------------
  |  Branch (577:7): [True: 68, False: 1.13k]
  ------------------
  578|    135|						case 6:
  ------------------
  |  Branch (578:7): [True: 67, False: 1.13k]
  ------------------
  579|    135|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    135|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  580|    135|							break;
  581|    116|						case 5:
  ------------------
  |  Branch (581:7): [True: 116, False: 1.08k]
  ------------------
  582|    184|						case 7:
  ------------------
  |  Branch (582:7): [True: 68, False: 1.13k]
  ------------------
  583|    184|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    184|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  584|    184|							break;
  585|     67|						case 12:
  ------------------
  |  Branch (585:7): [True: 67, False: 1.13k]
  ------------------
  586|    133|						case 13:
  ------------------
  |  Branch (586:7): [True: 66, False: 1.13k]
  ------------------
  587|    201|						case 14:
  ------------------
  |  Branch (587:7): [True: 68, False: 1.13k]
  ------------------
  588|    267|						case 15:
  ------------------
  |  Branch (588:7): [True: 66, False: 1.13k]
  ------------------
  589|    267|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    267|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  590|    267|							break;
  591|     71|						case 2:
  ------------------
  |  Branch (591:7): [True: 71, False: 1.12k]
  ------------------
  592|     71|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     71|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  593|     71|							break;
  594|     68|						case 8:
  ------------------
  |  Branch (594:7): [True: 68, False: 1.13k]
  ------------------
  595|     68|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     68|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  596|     68|							break;
  597|     66|						case 9:
  ------------------
  |  Branch (597:7): [True: 66, False: 1.13k]
  ------------------
  598|     66|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     66|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  599|     66|							break;
  600|     66|						case 10:
  ------------------
  |  Branch (600:7): [True: 66, False: 1.13k]
  ------------------
  601|     66|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     66|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  602|     66|							break;
  603|     66|						case 11:
  ------------------
  |  Branch (603:7): [True: 66, False: 1.13k]
  ------------------
  604|     66|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     66|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  605|     66|							break;
  606|     72|						default:
  ------------------
  |  Branch (606:7): [True: 72, False: 1.12k]
  ------------------
  607|     72|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     72|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  608|  1.19k|					}
  609|  1.19k|				}
  610|  1.52k|				break;
  611|       |
  612|  1.52k|			case 0x62:
  ------------------
  |  Branch (612:4): [True: 904, False: 17.1k]
  ------------------
  613|  1.04k|			case 0x64:
  ------------------
  |  Branch (613:4): [True: 142, False: 17.8k]
  ------------------
  614|  1.51k|			case 0x6F:
  ------------------
  |  Branch (614:4): [True: 464, False: 17.5k]
  ------------------
  615|       |				/* allow nested FCP/FMD/FCI templates */
  616|  1.51k|				iso7816_process_fci(card, file, p, length);
  617|  18.0k|		}
  618|  18.0k|	}
  619|       |
  620|  9.48k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|  9.48k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  621|       |
  622|  9.48k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.48k|#define SC_SUCCESS				0
  ------------------
  623|  9.48k|}
iso7816.c:iso7816_pin_cmd:
 1281|  9.14k|{
 1282|  9.14k|	struct sc_apdu local_apdu, *apdu;
 1283|  9.14k|	int r;
 1284|  9.14k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1285|       |
 1286|  9.14k|	data->pin1.tries_left = -1;
 1287|       |
 1288|       |	/* Many cards do support PIN status queries, but some cards don't and
 1289|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1290|       |	 * allow cards with this flag.  In future this may be reduced to a
 1291|       |	 * blocklist, subject to testing more cards. */
 1292|  9.14k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  18.2k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1292:6): [True: 7.44k, False: 1.70k]
  ------------------
 1293|  7.44k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|  7.44k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1293:6): [True: 248, False: 7.19k]
  ------------------
 1294|    248|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    248|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1295|    248|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    248|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1296|    248|	}
 1297|       |
 1298|       |	/* See if we've been called from another card driver, which is
 1299|       |	 * passing an APDU to us (this allows to write card drivers
 1300|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1301|       |	 * special circumstances.
 1302|       |	 */
 1303|  8.90k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1303:6): [True: 8.89k, False: 5]
  ------------------
 1304|  8.89k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1305|  8.89k|		if (r < 0)
  ------------------
  |  Branch (1305:7): [True: 65, False: 8.83k]
  ------------------
 1306|     65|			return r;
 1307|  8.83k|		data->apdu = &local_apdu;
 1308|  8.83k|	}
 1309|  8.83k|	apdu = data->apdu;
 1310|       |
 1311|  8.83k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|  8.83k|#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 (1311:6): [True: 8.83k, False: 0]
  |  Branch (1311:48): [True: 0, False: 0]
  ------------------
 1312|       |		/* Transmit the APDU to the card */
 1313|  8.83k|		r = sc_transmit_apdu(card, apdu);
 1314|       |
 1315|       |		/* Clear the buffer - it may contain pins */
 1316|  8.83k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1317|  8.83k|	}
 1318|      0|	else {
 1319|       |		/* Call the reader driver to collect
 1320|       |		 * the PIN and pass on the APDU to the card */
 1321|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1321:7): [True: 0, False: 0]
  ------------------
 1322|      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__
  |  |  ------------------
  ------------------
 1323|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1324|      0|		}
 1325|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1325:7): [True: 0, False: 0]
  |  Branch (1325:23): [True: 0, False: 0]
  |  Branch (1325:44): [True: 0, False: 0]
  ------------------
 1326|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1327|       |			/* sw1/sw2 filled in by reader driver */
 1328|      0|		}
 1329|      0|		else {
 1330|      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__
  |  |  ------------------
  ------------------
 1331|      0|					"PIN entry through reader key pad");
 1332|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1333|      0|		}
 1334|      0|	}
 1335|       |
 1336|       |	/* Don't pass references to local variables up to the caller. */
 1337|  8.83k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1337:6): [True: 8.83k, False: 5]
  ------------------
 1338|  8.83k|		data->apdu = NULL;
 1339|       |
 1340|  8.83k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  8.83k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.83k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.83k|	int _ret = (r); \
  |  |  |  |  168|  8.83k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 48, False: 8.78k]
  |  |  |  |  ------------------
  |  |  |  |  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|  8.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|  8.78k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1342|       |
 1343|  8.78k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  8.78k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1343:6): [True: 2.13k, False: 6.65k]
  ------------------
 1344|  2.13k|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|  2.13k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1345|  6.65k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  6.65k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1345:13): [True: 43, False: 6.61k]
  ------------------
 1346|     43|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1347|     43|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     43|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1348|     43|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     43|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1348:7): [True: 20, False: 23]
  ------------------
 1349|     20|			r = SC_SUCCESS;
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
 1350|  6.61k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  6.61k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1350:13): [True: 12, False: 6.59k]
  ------------------
 1351|     12|		data->pin1.tries_left = 0;
 1352|     12|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     12|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1353|     12|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     12|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1353:7): [True: 8, False: 4]
  ------------------
 1354|      8|			r = SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 1355|     12|	}
 1356|       |
 1357|  8.78k|	return r;
 1358|  8.83k|}
iso7816.c:iso7816_get_data:
 1362|    232|{
 1363|    232|	int                             r, cse;
 1364|    232|	struct sc_apdu                  apdu;
 1365|       |
 1366|    232|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    232|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    232|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    232|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 232]
  |  |  ------------------
  ------------------
 1367|       |
 1368|    232|	if (buf && len)
  ------------------
  |  Branch (1368:6): [True: 232, False: 0]
  |  Branch (1368:13): [True: 232, False: 0]
  ------------------
 1369|    232|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    232|#define SC_APDU_CASE_2			0x22
  ------------------
 1370|      0|	else
 1371|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1372|       |
 1373|    232|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1374|    232|	apdu.le = len;
 1375|    232|	apdu.resp = buf;
 1376|    232|	apdu.resplen = len;
 1377|    232|	r = sc_transmit_apdu(card, &apdu);
 1378|    232|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    232|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    232|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    232|	int _ret = (r); \
  |  |  |  |  168|    232|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 226]
  |  |  |  |  ------------------
  |  |  |  |  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|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 226]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1379|       |
 1380|    226|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1381|    226|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    226|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    226|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    226|	int _ret = (r); \
  |  |  |  |  168|    226|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 68, False: 158]
  |  |  |  |  ------------------
  |  |  |  |  169|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     68|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     68|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     68|		return _ret; \
  |  |  |  |  172|     68|	} \
  |  |  |  |  173|    226|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 158]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1382|       |
 1383|    158|	if (apdu.resplen > len)
  ------------------
  |  Branch (1383:6): [True: 0, False: 158]
  ------------------
 1384|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1385|    158|	else
 1386|    158|		r = (int)apdu.resplen;
 1387|       |
 1388|    158|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    158|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    158|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    158|	int _ret = r; \
  |  |  |  |  155|    158|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 35, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  157|     35|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    123|	} else { \
  |  |  |  |  159|    123|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    123|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    123|	} \
  |  |  |  |  162|    158|	return _ret; \
  |  |  |  |  163|    158|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1389|    158|}
iso7816.c:iso7816_read_binary:
  139|  25.6k|{
  140|  25.6k|	struct sc_context *ctx = card->ctx;
  141|  25.6k|	struct sc_apdu apdu;
  142|  25.6k|	int r;
  143|       |
  144|  25.6k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (144:6): [True: 3, False: 25.6k]
  ------------------
  145|      3|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  146|      3|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      3|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  147|      3|	}
  148|       |
  149|  25.6k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  25.6k|#define SC_APDU_CASE_2			0x22
  ------------------
  150|  25.6k|	apdu.le = count;
  151|  25.6k|	apdu.resplen = count;
  152|  25.6k|	apdu.resp = buf;
  153|       |
  154|  25.6k|	iso7816_fixup_transceive_length(card, &apdu);
  155|  25.6k|	r = sc_transmit_apdu(card, &apdu);
  156|  25.6k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  25.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  25.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  25.6k|	int _ret = (r); \
  |  |  |  |  168|  25.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 315, False: 25.3k]
  |  |  |  |  ------------------
  |  |  |  |  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|  25.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 25.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|       |
  158|  25.3k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  159|  25.3k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  50.7k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  24.0k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (159:6): [True: 1.30k, False: 24.0k]
  |  Branch (159:40): [True: 249, False: 23.8k]
  ------------------
  160|  25.3k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.55k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.55k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.55k|	int _ret = r; \
  |  |  |  |  155|  1.55k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 514, False: 1.04k]
  |  |  |  |  ------------------
  |  |  |  |  156|    514|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 514]
  |  |  |  |  ------------------
  |  |  |  |  157|    514|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.04k|	} else { \
  |  |  |  |  159|  1.04k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.04k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.04k|	} \
  |  |  |  |  162|  1.55k|	return _ret; \
  |  |  |  |  163|  1.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|  23.8k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  23.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  23.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  23.8k|	int _ret = (r); \
  |  |  |  |  168|  23.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.64k, False: 21.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.64k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.64k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.64k|		return _ret; \
  |  |  |  |  172|  2.64k|	} \
  |  |  |  |  173|  23.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 21.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|       |
  163|  21.1k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  21.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  21.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  21.1k|	int _ret = r; \
  |  |  |  |  155|  21.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.42k, False: 19.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.42k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  19.7k|	} else { \
  |  |  |  |  159|  19.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  19.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  19.7k|	} \
  |  |  |  |  162|  21.1k|	return _ret; \
  |  |  |  |  163|  21.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|  21.1k|}

sc_do_log:
   57|  18.6M|{
   58|  18.6M|	va_list ap;
   59|       |
   60|  18.6M|	va_start(ap, format);
   61|  18.6M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   62|       |	va_end(ap);
   63|  18.6M|}
sc_do_log_color:
   66|  5.60M|{
   67|  5.60M|	va_list ap;
   68|       |
   69|  5.60M|	va_start(ap, format);
   70|  5.60M|	sc_do_log_va(ctx, level, file, line, func, color, format, ap);
   71|       |	va_end(ap);
   72|  5.60M|}
sc_do_log_openssl:
   76|  6.73k|{
   77|  6.73k|	BIO *bio = NULL;
   78|  6.73k|	int length, rc;
   79|  6.73k|	char *buffer = NULL;
   80|       |
   81|  6.73k|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (81:6): [True: 0, False: 6.73k]
  ------------------
   82|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   83|      0|		goto end;
   84|      0|	}
   85|  6.73k|	ERR_print_errors(bio);
   86|       |
   87|  6.73k|	length = BIO_pending(bio);
   88|  6.73k|	if (length <= 0) {
  ------------------
  |  Branch (88:6): [True: 6.73k, False: 2]
  ------------------
   89|       |		/* no error? */
   90|  6.73k|		goto end;
   91|  6.73k|	}
   92|       |	/* trailing null byte */
   93|      2|	buffer = malloc(length + 1);
   94|      2|	if (buffer == NULL) {
  ------------------
  |  Branch (94:6): [True: 0, False: 2]
  ------------------
   95|      0|		sc_do_log(ctx, level, file, line, func, "No memory!");
   96|      0|		goto end;
   97|      0|	}
   98|      2|	rc = BIO_read(bio, buffer, length);
   99|      2|	buffer[length] = '\0';
  100|      2|	if (rc <= 0) {
  ------------------
  |  Branch (100:6): [True: 0, False: 2]
  ------------------
  101|      0|		sc_do_log(ctx, level, file, line, func, "Cannot read OpenSSL error");
  102|      0|		goto end;
  103|      0|	}
  104|       |
  105|      2|	sc_do_log(ctx, level, file, line, func, "OpenSSL error\n%s", buffer);
  106|  6.73k|end:
  107|  6.73k|	free(buffer);
  108|  6.73k|	BIO_free(bio);
  109|  6.73k|}
_sc_debug_hex:
  342|   513k|{
  343|   513k|	size_t blen;
  344|   513k|	char *buf;
  345|   513k|	const char *truncated = "";
  346|       |
  347|   513k|	if (len > SC_MAX_EXT_APDU_BUFFER_SIZE) {
  ------------------
  |  |   37|   513k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  |  Branch (347:6): [True: 0, False: 513k]
  ------------------
  348|      0|		len = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|      0|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  349|      0|		truncated = "truncated to ";
  350|      0|	}
  351|   513k|	blen = len * 5 + 128;
  352|       |
  353|   513k|	buf = malloc(blen);
  354|   513k|	if (buf == NULL)
  ------------------
  |  Branch (354:6): [True: 0, False: 513k]
  ------------------
  355|      0|		return;
  356|       |
  357|   513k|	sc_hex_dump(data, len, buf, blen);
  358|       |
  359|   513k|	if (label)
  ------------------
  |  Branch (359:6): [True: 513k, False: 0]
  ------------------
  360|   513k|		sc_do_log(ctx, type, file, line, func, "\n%s (%s%zu byte%s):\n%s",
  361|   513k|				label, truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (361:28): [True: 1.66k, False: 511k]
  ------------------
  362|      0|	else
  363|      0|		sc_do_log(ctx, type, file, line, func, "%s%zu byte%s:\n%s",
  364|      0|				truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (364:21): [True: 0, False: 0]
  ------------------
  365|       |
  366|   513k|	free(buf);
  367|   513k|}
sc_hex_dump:
  370|   513k|{
  371|   513k|	char *p = buf;
  372|   513k|	size_t p_len = len;
  373|   513k|	int lines = 0;
  374|       |
  375|   513k|	if (buf == NULL || (in == NULL && count != 0)) {
  ------------------
  |  Branch (375:6): [True: 0, False: 513k]
  |  Branch (375:22): [True: 351, False: 513k]
  |  Branch (375:36): [True: 0, False: 351]
  ------------------
  376|      0|		return;
  377|      0|	}
  378|   513k|	buf[0] = 0;
  379|   513k|	if ((count * 5) > len)
  ------------------
  |  Branch (379:6): [True: 0, False: 513k]
  ------------------
  380|      0|		return;
  381|  4.31M|	while (count) {
  ------------------
  |  Branch (381:9): [True: 3.80M, False: 513k]
  ------------------
  382|  3.80M|		char ascbuf[17];
  383|  3.80M|		size_t i;
  384|       |
  385|  61.4M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (385:15): [True: 61.0M, False: 395k]
  |  Branch (385:28): [True: 57.6M, False: 3.40M]
  ------------------
  386|  57.6M|			sprintf(p, "%02X ", *in);
  387|  57.6M|			if (isprint(*in))
  ------------------
  |  Branch (387:8): [True: 36.4M, False: 21.2M]
  ------------------
  388|  36.4M|				ascbuf[i] = *in;
  389|  21.2M|			else
  390|  21.2M|				ascbuf[i] = '.';
  391|  57.6M|			p += 3;
  392|  57.6M|			p_len -= 3;
  393|  57.6M|			in++;
  394|  57.6M|		}
  395|  3.80M|		count -= i;
  396|  3.80M|		ascbuf[i] = 0;
  397|  4.42M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (397:10): [True: 849k, False: 3.57M]
  |  Branch (397:20): [True: 624k, False: 224k]
  ------------------
  398|   624k|			strlcat(p, "   ", p_len);
  399|   624k|			p += 3;
  400|   624k|			p_len -= 3;
  401|   624k|		}
  402|  3.80M|		snprintf(p, p_len, "%s\n", ascbuf);
  403|  3.80M|		p += strlen(ascbuf) + 1;
  404|  3.80M|		p_len -= strlen(ascbuf) - 1;
  405|  3.80M|		lines++;
  406|  3.80M|	}
  407|   513k|}
sc_dump_hex:
  411|   212k|{
  412|   212k|	static char dump_buf[0x1000];
  413|   212k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  414|   212k|	size_t offs = 0;
  415|       |
  416|   212k|	memset(dump_buf, 0, sizeof(dump_buf));
  417|   212k|	if (in == NULL)
  ------------------
  |  Branch (417:6): [True: 0, False: 212k]
  ------------------
  418|      0|		return dump_buf;
  419|       |
  420|  1.23M|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (420:13): [True: 1.02M, False: 212k]
  ------------------
  421|  1.02M|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (421:7): [True: 948k, False: 75.6k]
  |  Branch (421:13): [True: 21.4k, False: 927k]
  ------------------
  422|  21.4k|			if (!(ii%48))
  ------------------
  |  Branch (422:8): [True: 5.82k, False: 15.6k]
  ------------------
  423|  5.82k|				snprintf(dump_buf + offs, size - offs, "\n");
  424|  15.6k|			else
  425|  15.6k|				snprintf(dump_buf + offs, size - offs, " ");
  426|  21.4k|			offs = strlen(dump_buf);
  427|  21.4k|		}
  428|       |
  429|  1.02M|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  430|  1.02M|		offs += 2;
  431|       |
  432|  1.02M|		if (offs > size)
  ------------------
  |  Branch (432:7): [True: 0, False: 1.02M]
  ------------------
  433|      0|			break;
  434|  1.02M|	}
  435|       |
  436|   212k|	if (ii<count)
  ------------------
  |  Branch (436:6): [True: 0, False: 212k]
  ------------------
  437|      0|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  438|       |
  439|   212k|	return dump_buf;
  440|   212k|}
sc_dump_oid:
  444|  7.19k|{
  445|  7.19k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  446|  7.19k|        size_t ii;
  447|       |
  448|  7.19k|	memset(dump_buf, 0, sizeof(dump_buf));
  449|  7.19k|	if (oid)
  ------------------
  |  Branch (449:6): [True: 7.19k, False: 0]
  ------------------
  450|  54.7k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|   109k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (450:14): [True: 54.7k, False: 0]
  |  Branch (450:44): [True: 47.5k, False: 7.19k]
  ------------------
  451|  47.5k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (451:88): [True: 40.3k, False: 7.19k]
  ------------------
  452|       |
  453|  7.19k|	return dump_buf;
  454|  7.19k|}
log.c:sc_do_log_va:
  123|  24.2M|{
  124|       |#ifdef _WIN32
  125|       |	SYSTEMTIME st;
  126|       |#else
  127|  24.2M|	struct tm *tm;
  128|  24.2M|	struct timeval tv;
  129|  24.2M|	char time_string[40];
  130|  24.2M|#endif
  131|       |
  132|  24.2M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (132:6): [True: 0, False: 24.2M]
  |  Branch (132:14): [True: 24.2M, False: 0]
  ------------------
  133|  24.2M|		return;
  134|       |
  135|       |#ifdef _WIN32
  136|       |	/* In Windows, file handles can not be shared between DLL-s, each DLL has a
  137|       |	 * separate file handle table. Make sure we always have a valid file
  138|       |	 * descriptor. */
  139|       |	if (sc_ctx_log_to_file(ctx, ctx->debug_filename) < 0)
  140|       |		return;
  141|       |#endif
  142|      0|	if (ctx->debug_file == NULL)
  ------------------
  |  Branch (142:6): [True: 0, False: 0]
  ------------------
  143|      0|		return;
  144|       |
  145|       |#ifdef _WIN32
  146|       |	GetLocalTime(&st);
  147|       |	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  148|       |			ctx, ctx->debug_file,
  149|       |			"P:%lu; T:%lu",
  150|       |			(unsigned long)GetCurrentProcessId(),
  151|       |			(unsigned long)GetCurrentThreadId());
  152|       |	sc_color_fprintf(SC_COLOR_FG_GREEN,
  153|       |			ctx, ctx->debug_file,
  154|       |			" %i-%02i-%02i %02i:%02i:%02i.%03i",
  155|       |			st.wYear, st.wMonth, st.wDay,
  156|       |			st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
  157|       |#else
  158|      0|	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   45|      0|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   56|      0|#define SC_COLOR_BOLD			0x8080
  ------------------
  159|      0|			ctx, ctx->debug_file,
  160|      0|			"P:%lu; T:0x%lu",
  161|      0|			(unsigned long)getpid(),
  162|      0|			(unsigned long)pthread_self());
  163|      0|	gettimeofday (&tv, NULL);
  164|      0|	tm = localtime (&tv.tv_sec);
  165|      0|	strftime (time_string, sizeof(time_string), "%H:%M:%S", tm);
  166|      0|	sc_color_fprintf(SC_COLOR_FG_GREEN,
  ------------------
  |  |   45|      0|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
  167|      0|			ctx, ctx->debug_file,
  168|      0|			" %s.%03ld",
  169|      0|			time_string,
  170|      0|			(long)tv.tv_usec / 1000);
  171|      0|#endif
  172|       |
  173|      0|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|      0|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  174|      0|			ctx, ctx->debug_file,
  175|      0|			" [");
  176|      0|	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   46|      0|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   56|      0|#define SC_COLOR_BOLD			0x8080
  ------------------
  177|      0|			ctx, ctx->debug_file,
  178|      0|			"%s",
  179|      0|			ctx->app_name);
  180|      0|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|      0|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  181|      0|			ctx, ctx->debug_file,
  182|      0|			"] ");
  183|       |
  184|      0|	if (file != NULL) {
  ------------------
  |  Branch (184:6): [True: 0, False: 0]
  ------------------
  185|      0|		sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|      0|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  186|      0|				ctx, ctx->debug_file,
  187|      0|				"%s:%d:%s: ",
  188|      0|				file, line, func ? func : "");
  ------------------
  |  Branch (188:17): [True: 0, False: 0]
  ------------------
  189|      0|	}
  190|       |
  191|      0|	sc_color_fprintf_va(color, ctx, ctx->debug_file, format, args);
  192|      0|	if (strlen(format) == 0 || format[strlen(format) - 1] != '\n')
  ------------------
  |  Branch (192:6): [True: 0, False: 0]
  |  Branch (192:29): [True: 0, False: 0]
  ------------------
  193|      0|		sc_color_fprintf(color, ctx, ctx->debug_file, "\n");
  194|      0|	fflush(ctx->debug_file);
  195|       |
  196|       |#ifdef _WIN32
  197|       |	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  198|       |		fclose(ctx->debug_file);
  199|       |	ctx->debug_file = NULL;
  200|       |#endif
  201|      0|}

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

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

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

sc_asn1_decode_algorithm_id:
  509|  5.21k|{
  510|  5.21k|	struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
  511|  5.21k|	struct sc_asn1_entry asn1_alg_id[3];
  512|  5.21k|	int r;
  513|       |
  514|  5.21k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.21k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.21k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.21k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.21k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|  5.21k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  516|  5.21k|	sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
  517|       |
  518|  5.21k|	memset(id, 0, sizeof(*id));
  519|  5.21k|	r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
  520|  5.21k|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
  ------------------
  |  |  174|  5.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.21k|	int _ret = (r); \
  |  |  |  |  168|  5.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 5.19k]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|       |
  522|  5.19k|        sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  523|       |
  524|       |	/* See if we understand the algorithm, and if we do, check
  525|       |	 * whether we know how to decode any additional parameters */
  526|  5.19k|	id->algorithm = (unsigned int ) -1;
  527|  5.19k|	alg_info = sc_asn1_get_algorithm_info(id);
  528|  5.19k|	if (alg_info != NULL) {
  ------------------
  |  Branch (528:6): [True: 2.71k, False: 2.47k]
  ------------------
  529|  2.71k|		id->algorithm = alg_info->id;
  530|  2.71k|		if (alg_info->decode) {
  ------------------
  |  Branch (530:7): [True: 1.28k, False: 1.42k]
  ------------------
  531|  1.28k|			if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|  1.28k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (531:8): [True: 10, False: 1.27k]
  ------------------
  532|     10|				sc_log(ctx, "SC_ASN1_PRESENT was set, so invalid");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  533|     10|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|     10|			}
  535|  1.27k|			r = alg_info->decode(ctx, &id->params, in, len, depth);
  536|  1.27k|		}
  537|  2.71k|	}
  538|       |
  539|  5.18k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  5.18k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.18k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.18k|	int _ret = r; \
  |  |  |  |  155|  5.18k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 54, False: 5.12k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.18k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.18k|	return _ret; \
  |  |  |  |  163|  5.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|  5.18k|}
sc_asn1_encode_algorithm_id:
  546|  2.00k|{
  547|  2.00k|	struct sc_asn1_pkcs15_algorithm_info *alg_info;
  548|  2.00k|	struct sc_algorithm_id temp_id;
  549|  2.00k|	struct sc_asn1_entry asn1_alg_id[3];
  550|  2.00k|	u8 *obj = NULL;
  551|  2.00k|	size_t obj_len = 0;
  552|  2.00k|	int r;
  553|  2.00k|	u8 *tmp;
  554|       |
  555|  2.00k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.00k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.00k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  2.00k|        sc_log(ctx, "type of algorithm to encode: %lu", id->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  557|  2.00k|	alg_info = sc_asn1_get_algorithm_info(id);
  558|  2.00k|	if (alg_info == NULL) {
  ------------------
  |  Branch (558:6): [True: 0, False: 2.00k]
  ------------------
  559|      0|		sc_log(ctx, "Cannot encode unknown algorithm %lu", id->algorithm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  560|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  561|      0|	}
  562|       |
  563|       |	/* Set the oid if not yet given */
  564|  2.00k|	if (!sc_valid_oid(&id->oid)) {
  ------------------
  |  Branch (564:6): [True: 0, False: 2.00k]
  ------------------
  565|      0|		temp_id = *id;
  566|      0|		temp_id.oid = alg_info->oid;
  567|      0|		id = &temp_id;
  568|      0|	}
  569|       |
  570|  2.00k|        sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  571|  2.00k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  572|  2.00k|	sc_format_asn1_entry(asn1_alg_id + 0, (void *) &id->oid, NULL, 1);
  573|       |
  574|       |	/* no parameters, write NULL tag */
  575|       |	/* If it's EDDSA/XEDDSA, according to RFC8410, params
  576|       |	 * MUST be absent */
  577|       |	/* PKCS11 3.0 list them under ec_params */
  578|  2.00k|	if (id->algorithm != SC_ALGORITHM_EDDSA &&
  ------------------
  |  |   72|  4.00k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (578:6): [True: 2.00k, False: 0]
  ------------------
  579|  2.00k|	    id->algorithm != SC_ALGORITHM_XEDDSA &&
  ------------------
  |  |   73|  4.00k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (579:6): [True: 2.00k, False: 0]
  ------------------
  580|  2.00k|	    (!id->params || !alg_info->encode))
  ------------------
  |  Branch (580:7): [True: 965, False: 1.03k]
  |  Branch (580:22): [True: 0, False: 1.03k]
  ------------------
  581|    965|		asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|    965|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  582|       |
  583|  2.00k|	r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
  584|  2.00k|	LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
  ------------------
  |  |  174|  2.00k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.00k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.00k|	int _ret = (r); \
  |  |  |  |  168|  2.00k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.00k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|       |	/* Encode any parameters */
  587|  2.00k|	if (id->params && alg_info->encode) {
  ------------------
  |  Branch (587:6): [True: 1.03k, False: 965]
  |  Branch (587:20): [True: 1.03k, False: 0]
  ------------------
  588|  1.03k|		r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
  589|  1.03k|		if (r < 0) {
  ------------------
  |  Branch (589:7): [True: 0, False: 1.03k]
  ------------------
  590|      0|			if (obj)
  ------------------
  |  Branch (590:8): [True: 0, False: 0]
  ------------------
  591|      0|				free(obj);
  592|      0|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  593|      0|		}
  594|  1.03k|	}
  595|       |
  596|  2.00k|	if (obj_len) {
  ------------------
  |  Branch (596:6): [True: 1.03k, False: 965]
  ------------------
  597|  1.03k|		tmp = (u8 *) realloc(*buf, *len + obj_len);
  598|  1.03k|		if (!tmp) {
  ------------------
  |  Branch (598:7): [True: 0, False: 1.03k]
  ------------------
  599|      0|			free(*buf);
  600|      0|			*buf = NULL;
  601|      0|			free(obj);
  602|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  603|      0|		}
  604|  1.03k|		*buf = tmp;
  605|  1.03k|		memcpy(*buf + *len, obj, obj_len);
  606|  1.03k|		*len += obj_len;
  607|  1.03k|		free(obj);
  608|  1.03k|	}
  609|       |
  610|  2.00k|	sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  611|  2.00k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.00k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.00k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.00k|	int _ret = r; \
  |  |  |  |  155|  2.00k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.00k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.00k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.00k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.00k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.00k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.00k|	return _ret; \
  |  |  |  |  163|  2.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|  2.00k|}
sc_asn1_clear_algorithm_id:
  616|  6.95k|{
  617|  6.95k|	struct sc_asn1_pkcs15_algorithm_info *aip;
  618|       |
  619|  6.95k|	if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
  ------------------
  |  Branch (619:6): [True: 2.22k, False: 4.73k]
  |  Branch (619:20): [True: 2.22k, False: 0]
  |  Branch (619:62): [True: 2.22k, False: 0]
  ------------------
  620|  2.22k|		aip->free(id->params);
  621|       |		id->params = NULL;
  622|  2.22k|	}
  623|  6.95k|}
pkcs15-algo.c:sc_asn1_get_algorithm_info:
  485|  9.42k|{
  486|  9.42k|	struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
  487|       |
  488|   120k|	for (aip = algorithm_table; aip->id >= 0; aip++)   {
  ------------------
  |  Branch (488:30): [True: 118k, False: 2.47k]
  ------------------
  489|   118k|		if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
  ------------------
  |  Branch (489:7): [True: 70.8k, False: 47.4k]
  |  Branch (489:34): [True: 2.71k, False: 68.1k]
  ------------------
  490|  2.71k|			return aip;
  491|       |
  492|   115k|		if (aip->id == (int)id->algorithm)
  ------------------
  |  Branch (492:7): [True: 4.22k, False: 111k]
  ------------------
  493|  4.22k|			return aip;
  494|   115k|	}
  495|       |
  496|  2.47k|	return NULL;
  497|  9.42k|}
pkcs15-algo.c:asn1_decode_des_params:
   44|      2|{
   45|      2|	struct sc_asn1_entry asn1_des_iv[2];
   46|      2|	u8	iv[8];
   47|      2|	size_t ivlen = 8;
   48|      2|	int r;
   49|       |
   50|      2|	sc_copy_asn1_entry(c_asn1_des_iv, asn1_des_iv);
   51|      2|	sc_format_asn1_entry(asn1_des_iv + 0, iv, &ivlen, 0);
   52|      2|	r = _sc_asn1_decode(ctx, asn1_des_iv, buf, buflen, NULL, NULL, 0, depth + 1);
   53|      2|	if (r < 0)
  ------------------
  |  Branch (53:6): [True: 1, False: 1]
  ------------------
   54|      1|		return r;
   55|      1|	if (ivlen != 8)
  ------------------
  |  Branch (55:6): [True: 1, False: 0]
  ------------------
   56|      1|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   57|      0|	*paramp = malloc(8);
   58|      0|	if (!*paramp)
  ------------------
  |  Branch (58:6): [True: 0, False: 0]
  ------------------
   59|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
   60|      0|	memcpy(*paramp, iv, 8);
   61|      0|	return 0;
   62|      0|}
pkcs15-algo.c:asn1_decode_pbkdf2_params:
  143|     10|{
  144|     10|	struct sc_pbkdf2_params info;
  145|     10|	struct sc_asn1_entry asn1_pbkdf2_params[5];
  146|     10|	int r;
  147|       |
  148|     10|	sc_copy_asn1_entry(c_asn1_pbkdf2_params, asn1_pbkdf2_params);
  149|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 0,
  150|     10|			info.salt, &info.salt_len, 0);
  151|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 1,
  152|     10|			&info.iterations, NULL, 0);
  153|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 2,
  154|     10|			&info.key_length, NULL, 0);
  155|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 3,
  156|     10|			&info.hash_alg, NULL, 0);
  157|       |
  158|     10|	memset(&info, 0, sizeof(info));
  159|     10|	info.salt_len = sizeof(info.salt);
  160|     10|	info.hash_alg.algorithm = SC_ALGORITHM_SHA1;
  ------------------
  |  |   84|     10|#define SC_ALGORITHM_SHA1		129
  ------------------
  161|       |
  162|     10|	r = _sc_asn1_decode(ctx, asn1_pbkdf2_params, buf, buflen, NULL, NULL, 0, depth + 1);
  163|     10|	if (r < 0)
  ------------------
  |  Branch (163:6): [True: 10, False: 0]
  ------------------
  164|     10|		return r;
  165|       |
  166|      0|	*paramp = malloc(sizeof(info));
  167|      0|	if (!*paramp)
  ------------------
  |  Branch (167:6): [True: 0, False: 0]
  ------------------
  168|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  169|      0|	memcpy(*paramp, &info, sizeof(info));
  170|      0|	return 0;
  171|      0|}
pkcs15-algo.c:asn1_decode_pbes2_params:
  206|     10|{
  207|     10|	struct sc_asn1_entry asn1_pbes2_params[3];
  208|     10|	struct sc_pbes2_params info;
  209|     10|	int r;
  210|       |
  211|     10|	sc_copy_asn1_entry(c_asn1_pbes2_params, asn1_pbes2_params);
  212|     10|	sc_format_asn1_entry(asn1_pbes2_params + 0,
  213|     10|				&info.derivation_alg, NULL, 0);
  214|     10|	sc_format_asn1_entry(asn1_pbes2_params + 1,
  215|     10|				&info.key_encr_alg, NULL, 0);
  216|     10|	memset(&info, 0, sizeof(info));
  217|       |
  218|     10|	r = _sc_asn1_decode(ctx, asn1_pbes2_params, buf, buflen, NULL, NULL, 0, depth + 1);
  219|     10|	if (r < 0)
  ------------------
  |  Branch (219:6): [True: 10, False: 0]
  ------------------
  220|     10|		return r;
  221|      0|	*paramp = malloc(sizeof(info));
  222|      0|	if (!*paramp)
  ------------------
  |  Branch (222:6): [True: 0, False: 0]
  ------------------
  223|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  224|      0|	memcpy(*paramp, &info, sizeof(info));
  225|      0|	return 0;
  226|      0|}
pkcs15-algo.c:asn1_decode_ec_params:
  264|  1.25k|{
  265|  1.25k|	int r;
  266|  1.25k|	struct sc_object_id curve;
  267|  1.25k|	struct sc_asn1_entry asn1_ec_params[4];
  268|  1.25k|	struct sc_ec_parameters *ecp;
  269|       |
  270|  1.25k|	memset(&curve, 0, sizeof(curve));
  271|       |
  272|       |	/* We only want to copy the parms if they are a namedCurve
  273|       |	 * or ecParameters  nullParam aka implicityCA is not to be
  274|       |	 * used with PKCS#11 2.20 */
  275|  1.25k|	sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
  276|  1.25k|	sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
  277|       |
  278|       |	/* Some signature algorithms will not have any data */
  279|  1.25k|	if (buflen == 0 || buf == NULL)
  ------------------
  |  Branch (279:6): [True: 35, False: 1.21k]
  |  Branch (279:21): [True: 0, False: 1.21k]
  ------------------
  280|     35|		return 0;
  281|       |
  282|  1.21k|	r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
  283|       |	/* r = index in asn1_ec_params */
  284|  1.21k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
  ------------------
  |  |   70|  1.21k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|  1.21k|	if (r < 0)
  ------------------
  |  Branch (285:6): [True: 32, False: 1.18k]
  ------------------
  286|     32|		return r;
  287|       |
  288|  1.18k|	ecp = calloc(1, sizeof(struct sc_ec_parameters));
  289|  1.18k|	if (ecp == NULL)
  ------------------
  |  Branch (289:6): [True: 0, False: 1.18k]
  ------------------
  290|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  291|       |
  292|  1.18k|	if (r <= 1) {
  ------------------
  |  Branch (292:6): [True: 1.18k, False: 0]
  ------------------
  293|  1.18k|		ecp->der.value = malloc(buflen);
  294|  1.18k|		if (ecp->der.value == NULL) {
  ------------------
  |  Branch (294:7): [True: 0, False: 1.18k]
  ------------------
  295|      0|			free(ecp);
  296|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  297|      0|		}
  298|  1.18k|		ecp->der.len = buflen;
  299|  1.18k|		memcpy(ecp->der.value, buf, buflen);
  300|  1.18k|	}
  301|      0|	else    {
  302|      0|		r = 0;
  303|      0|	}
  304|       |
  305|  1.18k|	ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
  306|  1.18k|	*paramp = ecp;
  307|  1.18k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.18k|#define SC_SUCCESS				0
  ------------------
  308|  1.18k|};
pkcs15-algo.c:asn1_encode_ec_params:
  313|  1.03k|{
  314|  1.03k|	 struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  315|       |
  316|       |	/* Only handle named curves. They may be absent too */
  317|  1.03k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
  ------------------
  |  |   70|  1.03k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|  1.03k|	*buf = NULL;
  319|  1.03k|	*buflen = 0;
  320|  1.03k|	if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
  ------------------
  |  Branch (320:6): [True: 1.03k, False: 0]
  |  Branch (320:13): [True: 1.03k, False: 0]
  |  Branch (320:31): [True: 1.03k, False: 0]
  ------------------
  321|  1.03k|		*buf = malloc(ecp->der.len);
  322|  1.03k|		if (*buf == NULL)
  ------------------
  |  Branch (322:7): [True: 0, False: 1.03k]
  ------------------
  323|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  324|       |
  325|  1.03k|		memcpy(*buf, ecp->der.value, ecp->der.len);
  326|  1.03k|		*buflen = ecp->der.len;
  327|  1.03k|	}
  328|      0|	else   {
  329|      0|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Not named curve");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  330|      0|	}
  331|       |
  332|  1.03k|	return 0;
  333|  1.03k|}
pkcs15-algo.c:asn1_free_ec_params:
  337|  2.22k|{
  338|  2.22k|	struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  339|       |
  340|  2.22k|	if (ecp) {
  ------------------
  |  Branch (340:6): [True: 2.22k, False: 0]
  ------------------
  341|  2.22k|		if (ecp->der.value)
  ------------------
  |  Branch (341:7): [True: 2.22k, False: 0]
  ------------------
  342|  2.22k|			free(ecp->der.value);
  343|  2.22k|		if (ecp->named_curve)
  ------------------
  |  Branch (343:7): [True: 0, False: 2.22k]
  ------------------
  344|      0|			free(ecp->named_curve);
  345|  2.22k|		free(ecp);
  346|  2.22k|	}
  347|  2.22k|}

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

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

sc_pkcs15emu_cardos_init_ex:
  173|  7.95k|{
  174|  7.95k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (174:6): [True: 7.57k, False: 372]
  ------------------
  175|  7.57k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.57k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  176|       |
  177|    372|	return sc_pkcs15emu_cardos_init(p15card, aid);
  178|  7.95k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  139|  7.95k|{
  140|  7.95k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (140:6): [True: 261, False: 7.69k]
  ------------------
  141|    261|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    261|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|       |
  143|  7.69k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (143:6): [True: 7.31k, False: 372]
  ------------------
  144|  7.31k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.31k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  145|       |
  146|    372|	return SC_SUCCESS;
  ------------------
  |  |   28|    372|#define SC_SUCCESS				0
  ------------------
  147|  7.69k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  152|    372|{
  153|    372|	sc_card_t *card = p15card->card;
  154|    372|	int r;
  155|       |
  156|    372|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    372|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    372|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    372|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    372|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 372]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|       |
  158|    372|	r = sc_pkcs15_bind_internal(p15card, aid);
  159|    372|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal failed");
  ------------------
  |  |  174|    372|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    372|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    372|	int _ret = (r); \
  |  |  |  |  168|    372|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 365, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|    372|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|       |	/* If card has created algorithms, return  */
  162|      7|	sc_log(card->ctx, " card->algorithms:%p card->algorithm_count:%d", card->algorithms, card->algorithm_count);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  163|      7|	if (!card->algorithms && card->algorithm_count == 0) {
  ------------------
  |  Branch (163:6): [True: 6, False: 1]
  |  Branch (163:27): [True: 6, False: 0]
  ------------------
  164|      6|		r = cardos_fix_token_info(p15card);
  165|      6|	}
  166|       |
  167|      7|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|      7|}
pkcs15-cardos.c:cardos_fix_token_info:
   43|      6|{
   44|      6|	sc_card_t *card;
   45|      6|	struct sc_supported_algo_info (*saa)[SC_MAX_SUPPORTED_ALGORITHMS];
   46|      6|	struct sc_supported_algo_info *sa;
   47|      6|	struct sc_cardctl_cardos_pass_algo_flags *passed = NULL;
   48|      6|	int r = 0;
   49|      6|	int i;
   50|       |
   51|      6|	card = p15card->card;
   52|       |
   53|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
   54|       |
   55|      6|	passed = calloc(1, sizeof(struct sc_cardctl_cardos_pass_algo_flags));
   56|      6|	if (!passed)
  ------------------
  |  Branch (56:6): [True: 0, False: 6]
  ------------------
   57|      6|		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|      6|	passed->pass = 1; /* get used_flags and card_flags from card */
   60|      6|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
   61|      6|	if (r < 0) {
  ------------------
  |  Branch (61:6): [True: 0, False: 6]
  ------------------
   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|      6|	saa = &(p15card->tokeninfo->supported_algos);
   67|       |
   68|      6|	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|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   69|       |
   70|      6|	if (passed->card_flags) { /* user forced the flags, use them */
  ------------------
  |  Branch (70:6): [True: 0, False: 6]
  ------------------
   71|      0|		passed->new_flags = passed->card_flags; /* from card_atr flags */
   72|      6|	} else {
   73|       |
   74|      6|		for (i = 0, sa = saa[0]; i < SC_MAX_SUPPORTED_ALGORITHMS; i++, sa++) {
  ------------------
  |  |   61|      6|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (74:28): [True: 6, False: 0]
  ------------------
   75|       |
   76|      6|			if (sa->reference == 0 && sa->mechanism == 0
  ------------------
  |  Branch (76:8): [True: 6, False: 0]
  |  Branch (76:30): [True: 6, False: 0]
  ------------------
   77|      6|					&& sa->operations == 0 && sa->algo_ref == 0)
  ------------------
  |  Branch (77:9): [True: 6, False: 0]
  |  Branch (77:32): [True: 6, False: 0]
  ------------------
   78|      6|				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|      6|		if (passed->new_flags == 0) {
  ------------------
  |  Branch (118:7): [True: 6, False: 0]
  ------------------
  119|      6|			if (p15card->tokeninfo && p15card->tokeninfo->flags & SC_PKCS15_TOKEN_EID_COMPLIANT) {
  ------------------
  |  |  598|      6|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  |  Branch (119:8): [True: 6, False: 0]
  |  Branch (119:30): [True: 1, False: 5]
  ------------------
  120|      1|				sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "EID_COMPLIANT flag found");
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  121|      1|				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |   96|      1|#define SC_ALGORITHM_SPECIFIC_FLAGS	0x001FFFFF
  ------------------
              				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  122|      1|				passed->new_flags |= (passed->used_flags & SC_ALGORITHM_RSA_PAD_PSS);
  ------------------
  |  |  107|      1|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  123|      1|			} else
  124|      5|				passed->new_flags = passed->used_flags; /* from default cardos_init */
  125|      6|		}
  126|      6|	}
  127|       |
  128|      6|	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|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|       |
  130|      6|	passed->pass = 2; /* tell card driver to use the new flags */
  131|      6|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
  132|       |
  133|      6|	free(passed);
  134|      6|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|      6|}

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

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

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

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

sc_pkcs15_read_data_object:
   46|     96|{
   47|     96|	struct sc_context *ctx = p15card->card->ctx;
   48|     96|	struct sc_pkcs15_data *data_object;
   49|     96|	struct sc_pkcs15_der der;
   50|     96|	int r;
   51|       |
   52|     96|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|     96|	if (!info || !data_object_out)
  ------------------
  |  Branch (53:6): [True: 0, False: 96]
  |  Branch (53:15): [True: 0, False: 96]
  ------------------
   54|     96|		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|     96|	if (!info->data.value)   {
  ------------------
  |  Branch (56:6): [True: 96, False: 0]
  ------------------
   57|     96|		r = sc_pkcs15_read_file(p15card, &info->path, (unsigned char **) &info->data.value, (size_t *) &info->data.len, private_obj);
   58|     96|		LOG_TEST_RET(ctx, r, "Cannot get DATA object data");
  ------------------
  |  |  174|     96|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     96|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     96|	int _ret = (r); \
  |  |  |  |  168|     96|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 43, False: 53]
  |  |  |  |  ------------------
  |  |  |  |  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|     96|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 53]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|     96|	}
   60|       |
   61|     53|	r = sc_der_copy(&der, &info->data);
   62|     53|	LOG_TEST_RET(ctx, r, "Cannot allocate memory for der value");
  ------------------
  |  |  174|     53|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     53|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     53|	int _ret = (r); \
  |  |  |  |  168|     53|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 53]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     53|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 53]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|       |
   64|     53|	data_object = calloc(1, sizeof(struct sc_pkcs15_data));
   65|     53|	if (!data_object)   {
  ------------------
  |  Branch (65:6): [True: 0, False: 53]
  ------------------
   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|     53|	data_object->data = der.value;
   71|     53|	data_object->data_len = der.len;
   72|     53|	*data_object_out = data_object;
   73|       |
   74|     53|	LOG_FUNC_RETURN(ctx,SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 53]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|     53|}
sc_pkcs15_free_data_object:
  180|     53|{
  181|     53|	if (data_object == NULL)
  ------------------
  |  Branch (181:6): [True: 0, False: 53]
  ------------------
  182|      0|		return;
  183|       |
  184|     53|	free(data_object->data);
  185|     53|	free(data_object);
  186|     53|}
sc_pkcs15_free_data_info:
  189|  26.2k|{
  190|  26.2k|	if (info && info->data.value)
  ------------------
  |  Branch (190:6): [True: 26.2k, False: 0]
  |  Branch (190:14): [True: 0, False: 26.2k]
  ------------------
  191|      0|		free(info->data.value);
  192|       |
  193|  26.2k|	free(info);
  194|  26.2k|}

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

sc_pkcs15emu_dnie_init_ex:
  281|  10.3k|{
  282|  10.3k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  10.3k|#define SC_SUCCESS				0
  ------------------
  283|  10.3k|	sc_context_t *ctx = p15card->card->ctx;
  284|  10.3k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  10.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  10.3k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  10.3k|	r = dnie_match_card(p15card->card);
  289|  10.3k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 9.87k, False: 506]
  ------------------
  290|  10.3k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  9.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.87k|	int _ret = r; \
  |  |  |  |  155|  9.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  9.87k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.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|  9.87k|	return _ret; \
  |  |  |  |  163|  9.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    506|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  164|    506|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    506|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    506|	int _ret = r; \
  |  |  |  |  155|    506|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 506, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    506|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    506|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 506, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    506|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    506|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    506|	return _ret; \
  |  |  |  |  163|    506|} 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|    506|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    506|{
  140|    506|	u8 buf[1024];
  141|    506|	sc_pkcs15_df_t *df;
  142|    506|	sc_pkcs15_object_t *p15_obj;
  143|    506|	size_t len = sizeof(buf);
  144|    506|	int rv;
  145|    506|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    506|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    506|	sc_context_t *ctx = p15card->card->ctx;
  149|    506|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    506|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    506|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    506|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    506|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 506]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    506|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 2, False: 504]
  ------------------
  153|      2|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      2|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    504|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 504]
  ------------------
  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|    504|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    504|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 437, False: 67]
  ------------------
  163|    437|		p15card->opts.use_pin_cache = 1;
  164|    437|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|    437|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|    437|		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|    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__
  |  |  ------------------
  ------------------
  166|    437|			p15card->opts.use_file_cache,
  167|    437|			p15card->opts.use_pin_cache,
  168|    437|			p15card->opts.pin_cache_counter,
  169|    437|			p15card->opts.pin_cache_ignore_user_consent);
  170|    437|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    504|	sc_file_free(p15card->file_app);
  174|    504|	p15card->file_app = sc_file_new();
  175|    504|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 504]
  ------------------
  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|    504|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    504|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    504|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    504|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    504|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    504|	int _ret = (r); \
  |  |  |  |  178|    504|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 471, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  179|    471|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    471|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    471|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    471|		goto err; \
  |  |  |  |  182|    471|	} \
  |  |  |  |  183|    504|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 33]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|     33|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  186|     33|				       buf, len);
  187|     33|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of EF.TOKENINFO failed.");
  ------------------
  |  |  184|     33|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     33|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     33|	int _ret = (r); \
  |  |  |  |  178|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 32, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  179|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     32|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     32|		goto err; \
  |  |  |  |  182|     32|	} \
  |  |  |  |  183|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* Only accept the original stuff */
  190|      1|	if (strcmp(p15card->tokeninfo->manufacturer_id, "DGP-FNMT") != 0) {
  ------------------
  |  Branch (190:6): [True: 1, False: 0]
  ------------------
  191|      1|		rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      1|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  192|      1|		LOG_TEST_GOTO_ERR(ctx, rv, "Wrong card.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|      1|	}
  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|    504|err:
  270|    504|	sc_pkcs15_card_clear(p15card);
  271|    504|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    504|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    504|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    504|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    504|	int _ret = r; \
  |  |  |  |  155|    504|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 504, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    504|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    504|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 504, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    504|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    504|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    504|	return _ret; \
  |  |  |  |  163|    504|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    504|}
pkcs15-dnie.c:dump_ef:
   42|    504|{
   43|    504|	int rv;
   44|    504|	sc_file_t *file = NULL;
   45|    504|	sc_path_t scpath;
   46|    504|	sc_format_path(path, &scpath);
   47|    504|	rv = sc_select_file(card, &scpath, &file);
   48|    504|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 438, False: 66]
  ------------------
   49|    438|		sc_file_free(file);
   50|    438|		return rv;
   51|    438|	}
   52|     66|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 29, False: 37]
  ------------------
   53|     29|		sc_file_free(file);
   54|     29|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     29|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|     29|	}
   56|     37|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   57|     37|	sc_file_free(file);
   58|     37|	if (rv < 0)
  ------------------
  |  Branch (58:6): [True: 4, False: 33]
  ------------------
   59|      4|		return rv;
   60|     33|	*buf_len = rv;
   61|       |
   62|     33|	return SC_SUCCESS;
  ------------------
  |  |   28|     33|#define SC_SUCCESS				0
  ------------------
   63|     37|}

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

sc_pkcs15emu_eoi_init_ex:
   35|  7.72k|{
   36|  7.72k|	struct sc_card *card = p15card->card;
   37|  7.72k|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
   38|  7.72k|	struct sc_pkcs15_search_key sk;
   39|  7.72k|	struct sc_pkcs15_object *objs[MAX_OBJECTS];
   40|  7.72k|	int i, j, len;
   41|       |
   42|  7.72k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.72k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.72k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.72k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.72k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.72k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   43|       |
   44|  7.72k|	if (card->type != SC_CARD_TYPE_EOI && card->type != SC_CARD_TYPE_EOI_CONTACTLESS)
  ------------------
  |  Branch (44:6): [True: 7.71k, False: 8]
  |  Branch (44:40): [True: 7.71k, False: 0]
  ------------------
   45|  7.72k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  7.71k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.71k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.71k|	int _ret = r; \
  |  |  |  |  155|  7.71k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.71k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.71k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.71k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.71k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.71k|	} else { \
  |  |  |  |  159|      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.71k|	return _ret; \
  |  |  |  |  163|  7.71k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   46|       |
   47|      8|	if (!privdata)
  ------------------
  |  Branch (47:6): [True: 0, False: 8]
  ------------------
   48|      8|		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|      8|	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: 8]
  |  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|      8|	LOG_TEST_RET(card->ctx, sc_pkcs15_bind_internal(p15card, aid),
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   64|      1|		"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|      1|	memset(&sk, 0, sizeof(sk));
   72|      1|	sk.class_mask = SC_PKCS15_SEARCH_CLASS_AUTH;
  ------------------
  |  |  455|      1|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
   73|      1|	len = sc_pkcs15_search_objects(p15card, &sk, (struct sc_pkcs15_object **)&objs, MAX_OBJECTS);
  ------------------
  |  |   24|      1|#define MAX_OBJECTS 8
  ------------------
   74|      1|	for (i = 0, j = 0; i < len; i++) {
  ------------------
  |  Branch (74:21): [True: 0, False: 1]
  ------------------
   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|      1|	memset(&sk, 0, sizeof(sk));
  116|      1|	sk.class_mask = SC_PKCS15_SEARCH_CLASS_PRKEY;
  ------------------
  |  |  450|      1|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  117|      1|	len = sc_pkcs15_search_objects(p15card, &sk, (struct sc_pkcs15_object **)&objs, MAX_OBJECTS);
  ------------------
  |  |   24|      1|#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|      1|	for (j = 0; j < MAX_OBJECTS && privdata->prkey_mappings[j][1] != 0; j++) {
  ------------------
  |  |   24|      2|#define MAX_OBJECTS 8
  ------------------
  |  Branch (122:14): [True: 1, False: 0]
  |  Branch (122:33): [True: 0, False: 1]
  ------------------
  123|       |		/* NOP */
  124|      0|	}
  125|      1|	for (i = 0; i < len; i++) {
  ------------------
  |  Branch (125:14): [True: 0, False: 1]
  ------------------
  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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  137|      1|}

sc_pkcs15emu_entersafe_init_ex:
   79|  10.6k|{
   80|  10.6k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.6k]
  |  |  ------------------
  ------------------
   81|       |
   82|  10.6k|	if (entersafe_detect_card(p15card))
  ------------------
  |  Branch (82:6): [True: 10.5k, False: 159]
  ------------------
   83|  10.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   84|    159|	return sc_pkcs15emu_entersafe_init(p15card);
   85|  10.6k|}
pkcs15-esinit.c:entersafe_detect_card:
   33|  10.6k|{
   34|  10.6k|	sc_card_t *card = p15card->card;
   35|       |
   36|  10.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.6k]
  |  |  ------------------
  ------------------
   37|       |
   38|       |	/* check if we have the correct card OS */
   39|  10.6k|	if (strcmp(card->name, "entersafe"))
  ------------------
  |  Branch (39:6): [True: 10.5k, False: 159]
  ------------------
   40|  10.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   41|       |
   42|    159|    return SC_SUCCESS;
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
   43|  10.6k|}
pkcs15-esinit.c:sc_pkcs15emu_entersafe_init:
   46|    159|{
   47|    159|	int    r;
   48|    159|	char   buf[256];
   49|    159|	sc_card_t *card = p15card->card;
   50|    159|	sc_serial_number_t serial;
   51|       |
   52|    159|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    159|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    159|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    159|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 159]
  |  |  ------------------
  ------------------
   53|       |
   54|       |	/* get serial number */
   55|    159|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   56|    159|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:6): [True: 156, False: 3]
  ------------------
   57|    156|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    156|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|      3|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
   59|      3|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (59:6): [True: 0, False: 3]
  ------------------
   60|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   61|       |
   62|      3|	set_string(&p15card->tokeninfo->serial_number, buf);
   63|      3|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (63:6): [True: 0, False: 3]
  ------------------
   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|      3|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   30|      3|#define MANU_ID		"entersafe"
  ------------------
   68|      3|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (68:6): [True: 0, False: 3]
  ------------------
   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|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
   75|      3|}

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

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

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

sc_pkcs15emu_gids_init_ex:
  241|  10.3k|{
  242|  10.3k|	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: 10.2k, False: 120]
  |  Branch (242:58): [True: 10.2k, False: 1]
  |  Branch (242:105): [True: 10.2k, False: 1]
  ------------------
  243|  10.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  244|  10.2k|	}
  245|    122|	return sc_pkcs15emu_gids_init(p15card);
  246|  10.3k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  112|    122|{
  113|    122|	sc_card_t *card = p15card->card;
  114|    122|	int r;
  115|    122|	size_t i;
  116|    122|	struct sc_pkcs15_auth_info pin_info;
  117|    122|	struct sc_pkcs15_object pin_obj;
  118|    122|	struct sc_pin_cmd_data pin_cmd_data;
  119|    122|	size_t recordsnum;
  120|    122|	int has_puk;
  121|       |
  122|    122|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  123|    122|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  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: 122, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    122|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    122|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    122|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    122|		return _ret; \
  |  |  |  |  172|    122|	} \
  |  |  |  |  173|    122|} 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|  10.2k|{
  269|  10.2k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (269:6): [True: 9.66k, False: 636]
  ------------------
  270|  9.66k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.66k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  271|       |
  272|    636|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  273|  10.2k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  239|  10.2k|{
  240|  10.2k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (240:6): [True: 7.25k, False: 3.04k]
  ------------------
  241|  7.25k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.25k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  242|       |
  243|  3.04k|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (243:6): [True: 2.40k, False: 636]
  ------------------
  244|  2.40k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  2.40k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  245|       |
  246|    636|	return SC_SUCCESS;
  ------------------
  |  |   28|    636|#define SC_SUCCESS				0
  ------------------
  247|  3.04k|}
pkcs15-iasecc.c:sc_pkcs15emu_iasecc_init:
  252|    636|{
  253|    636|	struct sc_context *ctx = p15card->card->ctx;
  254|    636|	int rv;
  255|       |
  256|    636|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    636|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    636|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    636|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    636|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 636]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|       |
  258|    636|	rv = sc_pkcs15_bind_internal(p15card, aid);
  259|       |
  260|    636|	p15card->ops.parse_df = _iasecc_parse_df;
  261|       |
  262|    636|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    636|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    636|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    636|	int _ret = r; \
  |  |  |  |  155|    636|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 636, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    636|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|    636|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    636|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    636|	return _ret; \
  |  |  |  |  163|    636|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|    636|}

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

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

sc_pkcs15emu_nqapplet_init_ex:
  179|  7.94k|{
  180|  7.94k|	int rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.94k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  181|  7.94k|	sc_context_t *ctx;
  182|  7.94k|	sc_card_t *card;
  183|       |
  184|  7.94k|	if (!p15card || !p15card->card || !p15card->card->ctx) {
  ------------------
  |  Branch (184:6): [True: 0, False: 7.94k]
  |  Branch (184:18): [True: 0, False: 7.94k]
  |  Branch (184:36): [True: 0, False: 7.94k]
  ------------------
  185|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  186|      0|	}
  187|       |
  188|  7.94k|	card = p15card->card;
  189|  7.94k|	ctx = card->ctx;
  190|       |
  191|  7.94k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  7.94k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.94k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.94k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.94k]
  |  |  ------------------
  ------------------
  192|       |
  193|  7.94k|	if (card->type < SC_CARD_TYPE_NQ_APPLET || card->type > SC_CARD_TYPE_NQ_APPLET_RFID) {
  ------------------
  |  Branch (193:6): [True: 7.53k, False: 408]
  |  Branch (193:45): [True: 223, False: 185]
  ------------------
  194|  7.75k|		sc_log(p15card->card->ctx, "Unsupported card type: %d", card->type);
  ------------------
  |  |   71|  7.75k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  195|  7.75k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.75k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  196|  7.75k|	}
  197|       |
  198|    185|	rv = add_nqapplet_objects(p15card);
  199|    185|	LOG_TEST_GOTO_ERR(ctx, rv, "Failed to add PKCS15");
  ------------------
  |  |  184|    185|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    185|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    185|	int _ret = (r); \
  |  |  |  |  178|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 26, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     26|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     26|		goto err; \
  |  |  |  |  182|     26|	} \
  |  |  |  |  183|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|       |
  201|    159|	if (aid != NULL) {
  ------------------
  |  Branch (201:6): [True: 0, False: 159]
  ------------------
  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|    159|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  212|       |
  213|    159|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  214|    159|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (214:6): [True: 0, False: 159]
  ------------------
  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|    159|	} else {
  218|    159|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  219|       |
  220|    159|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial_hex, sizeof(serial_hex), 0);
  221|    159|		set_string(&p15card->tokeninfo->serial_number, serial_hex);
  222|    159|		set_string(&p15card->tokeninfo->label, name_Card);
  223|    159|		set_string(&p15card->tokeninfo->manufacturer_id, name_Vendor);
  224|    159|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|    159|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  225|    159|	}
  226|       |
  227|    159|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    159|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    159|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    159|	int _ret = r; \
  |  |  |  |  155|    159|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    159|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  157|    159|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    159|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    159|	return _ret; \
  |  |  |  |  163|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  228|     26|err:
  229|     26|	sc_pkcs15_card_clear(p15card);
  230|     26|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     26|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     26|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     26|	int _ret = r; \
  |  |  |  |  155|     26|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     26|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     26|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|     26|}
pkcs15-nqApplet.c:add_nqapplet_objects:
  146|    185|{
  147|    185|	int rv;
  148|    185|	sc_card_t *card = p15card->card;
  149|       |
  150|    185|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    185|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    185|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    185|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    185|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  151|       |
  152|       |	// 1) User PIN
  153|    185|	rv = add_nqapplet_pin(p15card, "1", 0x01);
  154|    185|	LOG_TEST_RET(card->ctx, rv, "Failed to add PIN 1");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	// 2.1) C.CH.Auth
  157|    185|	rv = add_nqapplet_certificate(p15card, "1", "C.CH.Auth", 0x00);
  158|    185|	LOG_TEST_RET(card->ctx, rv, "Failed to add Auth. certificate");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  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|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|       |
  160|       |	// 2.2) PrK.CH.Auth
  161|    159|	rv = add_nqapplet_private_key(p15card, "1", 0x01, "PrK.CH.Auth", "1",
  162|    159|	                              SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DECRYPT);
  ------------------
  |  |  307|    159|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	                              SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_DECRYPT);
  ------------------
  |  |  306|    159|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  163|    159|	LOG_TEST_RET(card->ctx, rv, "Failed to add Auth. private key");
  ------------------
  |  |  174|    159|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    159|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    159|	int _ret = (r); \
  |  |  |  |  168|    159|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|       |	// 3.1) C.CH.Encr
  166|    159|	rv = add_nqapplet_certificate(p15card, "2", "C.CH.Encr", 0x01);
  167|    159|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    159|#define SC_SUCCESS				0
  ------------------
  |  Branch (167:6): [True: 69, False: 90]
  ------------------
  168|       |		// 3.2) PrK.CH.Encr
  169|     69|		rv = add_nqapplet_private_key(p15card, "2", 0x02, "PrK.CH.Encr", "1", SC_PKCS15_PRKEY_USAGE_DECRYPT);
  ------------------
  |  |  306|     69|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  170|     69|		LOG_TEST_RET(card->ctx, rv, "Failed to add Encr. private key");
  ------------------
  |  |  174|     69|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     69|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     69|	int _ret = (r); \
  |  |  |  |  168|     69|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 69]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 69]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  171|     90|	} else {
  172|     90|		sc_log(p15card->card->ctx, "The card has no C.CH.Encr, ignoring CH.Encr container");
  ------------------
  |  |   71|     90|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  173|     90|	}
  174|       |
  175|    159|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    159|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    159|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    159|	int _ret = r; \
  |  |  |  |  155|    159|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    159|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  157|    159|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    159|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    159|	return _ret; \
  |  |  |  |  163|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|    159|}
pkcs15-nqApplet.c:add_nqapplet_pin:
   59|    185|{
   60|    185|	int rv;
   61|    185|	struct sc_pkcs15_auth_info pin_info;
   62|    185|	struct sc_pkcs15_object pin_obj;
   63|    185|	sc_card_t *card = p15card->card;
   64|       |
   65|    185|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    185|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    185|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    185|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    185|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   66|       |
   67|    185|	memset(&pin_info, 0, sizeof(pin_info));
   68|    185|	memset(&pin_obj, 0, sizeof(pin_obj));
   69|       |
   70|    185|	sc_pkcs15_format_id(id, &pin_info.auth_id);
   71|    185|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    185|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
   72|    185|	pin_info.attrs.pin.reference = reference;
   73|    185|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_CASE_SENSITIVE |
  ------------------
  |  |   58|    185|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_CASE_SENSITIVE |
  ------------------
  |  |   54|    185|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
   74|    185|	                           SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   75|    185|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  ------------------
  |  |  |  |   58|    185|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  ------------------
              	                           SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    185|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
   75|    185|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_UTF8;
  ------------------
  |  |   90|    185|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
   76|    185|	pin_info.attrs.pin.min_length = 6;
   77|    185|	pin_info.attrs.pin.stored_length = 6;
   78|    185|	pin_info.attrs.pin.max_length = 6;
   79|    185|	pin_info.attrs.pin.pad_char = '\0';
   80|    185|	pin_info.tries_left = -1; // TODO
   81|    185|	pin_info.max_tries = 3;
   82|       |
   83|    185|	strlcpy(pin_obj.label, "UserPIN", sizeof(pin_obj.label));
  ------------------
  |  |   43|    185|#define strlcpy _strlcpy
  ------------------
   84|    185|	pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    185|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              	pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    185|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   85|       |
   86|    185|	rv = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
   87|    185|	LOG_TEST_RET(card->ctx, rv, "sc_pkcs15emu_add_pin_obj failed");
  ------------------
  |  |  174|    185|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    185|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    185|	int _ret = (r); \
  |  |  |  |  168|    185|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|       |
   89|    185|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    185|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    185|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    185|	int _ret = r; \
  |  |  |  |  155|    185|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 185, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    185|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  157|    185|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    185|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    185|	return _ret; \
  |  |  |  |  163|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|    185|}
pkcs15-nqApplet.c:add_nqapplet_certificate:
   93|    344|{
   94|    344|	int rv;
   95|    344|	struct sc_pkcs15_cert_info cert_info;
   96|    344|	struct sc_pkcs15_object cert_obj;
   97|    344|	sc_card_t *card = p15card->card;
   98|       |
   99|    344|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    344|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    344|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    344|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    344|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 344]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  100|       |
  101|    344|	memset(&cert_info, 0, sizeof(cert_info));
  102|    344|	memset(&cert_obj, 0, sizeof(cert_obj));
  103|       |
  104|    344|	sc_pkcs15_format_id(id, &cert_info.id);
  105|    344|	rv = get_nqapplet_certificate(card, data_id, &cert_info.value);
  106|    344|	LOG_TEST_RET(card->ctx, rv, "Failed to get certificate");
  ------------------
  |  |  174|    344|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    344|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    344|	int _ret = (r); \
  |  |  |  |  168|    344|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 116, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  169|    116|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    116|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    116|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    116|		return _ret; \
  |  |  |  |  172|    116|	} \
  |  |  |  |  173|    344|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|    228|	strlcpy(cert_obj.label, name, sizeof(cert_obj.label));
  ------------------
  |  |   43|    228|#define strlcpy _strlcpy
  ------------------
  109|       |
  110|    228|	rv = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  111|    228|	LOG_TEST_RET(card->ctx, rv, "sc_pkcs15emu_add_x509_cert failed");
  ------------------
  |  |  174|    228|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    228|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    228|	int _ret = (r); \
  |  |  |  |  168|    228|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  112|       |
  113|    228|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    228|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    228|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    228|	int _ret = r; \
  |  |  |  |  155|    228|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 228, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    228|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  157|    228|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    228|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    228|	return _ret; \
  |  |  |  |  163|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|    228|}
pkcs15-nqApplet.c:get_nqapplet_certificate:
   35|    344|{
   36|    344|	int rv;
   37|    344|	u8 buffer[3072];
   38|    344|	size_t cb_buffer = sizeof(buffer);
   39|    344|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    344|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    344|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    344|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    344|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 344]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   40|       |
   41|    344|	rv = sc_get_data(card, data_id, buffer, cb_buffer);
   42|    344|	LOG_TEST_RET(card->ctx, rv, "GET DATA failed");
  ------------------
  |  |  174|    344|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    344|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    344|	int _ret = (r); \
  |  |  |  |  168|    344|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 330]
  |  |  |  |  ------------------
  |  |  |  |  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|    344|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 330]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   43|    330|	if (rv == 0) {
  ------------------
  |  Branch (43:6): [True: 102, False: 228]
  ------------------
   44|    102|		LOG_TEST_RET(card->ctx, SC_ERROR_FILE_NOT_FOUND, "No certificate data returned");
  ------------------
  |  |  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: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    102|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    102|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    102|		return _ret; \
  |  |  |  |  172|    102|	} \
  |  |  |  |  173|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   45|    102|	}
   46|       |
   47|    228|	if (cert_info != NULL) {
  ------------------
  |  Branch (47:6): [True: 228, False: 0]
  ------------------
   48|    228|		free(cert_info->value);
   49|    228|		cert_info->value = malloc(rv);
   50|    228|		if (cert_info->value != NULL) {
  ------------------
  |  Branch (50:7): [True: 228, False: 0]
  ------------------
   51|    228|			cert_info->len = rv;
   52|    228|			memcpy(cert_info->value, buffer, rv);
   53|    228|		}
   54|    228|	}
   55|    228|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    228|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    228|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    228|	int _ret = r; \
  |  |  |  |  155|    228|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 228, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    228|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  157|    228|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    228|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    228|	return _ret; \
  |  |  |  |  163|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   56|    228|}
pkcs15-nqApplet.c:add_nqapplet_private_key:
  118|    228|{
  119|    228|	int rv;
  120|    228|	struct sc_pkcs15_prkey_info prkey_info;
  121|    228|	struct sc_pkcs15_object prkey_obj;
  122|    228|	sc_card_t *card = p15card->card;
  123|       |
  124|    228|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    228|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    228|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    228|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    228|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  125|       |
  126|    228|	memset(&prkey_info, 0, sizeof(prkey_info));
  127|    228|	memset(&prkey_obj, 0, sizeof(prkey_obj));
  128|       |
  129|    228|	sc_pkcs15_format_id(id, &prkey_info.id);
  130|    228|	prkey_info.usage = usage;
  131|    228|	prkey_info.native = 1;
  132|    228|	prkey_info.key_reference = reference;
  133|    228|	prkey_info.modulus_length = 3072;
  134|       |
  135|    228|	strlcpy(prkey_obj.label, name, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    228|#define strlcpy _strlcpy
  ------------------
  136|    228|	prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    228|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  137|    228|	sc_pkcs15_format_id(pin_id, &prkey_obj.auth_id);
  138|       |
  139|    228|	rv = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  140|    228|	LOG_TEST_RET(card->ctx, rv, "sc_pkcs15emu_add_rsa_prkey failed");
  ------------------
  |  |  174|    228|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    228|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    228|	int _ret = (r); \
  |  |  |  |  168|    228|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|    228|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    228|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    228|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    228|	int _ret = r; \
  |  |  |  |  155|    228|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 228, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    228|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  157|    228|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    228|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    228|	return _ret; \
  |  |  |  |  163|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  143|    228|}

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

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

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

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

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

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

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

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

sc_pkcs15_decipher:
  283|   175k|{
  284|   175k|	sc_context_t *ctx = p15card->card->ctx;
  285|   175k|	int r;
  286|   175k|	sc_algorithm_info_t *alg_info = NULL;
  287|   175k|	sc_security_env_t senv;
  288|   175k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  289|   175k|	unsigned long pad_flags = 0, sec_flags = 0;
  290|       |
  291|   175k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   175k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   175k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   175k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   175k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 175k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|   175k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|   175k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|   175k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (293:6): [True: 106k, False: 68.7k]
  ------------------
  294|   175k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for decryption");
  ------------------
  |  |  174|   106k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   106k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   106k|	int _ret = (r); \
  |  |  |  |  168|   106k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 106k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   106k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   106k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   106k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   106k|		return _ret; \
  |  |  |  |  172|   106k|	} \
  |  |  |  |  173|   106k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|       |
  296|  68.7k|	r = format_senv(p15card, obj, &senv, &alg_info);
  297|  68.7k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  68.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  68.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  68.7k|	int _ret = (r); \
  |  |  |  |  168|  68.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 59.1k, False: 9.67k]
  |  |  |  |  ------------------
  |  |  |  |  169|  59.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  59.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  59.1k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  59.1k|		return _ret; \
  |  |  |  |  172|  59.1k|	} \
  |  |  |  |  173|  68.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9.67k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|  9.67k|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|  9.67k|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  299|       |
  300|  9.67k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  301|  9.67k|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|  9.67k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.67k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.67k|	int _ret = (r); \
  |  |  |  |  168|  9.67k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.91k, False: 4.75k]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.91k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.91k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.91k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.91k|		return _ret; \
  |  |  |  |  172|  4.91k|	} \
  |  |  |  |  173|  9.67k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.75k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|  4.75k|	senv.algorithm_flags = sec_flags;
  303|       |
  304|  4.75k|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  305|  4.75k|			outlen);
  306|  4.75k|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|  4.75k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.75k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.75k|	int _ret = (r); \
  |  |  |  |  168|  4.75k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.23k, False: 521]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.23k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.23k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.23k|		return _ret; \
  |  |  |  |  172|  4.23k|	} \
  |  |  |  |  173|  4.75k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 521]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Strip any padding */
  309|    521|	if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  110|    521|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (309:6): [True: 228, False: 293]
  ------------------
  310|    228|		unsigned int s = r;
  311|    228|		unsigned int key_size = (unsigned int)alg_info->key_length;
  312|    228|		r = sc_pkcs1_strip_02_padding_constant_time(ctx, key_size / 8, out, s, out, &s);
  313|       |		/* for keeping PKCS#1 v1.5 depadding constant-time, do not log error here */
  314|    228|	}
  315|    293|#ifdef ENABLE_OPENSSL
  316|    293|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|    293|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (316:11): [True: 0, False: 293]
  ------------------
  317|      0|		size_t s = r;
  318|      0|		uint8_t *param = NULL;
  319|      0|		size_t paramlen = 0;
  320|      0|		if (pMechanism != NULL) {
  ------------------
  |  Branch (320:7): [True: 0, False: 0]
  ------------------
  321|      0|			CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
  322|      0|			if (mech->pParameter && sizeof(CK_RSA_PKCS_OAEP_PARAMS) == mech->ulParameterLen) {
  ------------------
  |  Branch (322:8): [True: 0, False: 0]
  |  Branch (322:28): [True: 0, False: 0]
  ------------------
  323|      0|				CK_RSA_PKCS_OAEP_PARAMS * oaep_params = mech->pParameter;
  324|      0|				if (oaep_params->source == CKZ_DATA_SPECIFIED) {
  ------------------
  |  | 1227|      0|#define CKZ_DATA_SPECIFIED 0x00000001UL
  ------------------
  |  Branch (324:9): [True: 0, False: 0]
  ------------------
  325|      0|					param = oaep_params->pSourceData;
  326|      0|					paramlen = (size_t)oaep_params->ulSourceDataLen;
  327|      0|				}
  328|      0|			}
  329|      0|		}
  330|      0|		r = sc_pkcs1_strip_oaep_padding(ctx, out, s, flags, param, paramlen);
  331|      0|		LOG_TEST_RET(ctx, r, "Invalid OAEP padding");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  332|      0|	}
  333|    521|#endif
  334|       |	/* do not log error code to prevent side channel attack */
  335|    521|	return r;
  336|    521|}
sc_pkcs15_derive:
  349|  43.8k|{
  350|  43.8k|	sc_context_t *ctx = p15card->card->ctx;
  351|  43.8k|	int r;
  352|  43.8k|	sc_algorithm_info_t *alg_info = NULL;
  353|  43.8k|	sc_security_env_t senv;
  354|  43.8k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  355|  43.8k|	unsigned long pad_flags = 0, sec_flags = 0;
  356|       |
  357|  43.8k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  43.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  43.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  43.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  43.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 43.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|       |
  359|  43.8k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DERIVE)))
  ------------------
  |  |  313|  43.8k|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  |  Branch (359:6): [True: 24.4k, False: 19.3k]
  ------------------
  360|  43.8k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for derivation");
  ------------------
  |  |  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: 24.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  24.4k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  24.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  24.4k|		return _ret; \
  |  |  |  |  172|  24.4k|	} \
  |  |  |  |  173|  24.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|  19.3k|	switch (obj->type) {
  363|    678|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|    678|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (363:3): [True: 678, False: 18.7k]
  ------------------
  364|    678|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|    678|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (364:3): [True: 0, False: 19.3k]
  ------------------
  365|    678|			if (out == NULL || *poutlen < BYTES4BITS(prkey->field_length)) {
  ------------------
  |  |  145|    678|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  |  Branch (365:8): [True: 0, False: 678]
  |  Branch (365:23): [True: 0, False: 678]
  ------------------
  366|      0|				*poutlen = BYTES4BITS(prkey->field_length);
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  367|      0|				r = 0; /* say no data to return */
  368|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  369|      0|			}
  370|    678|			break;
  371|  18.7k|		default:
  ------------------
  |  Branch (371:3): [True: 18.7k, False: 678]
  ------------------
  372|  18.7k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED,"Key type not supported");
  ------------------
  |  |  174|  18.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  18.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  18.7k|	int _ret = (r); \
  |  |  |  |  168|  18.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  18.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  18.7k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  18.7k|		return _ret; \
  |  |  |  |  172|  18.7k|	} \
  |  |  |  |  173|  18.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|  19.3k|	}
  374|       |
  375|    678|	r = format_senv(p15card, obj, &senv, &alg_info);
  376|    678|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    678|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    678|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    678|	int _ret = (r); \
  |  |  |  |  168|    678|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 90, False: 588]
  |  |  |  |  ------------------
  |  |  |  |  169|     90|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     90|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     90|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     90|		return _ret; \
  |  |  |  |  172|     90|	} \
  |  |  |  |  173|    678|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 588]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    588|	senv.operation = SC_SEC_OPERATION_DERIVE;
  ------------------
  |  |   50|    588|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  378|       |
  379|    588|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  380|    588|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    588|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    588|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    588|	int _ret = (r); \
  |  |  |  |  168|    588|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 588]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    588|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 588]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|    588|	senv.algorithm_flags = sec_flags;
  382|       |
  383|    588|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  384|    588|			*poutlen);
  385|    588|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    588|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    588|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    588|	int _ret = (r); \
  |  |  |  |  168|    588|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 556, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  169|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    556|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    556|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    556|		return _ret; \
  |  |  |  |  172|    556|	} \
  |  |  |  |  173|    588|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  386|       |
  387|       |	/* If card stores derived key on card, then no data is returned
  388|       |	 * and the key must be used on the card. */
  389|     32|	*poutlen = r;
  390|     32|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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: 31, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|     32|}
sc_pkcs15_unwrap:
  405|   175k|{
  406|   175k|	sc_context_t *ctx = p15card->card->ctx;
  407|   175k|	int r;
  408|   175k|	sc_algorithm_info_t *alg_info = NULL;
  409|   175k|	sc_security_env_t senv;
  410|   175k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  411|   175k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  412|   175k|	const struct sc_pkcs15_skey_info *tkey = (const struct sc_pkcs15_skey_info *) target_key->data;
  413|   175k|	unsigned long pad_flags = 0, sec_flags = 0;
  414|   175k|	u8 *out = 0;
  415|   175k|	size_t poutlen = 0;
  416|   175k|	sc_path_t path, target_file_id;
  417|   175k|	sc_sec_env_param_t senv_param;
  418|       |
  419|   175k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   175k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   175k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   175k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   175k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 175k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|       |
  421|   175k|	if (key->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|   175k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (421:6): [True: 18.8k, False: 156k]
  ------------------
  422|  18.8k|		if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|  18.8k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (422:7): [True: 14.8k, False: 3.94k]
  ------------------
  423|  18.8k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for unwrapping");
  ------------------
  |  |  174|  14.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  14.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  14.8k|	int _ret = (r); \
  |  |  |  |  168|  14.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  14.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  14.8k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  14.8k|		return _ret; \
  |  |  |  |  172|  14.8k|	} \
  |  |  |  |  173|  14.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  424|  18.8k|	}
  425|   156k|	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|   156k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|   156k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (425:11): [True: 0, False: 156k]
  ------------------
  426|      0|		if (!(src_skey->usage & (SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (426:7): [True: 0, False: 0]
  ------------------
  427|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for unwrapping");
  ------------------
  |  |  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|	}
  429|   156k|	else
  430|   156k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|   156k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   156k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   156k|	int _ret = (r); \
  |  |  |  |  168|   156k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 156k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   156k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   156k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   156k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   156k|		return _ret; \
  |  |  |  |  172|   156k|	} \
  |  |  |  |  173|   156k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|       |
  432|  3.94k|	r = format_senv(p15card, key, &senv, &alg_info);
  433|  3.94k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  3.94k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.94k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.94k|	int _ret = (r); \
  |  |  |  |  168|  3.94k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 3.70k]
  |  |  |  |  ------------------
  |  |  |  |  169|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    232|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    232|		return _ret; \
  |  |  |  |  172|    232|	} \
  |  |  |  |  173|  3.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.70k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|  3.70k|	senv.operation = SC_SEC_OPERATION_UNWRAP;
  ------------------
  |  |   52|  3.70k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  435|       |
  436|  3.70k|	memset(&path, 0, sizeof(sc_path_t));
  437|  3.70k|	memset(&target_file_id, 0, sizeof(sc_path_t));
  438|       |
  439|  3.70k|	if (!tkey->path.len && tkey->path.aid.len) {
  ------------------
  |  Branch (439:6): [True: 3.70k, False: 0]
  |  Branch (439:25): [True: 0, False: 3.70k]
  ------------------
  440|       |		/* Target key is a SDO allocated in application DF */
  441|      0|		target_file_id = tkey->path;
  442|      0|	}
  443|  3.70k|	else if (tkey->path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (443:11): [True: 0, False: 3.70k]
  |  Branch (443:34): [True: 0, False: 0]
  ------------------
  444|       |		/* Path is relative to app. DF */
  445|      0|		path = p15card->file_app->path;
  446|      0|		target_file_id = tkey->path;
  447|      0|		sc_append_path(&path, &target_file_id);
  448|      0|		target_file_id = path;
  449|      0|	}
  450|  3.70k|	else if (tkey->path.len > 2) {
  ------------------
  |  Branch (450:11): [True: 0, False: 3.70k]
  ------------------
  451|      0|		path = tkey->path;
  452|      0|		memcpy(target_file_id.value, tkey->path.value + tkey->path.len - 2, 2);
  453|      0|		target_file_id.len = 2;
  454|      0|		target_file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  455|      0|	}
  456|  3.70k|	else {
  457|  3.70k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid unwrapping target key path");
  ------------------
  |  |  174|  3.70k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.70k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.70k|	int _ret = (r); \
  |  |  |  |  168|  3.70k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.70k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.70k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.70k|		return _ret; \
  |  |  |  |  172|  3.70k|	} \
  |  |  |  |  173|  3.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  458|  3.70k|	}
  459|       |
  460|      0|	senv_param = (sc_sec_env_param_t) { SC_SEC_ENV_PARAM_TARGET_FILE, &target_file_id, sizeof(target_file_id)};
  ------------------
  |  |   66|      0|#define SC_SEC_ENV_PARAM_TARGET_FILE	2
  ------------------
  461|      0|	LOG_TEST_RET(ctx, sec_env_add_param(&senv, &senv_param), "failed to add target file path to security environment");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  462|       |
  463|      0|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  464|      0|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|      0|	senv.algorithm_flags = sec_flags;
  466|       |
  467|      0|	if ((sec_flags & (SC_ALGORITHM_AES_CBC | SC_ALGORITHM_AES_CBC_PAD)) > 0) {
  ------------------
  |  |  207|      0|#define SC_ALGORITHM_AES_CBC		 0x02000000
  ------------------
              	if ((sec_flags & (SC_ALGORITHM_AES_CBC | SC_ALGORITHM_AES_CBC_PAD)) > 0) {
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (467:6): [True: 0, False: 0]
  ------------------
  468|      0|	    senv_param = (sc_sec_env_param_t) { SC_SEC_ENV_PARAM_IV, (void*) param, paramlen };
  ------------------
  |  |   65|      0|#define SC_SEC_ENV_PARAM_IV		1
  ------------------
  469|      0|	    LOG_TEST_RET(ctx, sec_env_add_param(&senv, &senv_param), "failed to add IV to security environment");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|      0|	}
  471|       |
  472|      0|	r = use_key(p15card, key, &senv, sc_unwrap, in, inlen, out,
  473|      0|		    poutlen);
  474|      0|	LOG_TEST_RET(ctx, r, "use_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|       |
  476|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|      0|}
sc_pkcs15_wrap:
  490|   175k|		const u8 *param, size_t paramlen) {
  491|   175k|	sc_context_t *ctx = p15card->card->ctx;
  492|   175k|	int r;
  493|   175k|	sc_algorithm_info_t *alg_info = NULL;
  494|   175k|	sc_security_env_t senv;
  495|   175k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  496|   175k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  497|   175k|	const struct sc_pkcs15_prkey_info *target_prkey = (const struct sc_pkcs15_prkey_info *) target_key->data;
  498|   175k|	const struct sc_pkcs15_skey_info *target_skey = (const struct sc_pkcs15_skey_info *) target_key->data;
  499|   175k|	unsigned long pad_flags = 0, sec_flags = 0;
  500|   175k|	sc_path_t tkey_path;
  501|   175k|	sc_path_t path, target_file_id;
  502|   175k|	sc_sec_env_param_t senv_param;
  503|       |
  504|   175k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   175k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   175k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   175k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   175k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 175k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  505|       |
  506|   175k|	switch (key->type) {
  507|  18.8k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  18.8k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (507:3): [True: 18.8k, False: 156k]
  ------------------
  508|  18.8k|			if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_WRAP)))
  ------------------
  |  |  309|  18.8k|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  |  Branch (508:8): [True: 16.6k, False: 2.16k]
  ------------------
  509|  18.8k|				LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for wrapping");
  ------------------
  |  |  174|  16.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.6k|	int _ret = (r); \
  |  |  |  |  168|  16.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  16.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  16.6k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  16.6k|		return _ret; \
  |  |  |  |  172|  16.6k|	} \
  |  |  |  |  173|  16.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  510|  2.16k|			break;
  511|  2.16k|		case SC_PKCS15_TYPE_SKEY_DES:
  ------------------
  |  |  434|      0|#define SC_PKCS15_TYPE_SKEY_DES			0x302
  ------------------
  |  Branch (511:3): [True: 0, False: 175k]
  ------------------
  512|      0|		case SC_PKCS15_TYPE_SKEY_3DES:
  ------------------
  |  |  436|      0|#define SC_PKCS15_TYPE_SKEY_3DES		0x304
  ------------------
  |  Branch (512:3): [True: 0, False: 175k]
  ------------------
  513|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (513:3): [True: 0, False: 175k]
  ------------------
  514|      0|			if (!(src_skey->usage & (SC_PKCS15_PRKEY_USAGE_WRAP)))
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  |  Branch (514:8): [True: 0, False: 0]
  ------------------
  515|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for wrapping");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|      0|			break;
  517|   156k|		default:
  ------------------
  |  Branch (517:3): [True: 156k, False: 18.8k]
  ------------------
  518|   156k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Wrapping key type not supported");
  ------------------
  |  |  174|   156k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   156k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   156k|	int _ret = (r); \
  |  |  |  |  168|   156k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 156k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   156k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   156k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   156k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   156k|		return _ret; \
  |  |  |  |  172|   156k|	} \
  |  |  |  |  173|   156k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|   175k|	}
  520|       |
  521|  2.16k|	if (!(target_key->type == SC_PKCS15_TYPE_PRKEY_RSA ||
  ------------------
  |  |  419|  4.32k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (521:8): [True: 0, False: 2.16k]
  ------------------
  522|  2.16k|			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  416|  2.16k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  432|  2.16k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (522:4): [True: 2.16k, False: 0]
  ------------------
  523|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Target key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|      0|	}
  525|       |
  526|  2.16k|	r = format_senv(p15card, key, &senv, &alg_info);
  527|  2.16k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  2.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.16k|	int _ret = (r); \
  |  |  |  |  168|  2.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 2.12k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.12k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  528|  2.12k|	senv.operation = SC_SEC_OPERATION_WRAP;
  ------------------
  |  |   51|  2.12k|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  529|       |
  530|  2.12k|	memset(&path, 0, sizeof (sc_path_t));
  531|  2.12k|	memset(&target_file_id, 0, sizeof (sc_path_t));
  532|       |
  533|  2.12k|	switch (target_key->type) {
  534|      0|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|      0|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (534:3): [True: 0, False: 2.12k]
  ------------------
  535|      0|			tkey_path = target_prkey->path;
  536|      0|			break;
  537|  2.12k|		default: /* we already know it is a secret key */
  ------------------
  |  Branch (537:3): [True: 2.12k, False: 0]
  ------------------
  538|  2.12k|			tkey_path = target_skey->path;
  539|  2.12k|			break;
  540|  2.12k|	}
  541|       |
  542|  2.12k|	if (!tkey_path.len && tkey_path.aid.len) {
  ------------------
  |  Branch (542:6): [True: 2.12k, False: 0]
  |  Branch (542:24): [True: 0, False: 2.12k]
  ------------------
  543|       |		/* Target key is a SDO allocated in application DF */
  544|      0|		target_file_id = tkey_path;
  545|  2.12k|	} else if (tkey_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (545:13): [True: 0, False: 2.12k]
  |  Branch (545:35): [True: 0, False: 0]
  ------------------
  546|       |		/* Path is relative to app. DF */
  547|      0|		path = p15card->file_app->path;
  548|      0|		target_file_id = tkey_path;
  549|      0|		sc_append_path(&path, &target_file_id);
  550|      0|		target_file_id  = path;
  551|  2.12k|	} else if (tkey_path.len > 2) {
  ------------------
  |  Branch (551:13): [True: 0, False: 2.12k]
  ------------------
  552|       |		/*path = tkey_path;*/
  553|      0|		memcpy(target_file_id.value, tkey_path.value + tkey_path.len - 2, 2);
  554|      0|		target_file_id.len = 2;
  555|      0|		target_file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  556|      0|	}
  557|  2.12k|	else {
  558|  2.12k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid unwrapping target key path");
  ------------------
  |  |  174|  2.12k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.12k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.12k|	int _ret = (r); \
  |  |  |  |  168|  2.12k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.12k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.12k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.12k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.12k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.12k|		return _ret; \
  |  |  |  |  172|  2.12k|	} \
  |  |  |  |  173|  2.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|  2.12k|	}
  560|      0|	senv_param = (sc_sec_env_param_t) { SC_SEC_ENV_PARAM_TARGET_FILE, &target_file_id, sizeof(target_file_id)};
  ------------------
  |  |   66|      0|#define SC_SEC_ENV_PARAM_TARGET_FILE	2
  ------------------
  561|      0|	LOG_TEST_RET(ctx, sec_env_add_param(&senv, &senv_param), "failed to add target file path to security environment");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  562|       |
  563|      0|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  564|      0|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  565|      0|	senv.algorithm_flags = sec_flags;
  566|       |
  567|      0|	if ((sec_flags & (SC_ALGORITHM_AES_CBC | SC_ALGORITHM_AES_CBC_PAD)) > 0) {
  ------------------
  |  |  207|      0|#define SC_ALGORITHM_AES_CBC		 0x02000000
  ------------------
              	if ((sec_flags & (SC_ALGORITHM_AES_CBC | SC_ALGORITHM_AES_CBC_PAD)) > 0) {
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (567:6): [True: 0, False: 0]
  ------------------
  568|      0|		senv_param = (sc_sec_env_param_t) { SC_SEC_ENV_PARAM_IV, (void*) param, paramlen };
  ------------------
  |  |   65|      0|#define SC_SEC_ENV_PARAM_IV		1
  ------------------
  569|      0|		LOG_TEST_RET(ctx, sec_env_add_param(&senv, &senv_param), "failed to add IV to security environment");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|      0|	}
  571|       |
  572|      0|	r = use_key(p15card, key, &senv, sc_wrap, NULL, 0, cryptogram, crgram_len ? *crgram_len : 0);
  ------------------
  |  Branch (572:65): [True: 0, False: 0]
  ------------------
  573|       |
  574|      0|	if (r > -1 && crgram_len) {
  ------------------
  |  Branch (574:6): [True: 0, False: 0]
  |  Branch (574:16): [True: 0, False: 0]
  ------------------
  575|      0|		if (*crgram_len < (size_t) r) {
  ------------------
  |  Branch (575:7): [True: 0, False: 0]
  ------------------
  576|      0|			*crgram_len = r;
  577|      0|			if (cryptogram != NULL) /* if NULL, return success and required buffer length by PKCS#11 convention */
  ------------------
  |  Branch (577:8): [True: 0, False: 0]
  ------------------
  578|      0|				LOG_TEST_RET(ctx, SC_ERROR_BUFFER_TOO_SMALL, "Buffer too small to hold the wrapped key.");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  579|      0|		}
  580|      0|		*crgram_len = r;
  581|      0|	}
  582|       |
  583|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|      0|}
sc_pkcs15_compute_signature:
  597|   788k|{
  598|   788k|	sc_context_t *ctx = p15card->card->ctx;
  599|   788k|	int r;
  600|   788k|	sc_security_env_t senv;
  601|   788k|	sc_algorithm_info_t *alg_info;
  602|   788k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  603|   788k|	u8 *buf = NULL, *tmp;
  604|   788k|	size_t modlen = 0, buflen = 0;
  605|   788k|	unsigned long pad_flags = 0, sec_flags = 0;
  606|       |
  607|   788k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   788k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   788k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   788k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   788k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 788k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|   788k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|   788k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|   788k|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (609:6): [True: 531k, False: 257k]
  ------------------
  610|   788k|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|   788k|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  611|   788k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for signing");
  ------------------
  |  |  174|   531k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   531k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   531k|	int _ret = (r); \
  |  |  |  |  168|   531k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 531k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   531k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   531k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   531k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   531k|		return _ret; \
  |  |  |  |  172|   531k|	} \
  |  |  |  |  173|   531k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|   257k|	r = format_senv(p15card, obj, &senv, &alg_info);
  614|   257k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|   257k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   257k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   257k|	int _ret = (r); \
  |  |  |  |  168|   257k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 202k, False: 54.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|   202k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   202k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   202k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   202k|		return _ret; \
  |  |  |  |  172|   202k|	} \
  |  |  |  |  173|   257k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 54.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|  54.5k|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|  54.5k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  616|       |
  617|  54.5k|	switch (obj->type) {
  618|  48.2k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  48.2k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (618:3): [True: 48.2k, False: 6.28k]
  ------------------
  619|  48.2k|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  145|  48.2k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  620|  48.2k|			break;
  621|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (621:3): [True: 0, False: 54.5k]
  ------------------
  622|      0|			modlen = BYTES4BITS(prkey->modulus_length) * 2;
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  623|      0|			break;
  624|  6.28k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  6.28k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (624:3): [True: 6.28k, False: 48.2k]
  ------------------
  625|  6.28k|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|  6.28k|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (625:3): [True: 0, False: 54.5k]
  ------------------
  626|  6.28k|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|  6.28k|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (626:3): [True: 0, False: 54.5k]
  ------------------
  627|  6.28k|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  145|  6.28k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  628|  6.28k|			break;
  629|      0|		default:
  ------------------
  |  Branch (629:3): [True: 0, False: 54.5k]
  ------------------
  630|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  54.5k|	}
  632|       |
  633|       |	/* Probably never happens, but better make sure */
  634|  54.5k|	if (outlen < modlen)
  ------------------
  |  Branch (634:6): [True: 0, False: 54.5k]
  ------------------
  635|  54.5k|		LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|  54.5k|	buflen = inlen + modlen;
  638|  54.5k|	buf = sc_mem_secure_alloc(buflen);
  639|  54.5k|	if (buf == NULL)
  ------------------
  |  Branch (639:6): [True: 0, False: 54.5k]
  ------------------
  640|  54.5k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  641|  54.5k|	memcpy(buf, in, inlen);
  642|       |
  643|       |	/* revert data to sign when signing with the GOST key.
  644|       |	 * TODO: can it be confirmed by the GOST standard?
  645|       |	 * TODO: tested with RuTokenECP, has to be validated for RuToken. */
  646|  54.5k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|  54.5k|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (646:6): [True: 0, False: 54.5k]
  ------------------
  647|      0|		r = sc_mem_reverse(buf, inlen);
  648|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Reverse memory error");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  649|      0|	}
  650|       |
  651|  54.5k|	tmp = buf;
  652|       |
  653|       |	/* flags: the requested algo
  654|       |	 * algo_info->flags: what is supported by the card
  655|       |	 * senv.algorithm_flags: what the card will have to do */
  656|       |
  657|       |	/* if the card has SC_ALGORITHM_NEED_USAGE set, and the
  658|       |	 * key is for signing and decryption, we need to emulate signing */
  659|       |
  660|  54.5k|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|  54.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  661|  54.5k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|  54.5k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (661:6): [True: 48.2k, False: 6.28k]
  ------------------
  662|  48.2k|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |   95|  48.2k|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (662:7): [True: 0, False: 48.2k]
  ------------------
  663|      0|			((prkey->usage & USAGE_ANY_SIGN) &&
  ------------------
  |  |  588|      0|#define USAGE_ANY_SIGN          (SC_PKCS15_PRKEY_USAGE_SIGN|\
  |  |  ------------------
  |  |  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  |  |  589|      0|                                 SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)
  |  |  ------------------
  |  |  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  |  Branch (663:5): [True: 0, False: 0]
  ------------------
  664|      0|			(prkey->usage & USAGE_ANY_DECIPHER)) ) {
  ------------------
  |  |  590|      0|#define USAGE_ANY_DECIPHER      (SC_PKCS15_PRKEY_USAGE_DECRYPT|\
  |  |  ------------------
  |  |  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |  591|      0|                                 SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  |  Branch (664:4): [True: 0, False: 0]
  ------------------
  665|      0|			size_t tmplen = buflen;
  666|      0|			if (flags & SC_ALGORITHM_RSA_RAW) {
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (666:8): [True: 0, False: 0]
  ------------------
  667|      0|				r = sc_pkcs15_decipher(p15card, obj, flags, in, inlen, out, outlen, NULL);
  668|      0|				goto err;
  669|      0|			}
  670|      0|			if (modlen > tmplen)
  ------------------
  |  Branch (670:8): [True: 0, False: 0]
  ------------------
  671|      0|				LOG_TEST_GOTO_ERR(ctx, SC_ERROR_NOT_ALLOWED, "Buffer too small, needs recompile!");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|       |
  673|       |			/* XXX Assuming RSA key here */
  674|      0|			r = sc_pkcs1_encode(ctx, flags, in, inlen, buf, &tmplen, prkey->modulus_length, pMechanism);
  675|       |
  676|       |			/* no padding needed - already done */
  677|      0|			flags &= ~SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|      0|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  678|       |			/* instead use raw rsa */
  679|      0|			flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  680|       |
  681|      0|			LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|       |
  683|      0|			r = sc_pkcs15_decipher(p15card, obj, flags, buf, modlen, out, outlen, NULL);
  684|      0|			goto err;
  685|      0|		}
  686|       |
  687|       |
  688|       |		/* If the card doesn't support the requested algorithm, we normally add the
  689|       |		 * padding here in software and ask the card to do a raw signature.  There's
  690|       |		 * one exception to that, where we might be able to get the signature to
  691|       |		 * succeed by stripping padding if the card only offers higher-level
  692|       |		 * signature operations.  The only thing we can strip is the DigestInfo
  693|       |		 * block from PKCS1 padding. */
  694|  48.2k|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|  48.2k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|  48.2k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (694:7): [True: 0, False: 48.2k]
  ------------------
  695|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (695:4): [True: 0, False: 0]
  ------------------
  696|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_HASH_NONE) &&
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (696:4): [True: 0, False: 0]
  ------------------
  697|      0|			(alg_info->flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (697:4): [True: 0, False: 0]
  ------------------
  698|      0|			unsigned int algo;
  699|      0|			size_t tmplen = buflen;
  700|       |
  701|      0|			r = sc_pkcs1_strip_digest_info_prefix(&algo, tmp, inlen, tmp, &tmplen);
  702|      0|			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (702:8): [True: 0, False: 0]
  |  Branch (702:27): [True: 0, False: 0]
  ------------------
  703|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|				goto err;
  705|      0|			}
  706|      0|			flags &= ~SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  707|      0|			flags |= algo;
  708|      0|			inlen = tmplen;
  709|      0|		}
  710|  48.2k|	}
  711|       |
  712|       |
  713|       |	/* ECDSA software hash has already been done, or is not needed, or card will do hash */
  714|       |	/* if card can not do the hash, will use SC_ALGORITHM_ECDSA_RAW */
  715|  54.5k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|  54.5k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (715:6): [True: 6.28k, False: 48.2k]
  ------------------
  716|  6.28k|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  174|  6.28k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (716:7): [True: 6.28k, False: 0]
  ------------------
  717|  6.28k|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  181|  6.28k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (717:8): [True: 6.28k, False: 0]
  ------------------
  718|  6.28k|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  719|  6.28k|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|  6.28k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  720|  6.28k|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  181|  6.28k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  6.28k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  6.28k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  6.28k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|  6.28k|		}
  722|  6.28k|	}
  723|       |
  724|  54.5k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  725|  54.5k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  54.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (725:6): [True: 34.9k, False: 19.5k]
  ------------------
  726|  34.9k|		goto err;
  727|  34.9k|	}
  728|       |	/* senv now has flags card or driver will do */
  729|  19.5k|	senv.algorithm_flags = sec_flags;
  730|       |
  731|  19.5k|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|  19.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  732|  19.5k|		flags, alg_info->flags, pad_flags, sec_flags);
  733|       |
  734|       |	/* add the padding bytes (if necessary) */
  735|  19.5k|	if (pad_flags != 0) {
  ------------------
  |  Branch (735:6): [True: 7.47k, False: 12.0k]
  ------------------
  736|  7.47k|		size_t tmplen = buflen;
  737|       |
  738|       |		/* XXX Assuming RSA key here */
  739|  7.47k|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  740|  7.47k|		    prkey->modulus_length, pMechanism);
  741|  7.47k|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|  7.47k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  7.47k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  7.47k|	int _ret = (r); \
  |  |  |  |  178|  7.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 7.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|  7.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  7.47k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  7.47k|		goto err; \
  |  |  |  |  182|  7.47k|	} \
  |  |  |  |  183|  7.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|      0|		inlen = tmplen;
  743|      0|	}
  744|  12.0k|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   69|  24.1k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (744:12): [True: 9.26k, False: 2.79k]
  ------------------
  745|  9.26k|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  103|  9.26k|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  104|  9.26k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (745:12): [True: 1.49k, False: 7.77k]
  ------------------
  746|       |		/* Add zero-padding if input is shorter than the modulus */
  747|  1.49k|		if (inlen < modlen) {
  ------------------
  |  Branch (747:7): [True: 1.04k, False: 454]
  ------------------
  748|  1.04k|			if (modlen > buflen) {
  ------------------
  |  Branch (748:8): [True: 0, False: 1.04k]
  ------------------
  749|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  750|      0|				goto err;
  751|      0|			}
  752|  1.04k|			memmove(tmp+modlen-inlen, tmp, inlen);
  753|  1.04k|			memset(tmp, 0, modlen-inlen);
  754|  1.04k|		}
  755|  1.49k|		inlen = modlen;
  756|  1.49k|	}
  757|       |	/* PKCS#11 MECHANISMS V2.30: 6.3.1 EC Signatures
  758|       |	 * If the length of the hash value is larger than the bit length of n, only
  759|       |	 * the leftmost bits of the hash up to the length of n will be used. Any
  760|       |	 * truncation is done by the token.
  761|       |	 * But if card is going to do the hash, pass in all the data
  762|       |	 */
  763|  10.5k|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   70|  21.1k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (763:11): [True: 2.79k, False: 7.77k]
  ------------------
  764|  2.79k|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  181|  2.79k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  2.79k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  2.79k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  2.79k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  2.79k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  2.79k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  2.79k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  2.79k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  2.79k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  2.79k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  2.79k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  2.79k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  2.79k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  2.79k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  2.79k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (764:4): [True: 2.79k, False: 0]
  ------------------
  765|  2.79k|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   69|  2.79k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 2.58k, False: 208]
  |  |  ------------------
  ------------------
  766|  2.79k|	}
  767|       |
  768|       |
  769|  12.0k|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  770|  12.0k|			out, outlen);
  771|  12.0k|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|  12.0k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  12.0k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  12.0k|	int _ret = (r); \
  |  |  |  |  178|  12.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11.3k, False: 699]
  |  |  |  |  ------------------
  |  |  |  |  179|  11.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  11.3k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  11.3k|		goto err; \
  |  |  |  |  182|  11.3k|	} \
  |  |  |  |  183|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 699]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|       |
  773|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  774|       |	/* Already know outlen >= modlen and r >= 0 */
  775|    699|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|  1.39k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (775:6): [True: 699, False: 0]
  |  Branch (775:47): [True: 602, False: 97]
  ------------------
  776|    602|		memmove(out + modlen - r, out, r);
  777|    602|		memset(out, 0, modlen - r);
  778|    602|		r = (int)modlen;
  779|    602|	}
  780|       |
  781|  54.5k|err:
  782|  54.5k|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1580|  54.5k|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|  54.5k|	sc_mem_clear(ptr, len); \
  |  | 1582|  54.5k|	sc_mem_secure_free(ptr, len); \
  |  | 1583|  54.5k|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 54.5k]
  |  |  ------------------
  ------------------
  783|       |
  784|  54.5k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  54.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  54.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  54.5k|	int _ret = r; \
  |  |  |  |  155|  54.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 53.8k, False: 687]
  |  |  |  |  ------------------
  |  |  |  |  156|  53.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  53.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 53.8k, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  157|  53.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  53.8k|	} else { \
  |  |  |  |  159|    687|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    687|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    687|	} \
  |  |  |  |  162|  54.5k|	return _ret; \
  |  |  |  |  163|  54.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|  54.5k|}
pkcs15-sec.c:format_senv:
  175|   332k|{
  176|   332k|	sc_context_t *ctx = p15card->card->ctx;
  177|   332k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|   332k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|   332k|	memset(senv_out, 0, sizeof(*senv_out));
  181|       |
  182|       |	/* Card driver should have the access to supported algorithms from 'tokenInfo'. So that
  183|       |	 * it can get value of card specific 'AlgorithmInfo::algRef'. */
  184|   332k|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|   332k|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|   332k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  418|   665k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|   238k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  432|   238k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (186:8): [True: 94.0k, False: 238k]
  |  Branch (186:75): [True: 0, False: 238k]
  ------------------
  187|   332k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This is not a private or secret key");
  ------------------
  |  |  174|   238k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   238k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   238k|	int _ret = (r); \
  |  |  |  |  168|   238k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 238k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   238k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   238k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   238k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   238k|		return _ret; \
  |  |  |  |  172|   238k|	} \
  |  |  |  |  173|   238k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* If the key is not native, we can't operate with it. */
  190|  94.0k|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 94.0k]
  ------------------
  191|  94.0k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "This key is not native, cannot operate with it");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|       |
  193|  94.0k|	switch (obj->type) {
  194|  86.4k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  86.4k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 86.4k, False: 7.54k]
  ------------------
  195|  86.4k|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|  86.4k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 22.7k, False: 63.7k]
  ------------------
  197|  22.7k|				sc_log(ctx, "Card does not support RSA with key length %zu",
  ------------------
  |  |   71|  22.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__
  |  |  ------------------
  ------------------
  198|  22.7k|						prkey->modulus_length);
  199|  22.7k|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  22.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.7k|	int _ret = r; \
  |  |  |  |  155|  22.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.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|  22.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  22.7k|	return _ret; \
  |  |  |  |  163|  22.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|  22.7k|			}
  201|  63.7k|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  63.7k|#define SC_ALGORITHM_RSA		0
  ------------------
  202|  63.7k|			senv_out->key_size_bits = prkey->modulus_length;
  203|  63.7k|			break;
  204|       |
  205|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (205:3): [True: 0, False: 94.0k]
  ------------------
  206|      0|			*alg_info_out = sc_card_find_gostr3410_alg(p15card->card, prkey->modulus_length);
  207|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (207:8): [True: 0, False: 0]
  ------------------
  208|      0|				sc_log(ctx, "Card does not support GOSTR3410 with key length %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__
  |  |  ------------------
  ------------------
  209|      0|						prkey->modulus_length);
  210|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|      0|			}
  212|      0|			senv_out->algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  213|      0|			senv_out->key_size_bits = prkey->modulus_length;
  214|      0|			break;
  215|       |
  216|      0|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      0|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (216:3): [True: 0, False: 94.0k]
  ------------------
  217|      0|			*alg_info_out = sc_card_find_eddsa_alg(p15card->card, prkey->field_length, NULL);
  218|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (218:8): [True: 0, False: 0]
  ------------------
  219|      0|				sc_log(ctx, "Card does not support EDDSA with field_size %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__
  |  |  ------------------
  ------------------
  220|      0|						prkey->field_length);
  221|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|			}
  223|      0|			senv_out->algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  224|      0|			senv_out->key_size_bits = prkey->field_length;
  225|      0|			break;
  226|       |
  227|      0|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|      0|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (227:3): [True: 0, False: 94.0k]
  ------------------
  228|      0|			*alg_info_out = sc_card_find_xeddsa_alg(p15card->card, prkey->field_length, NULL);
  229|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (229:8): [True: 0, False: 0]
  ------------------
  230|      0|				sc_log(ctx, "Card does not support XEDDSA with field_size %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__
  |  |  ------------------
  ------------------
  231|      0|						prkey->field_length);
  232|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|      0|			}
  234|      0|			senv_out->algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  235|      0|			senv_out->key_size_bits = prkey->field_length;
  236|      0|			break;
  237|       |
  238|  7.54k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  7.54k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (238:3): [True: 7.54k, False: 86.4k]
  ------------------
  239|  7.54k|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  240|  7.54k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (240:8): [True: 670, False: 6.87k]
  ------------------
  241|    670|				sc_log(ctx, "Card does not support EC with field_size %zu",
  ------------------
  |  |   71|    670|#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|    670|						prkey->field_length);
  243|    670|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    670|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    670|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    670|	int _ret = r; \
  |  |  |  |  155|    670|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 670, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    670|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    670|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 670, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    670|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    670|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    670|	return _ret; \
  |  |  |  |  163|    670|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|    670|			}
  245|  6.87k|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|  6.87k|#define SC_ALGORITHM_EC		2
  ------------------
  246|  6.87k|			senv_out->key_size_bits = prkey->field_length;
  247|       |
  248|  6.87k|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|  6.87k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  249|  6.87k|			senv_out->algorithm_ref = prkey->field_length;
  250|  6.87k|			break;
  251|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (251:3): [True: 0, False: 94.0k]
  ------------------
  252|      0|			if (skey->key_type != CKK_AES)
  ------------------
  |  |  485|      0|#define CKK_AES 0x0000001FUL
  ------------------
  |  Branch (252:8): [True: 0, False: 0]
  ------------------
  253|      0|				LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|      0|			*alg_info_out = sc_card_find_alg(p15card->card, SC_ALGORITHM_AES,
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  255|      0|					skey->value_len, NULL);
  256|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (256:8): [True: 0, False: 0]
  ------------------
  257|      0|				sc_log(ctx, "Card does not support AES with key length %zu", skey->value_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|      0|			}
  260|      0|			senv_out->algorithm = SC_ALGORITHM_AES;
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  261|      0|			senv_out->key_size_bits = skey->value_len;
  262|      0|			break;
  263|       |			/* add other crypto types here */
  264|      0|		default:
  ------------------
  |  Branch (264:3): [True: 0, False: 94.0k]
  ------------------
  265|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|  94.0k|	}
  267|  70.6k|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|  70.6k|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  268|       |
  269|       |	/* optional keyReference attribute (the default value is -1) */
  270|  70.6k|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (270:6): [True: 70.4k, False: 210]
  ------------------
  271|  70.4k|		senv_out->key_ref_len = 1;
  272|  70.4k|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  273|  70.4k|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|  70.4k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  274|  70.4k|	}
  275|       |
  276|  70.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  70.6k|#define SC_SUCCESS				0
  ------------------
  277|  94.0k|}
pkcs15-sec.c:use_key:
  133|  17.4k|{
  134|  17.4k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  17.4k|#define SC_SUCCESS				0
  ------------------
  135|  17.4k|	int revalidated_cached_pin = 0;
  136|  17.4k|	sc_path_t path;
  137|  17.4k|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  174|  17.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  17.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  17.4k|	int _ret = (r); \
  |  |  |  |  168|  17.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 17.4k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  17.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|  17.4k|	r = sc_lock(p15card->card);
  140|  17.4k|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  17.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  17.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  17.4k|	int _ret = (r); \
  |  |  |  |  168|  17.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 17.4k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  17.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|  17.7k|	do {
  143|  17.7k|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 3.88k, False: 13.8k]
  |  Branch (143:24): [True: 1.14k, False: 12.7k]
  ------------------
  144|  5.02k|			r = select_key_file(p15card, obj, senv);
  145|  5.02k|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 3.11k, False: 1.90k]
  ------------------
  146|  3.11k|				sc_log(p15card->card->ctx,
  ------------------
  |  |   71|  3.11k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|  3.11k|						"Unable to select private key file");
  148|  3.11k|			}
  149|  5.02k|		}
  150|  17.7k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  17.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 14.6k, False: 3.11k]
  ------------------
  151|  14.6k|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|  17.7k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  17.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 10.0k, False: 7.69k]
  ------------------
  154|  10.0k|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|  17.7k|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 369, False: 17.4k]
  ------------------
  157|       |			/* only re-validate once */
  158|    369|			break;
  159|  17.4k|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|  17.4k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 515, False: 16.8k]
  ------------------
  160|    515|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|    515|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 146, False: 369]
  ------------------
  162|    146|				break;
  163|    369|			revalidated_cached_pin = 1;
  164|    369|		}
  165|  17.4k|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 369, False: 16.8k]
  ------------------
  166|       |
  167|  17.4k|	sc_unlock(p15card->card);
  168|       |
  169|  17.4k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  17.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.4k|	int _ret = r; \
  |  |  |  |  155|  17.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.6k, False: 756]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  16.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16.1k, False: 496]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.6k|	} else { \
  |  |  |  |  159|    756|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    756|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    756|	} \
  |  |  |  |  162|  17.4k|	return _ret; \
  |  |  |  |  163|  17.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|  17.4k|}
pkcs15-sec.c:get_file_path:
   57|  22.4k|{
   58|  22.4k|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 22.4k]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|  22.4k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|  22.4k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|  22.4k|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|  22.4k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|  22.4k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 22.4k, False: 0]
  ------------------
   65|  22.4k|		*path = prkey->path;
   66|  22.4k|	}
   67|      0|	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (67:11): [True: 0, False: 0]
  ------------------
   68|      0|		*path = skey->path;
   69|      0|	}
   70|      0|	else
   71|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   72|       |
   73|  22.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  22.4k|#define SC_SUCCESS				0
  ------------------
   74|  22.4k|}
pkcs15-sec.c:select_key_file:
   80|  5.02k|{
   81|  5.02k|	sc_context_t *ctx = p15card->card->ctx;
   82|  5.02k|	sc_path_t orig_path;
   83|  5.02k|	sc_path_t path, file_id;
   84|  5.02k|	int r;
   85|       |
   86|  5.02k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.02k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.02k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.02k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.02k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|  5.02k|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|  5.02k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.02k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.02k|	int _ret = (r); \
  |  |  |  |  168|  5.02k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 5.02k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  5.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  5.02k|	memset(&path, 0, sizeof(sc_path_t));
   90|  5.02k|	memset(&file_id, 0, sizeof(sc_path_t));
   91|       |
   92|       |	/* TODO: Why file_app may be NULL -- at least 3F00 has to be present?
   93|       |	 * Check validity of the following assumption. */
   94|       |	/* For pkcs15-emulated cards, the file_app may be NULL,
   95|       |	 * in that case we always assume an absolute path */
   96|  5.02k|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 1.14k, False: 3.88k]
  |  Branch (96:24): [True: 1.14k, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|  1.14k|		path = orig_path;
   99|  1.14k|	}
  100|  3.88k|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 3.88k]
  |  Branch (100:33): [True: 0, False: 0]
  ------------------
  101|       |		/* Path is relative to app. DF */
  102|      0|		path = p15card->file_app->path;
  103|      0|		file_id = orig_path;
  104|      0|		sc_append_path(&path, &file_id);
  105|      0|		senv->file_ref = file_id;
  106|      0|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|      0|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  107|      0|	}
  108|  3.88k|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 3.88k, False: 0]
  ------------------
  109|  3.88k|		path = orig_path;
  110|  3.88k|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|  3.88k|		file_id.len = 2;
  112|  3.88k|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  3.88k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|  3.88k|		senv->file_ref = file_id;
  114|  3.88k|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|  3.88k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|  3.88k|	}
  116|      0|	else {
  117|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid private key path");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  118|      0|	}
  119|       |
  120|  5.02k|	r = sc_select_file(p15card->card, &path, NULL);
  121|  5.02k|	LOG_TEST_RET(ctx, r, "sc_select_file() failed");
  ------------------
  |  |  174|  5.02k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.02k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.02k|	int _ret = (r); \
  |  |  |  |  168|  5.02k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.11k, False: 1.90k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.11k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.11k|		return _ret; \
  |  |  |  |  172|  3.11k|	} \
  |  |  |  |  173|  5.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.90k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|  1.90k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.90k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.90k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.90k|	int _ret = r; \
  |  |  |  |  155|  1.90k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.90k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.90k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.90k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.90k|	} else { \
  |  |  |  |  159|      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.90k|	return _ret; \
  |  |  |  |  163|  1.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|  1.90k|}

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

sc_pkcs15emu_srbeid_init_ex:
  572|  7.72k|{
  573|  7.72k|	(void)aid;
  574|       |
  575|  7.72k|	if (p15card->card->type != SC_CARD_TYPE_SRBEID_BASE)
  ------------------
  |  Branch (575:6): [True: 7.50k, False: 215]
  ------------------
  576|  7.50k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.50k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  577|       |
  578|    215|	return sc_pkcs15emu_srbeid_init(p15card);
  579|  7.72k|}
pkcs15-srbeid.c:sc_pkcs15emu_srbeid_init:
  417|    215|{
  418|    215|	sc_card_t *card = p15card->card;
  419|    215|	cert_entry_t *certs = NULL;
  420|    215|	int ncerts, i, r = SC_SUCCESS;
  ------------------
  |  |   28|    215|#define SC_SUCCESS				0
  ------------------
  421|       |
  422|    215|	sc_log(card->ctx, "srbeid: pkcs15 bind");
  ------------------
  |  |   71|    215|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  423|       |
  424|    215|	ncerts = srbeid_enum_certs(card, &certs);
  425|    215|	if (ncerts < 0) {
  ------------------
  |  Branch (425:6): [True: 131, False: 84]
  ------------------
  426|    131|		sc_log(card->ctx, "srbeid: cert enumeration failed: %d", ncerts);
  ------------------
  |  |   71|    131|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  427|    131|		return ncerts;
  428|    131|	}
  429|     84|	if (ncerts == 0) {
  ------------------
  |  Branch (429:6): [True: 17, False: 67]
  ------------------
  430|     17|		sc_log(card->ctx, "srbeid: no certificates found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  431|     17|		goto out;
  432|     17|	}
  433|       |
  434|       |	/* Set card label and manufacturer. */
  435|     67|	set_string(&p15card->tokeninfo->label, "Serbian CardEdge");
  436|     67|	set_string(&p15card->tokeninfo->manufacturer_id, "CardEdge");
  437|       |
  438|       |	/* Query PIN tries_left via card driver's pin_cmd. */
  439|     67|	{
  440|     67|		struct sc_pin_cmd_data pin_data = {0};
  441|       |
  442|     67|		pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     67|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  443|     67|		pin_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|     67|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  444|     67|		pin_data.pin_reference = CE_PIN_REFERENCE;
  ------------------
  |  |   51|     67|#define CE_PIN_REFERENCE  0x80u
  ------------------
  445|     67|		pin_data.pin1.tries_left = -1;
  446|       |
  447|       |		/* Best-effort: failure to query PIN status is not fatal. */
  448|     67|		sc_pin_cmd(card, &pin_data);
  449|     67|		sc_log(card->ctx, "srbeid: PIN tries_left=%d", pin_data.pin1.tries_left);
  ------------------
  |  |   71|     67|#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|       |		/* ---- PIN auth object ----
  452|       |		 * Must be registered before private keys so auth_id links work. */
  453|     67|		{
  454|     67|			sc_pkcs15_auth_info_t auth_info = {0};
  455|     67|			sc_pkcs15_object_t auth_obj = {0};
  456|       |
  457|     67|			auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     67|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  458|     67|			auth_info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|     67|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  459|     67|			auth_info.tries_left = pin_data.pin1.tries_left;
  460|     67|			auth_info.attrs.pin.reference = CE_PIN_REFERENCE;
  ------------------
  |  |   51|     67|#define CE_PIN_REFERENCE  0x80u
  ------------------
  461|     67|			auth_info.attrs.pin.min_length = 4;
  462|     67|			auth_info.attrs.pin.max_length = CE_PIN_MAX_LENGTH;
  ------------------
  |  |   52|     67|#define CE_PIN_MAX_LENGTH 8u
  ------------------
  463|     67|			auth_info.attrs.pin.stored_length = CE_PIN_MAX_LENGTH;
  ------------------
  |  |   52|     67|#define CE_PIN_MAX_LENGTH 8u
  ------------------
  464|     67|			auth_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|     67|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  465|     67|			auth_info.attrs.pin.pad_char = 0x00;
  466|     67|			auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   58|     67|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              			auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   55|     67|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              			auth_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_NEEDS_PADDING;
  ------------------
  |  |   59|     67|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  467|     67|			auth_info.path.aid.len = AID_PKCS15_LEN;
  ------------------
  |  |   30|     67|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
  468|     67|			memcpy(auth_info.path.aid.value, AID_PKCS15, AID_PKCS15_LEN);
  ------------------
  |  |   30|     67|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
  469|     67|			auth_info.auth_id.len = 1;
  470|     67|			auth_info.auth_id.value[0] = 1;
  471|       |
  472|     67|			strncpy(auth_obj.label, "User PIN", sizeof(auth_obj.label) - 1);
  473|     67|			auth_obj.auth_id.len = 0;
  474|     67|			auth_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     67|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  475|       |
  476|     67|			r = sc_pkcs15emu_add_pin_obj(p15card, &auth_obj, &auth_info);
  477|     67|			if (r < 0) {
  ------------------
  |  Branch (477:8): [True: 0, False: 67]
  ------------------
  478|      0|				sc_log(card->ctx, "srbeid: add PIN obj failed: %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__
  |  |  ------------------
  ------------------
  479|      0|				goto out;
  480|      0|			}
  481|     67|		}
  482|     67|	}
  483|       |
  484|    251|	for (i = 0; i < ncerts; i++) {
  ------------------
  |  Branch (484:14): [True: 184, False: 67]
  ------------------
  485|    184|		sc_pkcs15_prkey_info_t key_info = {0};
  486|    184|		sc_pkcs15_object_t key_obj = {0};
  487|    184|		sc_pkcs15_cert_info_t cert_info = {0};
  488|    184|		sc_pkcs15_object_t cert_obj = {0};
  489|    184|		u8 *der = NULL;
  490|    184|		size_t der_len = 0;
  491|    184|		int is_kxc = (certs[i].key_pair_id == CE_AT_KEYEXCHANGE);
  ------------------
  |  |   44|    184|#define CE_AT_KEYEXCHANGE	1u
  ------------------
  492|       |
  493|       |		/* ---- Private key object ---- */
  494|       |
  495|    184|		key_info.id.len = 1;
  496|    184|		key_info.id.value[0] = (u8)(i + 1);
  497|    184|		key_info.native = 1;
  498|    184|		key_info.key_reference = (int)certs[i].key_fid;
  499|    184|		key_info.modulus_length = certs[i].key_size_bits
  ------------------
  |  Branch (499:29): [True: 0, False: 184]
  ------------------
  500|    184|							  ? certs[i].key_size_bits
  501|    184|							  : 2048;
  502|       |
  503|       |		/*
  504|       |		 * Key usage flags by type:
  505|       |		 *   kxc (AT_KEYEXCHANGE) — encryption / key wrapping / decryption + signing
  506|       |		 *                          (TLS client auth uses the key exchange cert for signing)
  507|       |		 *   ksc (AT_SIGNATURE)   — digital signature / non-repudiation only
  508|       |		 */
  509|    184|		if (is_kxc) {
  ------------------
  |  Branch (509:7): [True: 133, False: 51]
  ------------------
  510|    133|			key_info.usage = SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_WRAP | SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  305|    133|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              			key_info.usage = SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_WRAP | SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  306|    133|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              			key_info.usage = SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_WRAP | SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  309|    133|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
              			key_info.usage = SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_WRAP | SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  310|    133|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
              			key_info.usage = SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_WRAP | SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|    133|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  511|    133|		} else {
  512|     51|			key_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  307|     51|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              			key_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|     51|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  513|     51|		}
  514|       |
  515|       |		/*
  516|       |		 * Set only the AID on key_info.path (path.len stays 0).
  517|       |		 * This makes select_key_file() select the PKI applet via AID
  518|       |		 * before calling set_security_env(), without appending a file
  519|       |		 * path that would fail on CardEdge's non-TLV FCI.
  520|       |		 *
  521|       |		 * The key FID is passed via key_info.key_reference and
  522|       |		 * reconstructed in set_security_env() from the low byte.
  523|       |		 */
  524|    184|		key_info.path.aid.len = AID_PKCS15_LEN;
  ------------------
  |  |   30|    184|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
  525|    184|		memcpy(key_info.path.aid.value, AID_PKCS15, AID_PKCS15_LEN);
  ------------------
  |  |   30|    184|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
  526|       |
  527|    184|		strncpy(key_obj.label, certs[i].label, sizeof(key_obj.label) - 1);
  528|    184|		key_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    184|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  529|    184|		key_obj.auth_id.len = 1;
  530|    184|		key_obj.auth_id.value[0] = 1;
  531|       |
  532|    184|		r = sc_pkcs15emu_add_rsa_prkey(p15card, &key_obj, &key_info);
  533|    184|		if (r < 0) {
  ------------------
  |  Branch (533:7): [True: 0, False: 184]
  ------------------
  534|      0|			sc_log(card->ctx, "srbeid: add prkey[%d] failed: %d", i, 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__
  |  |  ------------------
  ------------------
  535|      0|			goto out;
  536|      0|		}
  537|       |
  538|       |		/* ---- Certificate object ---- */
  539|    184|		if (srbeid_read_cert_der(card, certs[i].cert_fid, &der, &der_len) < 0) {
  ------------------
  |  Branch (539:7): [True: 183, False: 1]
  ------------------
  540|    183|			sc_log(card->ctx, "srbeid: could not read cert[%d] DER", i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  541|    183|			continue;
  542|    183|		}
  543|       |
  544|      1|		cert_info.id.len = 1;
  545|      1|		cert_info.id.value[0] = (u8)(i + 1);
  546|      1|		cert_info.authority = 0;
  547|       |
  548|       |		/* Store DER directly in the PKCS#15 value buffer. */
  549|      1|		cert_info.value.value = der; /* ownership transferred */
  550|      1|		cert_info.value.len = der_len;
  551|       |
  552|      1|		strncpy(cert_obj.label, certs[i].label, sizeof(cert_obj.label) - 1);
  553|       |
  554|      1|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  555|      1|		if (r < 0) {
  ------------------
  |  Branch (555:7): [True: 0, False: 1]
  ------------------
  556|      0|			sc_log(card->ctx, "srbeid: add cert[%d] failed: %d", i, 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__
  |  |  ------------------
  ------------------
  557|      0|			free(der);
  558|      0|			goto out;
  559|      0|		}
  560|       |		/* der ownership now belongs to p15card; do not free. */
  561|      1|	}
  562|       |
  563|     67|	sc_log(card->ctx, "srbeid: pkcs15 bind OK (%d certs)", ncerts);
  ------------------
  |  |   71|     67|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  564|       |
  565|     84|out:
  566|     84|	free(certs);
  567|     84|	return r;
  568|     67|}
pkcs15-srbeid.c:srbeid_enum_certs:
  190|    215|{
  191|    215|	u8 *dir_buf = NULL, *mscp_buf = NULL, *cmap_buf = NULL;
  192|    215|	size_t dir_len = 0, mscp_len = 0, cmap_len = 0;
  193|    215|	ce_dir_entry_t *root_entries = NULL, *mscp_entries = NULL;
  194|    215|	int root_count = 0, mscp_count = 0;
  195|    215|	unsigned mscp_fid = 0, cmap_fid = 0;
  196|    215|	cert_entry_t *certs = NULL;
  197|    215|	int ncerts = 0, cap = 8;
  198|    215|	int r, i;
  199|    215|	size_t cmap_offset = 0, cmap_nrec = 0;
  200|       |
  201|    215|	*certs_out = NULL;
  202|       |
  203|       |	/* Select PKI applet. */
  204|    215|	if (iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) != SC_SUCCESS) {
  ------------------
  |  |   30|    215|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) != SC_SUCCESS) {
  ------------------
  |  |   28|    215|#define SC_SUCCESS				0
  ------------------
  |  Branch (204:6): [True: 16, False: 199]
  ------------------
  205|     16|		r = SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     16|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  206|     16|		goto out;
  207|     16|	}
  208|       |
  209|       |	/* Read root directory (FID 0x7000). */
  210|    199|	r = srbeid_read_file(card, CE_PKI_ROOT_DIR_FID, &dir_buf, &dir_len);
  ------------------
  |  |   46|    199|#define CE_PKI_ROOT_DIR_FID	0x7000u
  ------------------
  211|    199|	if (r < 0)
  ------------------
  |  Branch (211:6): [True: 26, False: 173]
  ------------------
  212|     26|		goto out;
  213|       |
  214|    173|	root_count = ce_parse_dir(dir_buf, dir_len, &root_entries);
  215|    173|	if (root_count < 0) {
  ------------------
  |  Branch (215:6): [True: 18, False: 155]
  ------------------
  216|     18|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     18|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  217|     18|		goto out;
  218|     18|	}
  219|       |
  220|  2.81k|	for (i = 0; i < root_count; i++) {
  ------------------
  |  Branch (220:14): [True: 2.74k, False: 67]
  ------------------
  221|  2.74k|		if (root_entries[i].is_dir && strcmp(root_entries[i].name, "mscp") == 0) {
  ------------------
  |  Branch (221:7): [True: 1.68k, False: 1.05k]
  |  Branch (221:33): [True: 88, False: 1.60k]
  ------------------
  222|     88|			mscp_fid = root_entries[i].fid;
  223|     88|			break;
  224|     88|		}
  225|  2.74k|	}
  226|    155|	if (mscp_fid == 0) {
  ------------------
  |  Branch (226:6): [True: 67, False: 88]
  ------------------
  227|     67|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     67|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  228|     67|		goto out;
  229|     67|	}
  230|       |
  231|       |	/* Read mscp directory. */
  232|     88|	r = srbeid_read_file(card, mscp_fid, &mscp_buf, &mscp_len);
  233|     88|	if (r < 0)
  ------------------
  |  Branch (233:6): [True: 3, False: 85]
  ------------------
  234|      3|		goto out;
  235|       |
  236|     85|	mscp_count = ce_parse_dir(mscp_buf, mscp_len, &mscp_entries);
  237|     85|	if (mscp_count < 0) {
  ------------------
  |  Branch (237:6): [True: 1, False: 84]
  ------------------
  238|      1|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  239|      1|		goto out;
  240|      1|	}
  241|       |
  242|     84|	certs = calloc((size_t)cap, sizeof(cert_entry_t));
  243|     84|	if (!certs) {
  ------------------
  |  Branch (243:6): [True: 0, False: 84]
  ------------------
  244|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  245|      0|		goto out;
  246|      0|	}
  247|       |
  248|  18.6k|	for (i = 0; i < mscp_count; i++) {
  ------------------
  |  Branch (248:14): [True: 18.5k, False: 84]
  ------------------
  249|  18.5k|		ce_dir_entry_t *e = &mscp_entries[i];
  250|  18.5k|		if (e->is_dir)
  ------------------
  |  Branch (250:7): [True: 11.3k, False: 7.20k]
  ------------------
  251|  11.3k|			continue;
  252|       |
  253|  7.20k|		if (strcmp(e->name, "cmapfile") == 0) {
  ------------------
  |  Branch (253:7): [True: 56, False: 7.14k]
  ------------------
  254|     56|			cmap_fid = e->fid;
  255|  7.14k|		} else if (strlen(e->name) == 5) {
  ------------------
  |  Branch (255:14): [True: 409, False: 6.73k]
  ------------------
  256|    409|			unsigned kp_id;
  257|    409|			const char *lbl;
  258|       |
  259|    409|			if (strncmp(e->name, "kxc", 3) == 0) {
  ------------------
  |  Branch (259:8): [True: 133, False: 276]
  ------------------
  260|    133|				kp_id = CE_AT_KEYEXCHANGE;
  ------------------
  |  |   44|    133|#define CE_AT_KEYEXCHANGE	1u
  ------------------
  261|    133|				lbl = "Key Exchange Certificate";
  262|    276|			} else if (strncmp(e->name, "ksc", 3) == 0) {
  ------------------
  |  Branch (262:15): [True: 51, False: 225]
  ------------------
  263|     51|				kp_id = CE_AT_SIGNATURE;
  ------------------
  |  |   45|     51|#define CE_AT_SIGNATURE		2u
  ------------------
  264|     51|				lbl = "Digital Signature Certificate";
  265|    225|			} else {
  266|    225|				continue;
  267|    225|			}
  268|       |
  269|    184|			if (ncerts >= cap) {
  ------------------
  |  Branch (269:8): [True: 0, False: 184]
  ------------------
  270|      0|				cert_entry_t *tmp = realloc(certs,
  271|      0|						(size_t)(cap * 2) * sizeof(cert_entry_t));
  272|      0|				if (!tmp) {
  ------------------
  |  Branch (272:9): [True: 0, False: 0]
  ------------------
  273|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  274|      0|					goto out;
  275|      0|				}
  276|      0|				certs = tmp;
  277|       |				/* realloc() leaves the new tail uninitialised */
  278|      0|				memset(certs + cap, 0, (size_t)cap * sizeof(cert_entry_t));
  279|      0|				cap *= 2;
  280|      0|			}
  281|       |
  282|    184|			certs[ncerts].cont_id = (unsigned)(e->name[3] - '0') * 10 + (unsigned)(e->name[4] - '0');
  283|    184|			certs[ncerts].cert_fid = e->fid;
  284|    184|			certs[ncerts].key_pair_id = kp_id;
  285|    184|			snprintf(certs[ncerts].label, sizeof(certs[ncerts].label), "%s", lbl);
  286|    184|			ncerts++;
  287|    184|		}
  288|  7.20k|	}
  289|       |
  290|       |	/* Read cmapfile and resolve key FIDs. */
  291|     84|	if (cmap_fid != 0) {
  ------------------
  |  Branch (291:6): [True: 55, False: 29]
  ------------------
  292|     55|		r = srbeid_read_file(card, cmap_fid, &cmap_buf, &cmap_len);
  293|     55|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     55|#define SC_SUCCESS				0
  ------------------
  |  Branch (293:7): [True: 23, False: 32]
  ------------------
  294|       |			/* Optional 2-byte prefix present when (len-2) is a multiple of 86. */
  295|     23|			if (cmap_len >= 2 && (cmap_len - 2) % CE_CMAP_RECORD_SIZE == 0)
  ------------------
  |  |   38|     18|#define CE_CMAP_RECORD_SIZE	86u
  ------------------
  |  Branch (295:8): [True: 18, False: 5]
  |  Branch (295:25): [True: 5, False: 13]
  ------------------
  296|      5|				cmap_offset = 2;
  297|     23|			cmap_nrec = (cmap_len - cmap_offset) / CE_CMAP_RECORD_SIZE;
  ------------------
  |  |   38|     23|#define CE_CMAP_RECORD_SIZE	86u
  ------------------
  298|     23|		}
  299|     55|	}
  300|       |
  301|    268|	for (i = 0; i < ncerts; i++) {
  ------------------
  |  Branch (301:14): [True: 184, False: 84]
  ------------------
  302|    184|		unsigned ci = certs[i].cont_id;
  303|       |
  304|    184|		if (cmap_buf && ci < cmap_nrec) {
  ------------------
  |  Branch (304:7): [True: 57, False: 127]
  |  Branch (304:19): [True: 0, False: 57]
  ------------------
  305|      0|			size_t rec = cmap_offset + (size_t)ci * CE_CMAP_RECORD_SIZE;
  ------------------
  |  |   38|      0|#define CE_CMAP_RECORD_SIZE	86u
  ------------------
  306|      0|			u8 flags = cmap_buf[rec + CE_CMAP_FLAGS_OFFSET];
  ------------------
  |  |   39|      0|#define CE_CMAP_FLAGS_OFFSET	80u
  ------------------
  307|       |
  308|      0|			if (flags & CE_CMAP_VALID_CONTAINER) {
  ------------------
  |  |   42|      0|#define CE_CMAP_VALID_CONTAINER 0x01u
  ------------------
  |  Branch (308:8): [True: 0, False: 0]
  ------------------
  309|      0|				size_t sz_off = (certs[i].key_pair_id == CE_AT_KEYEXCHANGE)
  ------------------
  |  |   44|      0|#define CE_AT_KEYEXCHANGE	1u
  ------------------
  |  Branch (309:21): [True: 0, False: 0]
  ------------------
  310|      0|								? rec + CE_CMAP_KX_SIZE_OFFSET
  ------------------
  |  |   41|      0|#define CE_CMAP_KX_SIZE_OFFSET	84u
  ------------------
  311|      0|								: rec + CE_CMAP_SIG_SIZE_OFFSET;
  ------------------
  |  |   40|      0|#define CE_CMAP_SIG_SIZE_OFFSET 82u
  ------------------
  312|      0|				unsigned kbits = (unsigned)cmap_buf[sz_off] | ((unsigned)cmap_buf[sz_off + 1] << 8);
  313|      0|				if (kbits != 0) {
  ------------------
  |  Branch (313:9): [True: 0, False: 0]
  ------------------
  314|      0|					certs[i].key_size_bits = kbits;
  315|      0|					certs[i].key_fid = ce_private_key_fid(ci, certs[i].key_pair_id);
  316|      0|				}
  317|      0|			}
  318|      0|		}
  319|    184|		sc_log(card->ctx,
  ------------------
  |  |   71|    184|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|    184|				"srbeid: cert[%d] \"%s\" cert_fid=0x%04x key_fid=0x%04x key_size=%u",
  321|    184|				i, certs[i].label, certs[i].cert_fid,
  322|    184|				certs[i].key_fid, certs[i].key_size_bits);
  323|    184|	}
  324|       |
  325|     84|	*certs_out = certs;
  326|     84|	certs = NULL;
  327|     84|	r = ncerts;
  328|       |
  329|    215|out:
  330|    215|	free(dir_buf);
  331|    215|	free(mscp_buf);
  332|    215|	free(cmap_buf);
  333|    215|	free(root_entries);
  334|    215|	free(mscp_entries);
  335|    215|	free(certs);
  336|    215|	return r;
  337|     84|}
pkcs15-srbeid.c:srbeid_read_file:
   73|    526|{
   74|    526|	sc_path_t path = {0};
   75|    526|	sc_file_t *file = NULL;
   76|    526|	u8 *buf;
   77|    526|	int r;
   78|       |
   79|    526|	*buf_out = NULL;
   80|    526|	*out_len = 0;
   81|       |
   82|    526|	path.value[0] = (u8)((fid >> 8) & 0xFF);
   83|    526|	path.value[1] = (u8)(fid & 0xFF);
   84|    526|	path.len = 2;
   85|    526|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    526|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
   86|       |
   87|    526|	r = sc_select_file(card, &path, &file);
   88|    526|	if (r < 0)
  ------------------
  |  Branch (88:6): [True: 171, False: 355]
  ------------------
   89|    171|		return r;
   90|       |
   91|    355|	if (!file || file->size == 0) {
  ------------------
  |  Branch (91:6): [True: 0, False: 355]
  |  Branch (91:15): [True: 14, False: 341]
  ------------------
   92|     14|		sc_file_free(file);
   93|     14|		return SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
   94|     14|	}
   95|       |
   96|    341|	if (file->size > 65536) {
  ------------------
  |  Branch (96:6): [True: 0, False: 341]
  ------------------
   97|      0|		sc_file_free(file);
   98|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
   99|      0|	}
  100|       |
  101|    341|	buf = malloc(file->size);
  102|    341|	if (!buf) {
  ------------------
  |  Branch (102:6): [True: 0, False: 341]
  ------------------
  103|      0|		sc_file_free(file);
  104|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  105|      0|	}
  106|       |
  107|    341|	r = sc_read_binary(card, 0, buf, file->size, 0);
  108|    341|	sc_file_free(file);
  109|    341|	if (r < 0) {
  ------------------
  |  Branch (109:6): [True: 30, False: 311]
  ------------------
  110|     30|		free(buf);
  111|     30|		return r;
  112|     30|	}
  113|       |
  114|    311|	*buf_out = buf;
  115|    311|	*out_len = (size_t)r;
  116|    311|	return SC_SUCCESS;
  ------------------
  |  |   28|    311|#define SC_SUCCESS				0
  ------------------
  117|    341|}
pkcs15-srbeid.c:ce_parse_dir:
  138|    258|{
  139|    258|	size_t count, i;
  140|    258|	ce_dir_entry_t *entries;
  141|       |
  142|    258|	*entries_out = NULL;
  143|    258|	if (len < CE_DIR_HEADER_SIZE)
  ------------------
  |  |   47|    258|#define CE_DIR_HEADER_SIZE	10u
  ------------------
  |  Branch (143:6): [True: 3, False: 255]
  ------------------
  144|      3|		return -1;
  145|       |
  146|    255|	count = (size_t)data[6] | ((size_t)data[7] << 8);
  147|    255|	if (count == 0)
  ------------------
  |  Branch (147:6): [True: 1, False: 254]
  ------------------
  148|      1|		return 0;
  149|       |
  150|       |	/* Bound count against buffer size before allocation. */
  151|    254|	if (count > (len - CE_DIR_HEADER_SIZE) / CE_DIR_ENTRY_SIZE)
  ------------------
  |  |   47|    254|#define CE_DIR_HEADER_SIZE	10u
  ------------------
              	if (count > (len - CE_DIR_HEADER_SIZE) / CE_DIR_ENTRY_SIZE)
  ------------------
  |  |   48|    254|#define CE_DIR_ENTRY_SIZE	12u
  ------------------
  |  Branch (151:6): [True: 16, False: 238]
  ------------------
  152|     16|		return -1;
  153|       |
  154|    238|	entries = calloc(count, sizeof(ce_dir_entry_t));
  155|    238|	if (!entries)
  ------------------
  |  Branch (155:6): [True: 0, False: 238]
  ------------------
  156|      0|		return -1;
  157|       |
  158|  21.6k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (158:14): [True: 21.3k, False: 238]
  ------------------
  159|  21.3k|		size_t off = CE_DIR_HEADER_SIZE + i * CE_DIR_ENTRY_SIZE;
  ------------------
  |  |   47|  21.3k|#define CE_DIR_HEADER_SIZE	10u
  ------------------
              		size_t off = CE_DIR_HEADER_SIZE + i * CE_DIR_ENTRY_SIZE;
  ------------------
  |  |   48|  21.3k|#define CE_DIR_ENTRY_SIZE	12u
  ------------------
  160|  21.3k|		int k;
  161|       |
  162|       |		/* Name: up to 8 ASCII chars, may not be NUL-terminated on card. */
  163|  21.3k|		memcpy(entries[i].name, data + off, 8);
  164|  21.3k|		entries[i].name[8] = '\0';
  165|       |		/* Strip trailing spaces/NULs. */
  166|  21.3k|		k = 7;
  167|  39.6k|		while (k >= 0 && (entries[i].name[k] == ' ' || entries[i].name[k] == '\0'))
  ------------------
  |  Branch (167:10): [True: 39.5k, False: 92]
  |  Branch (167:21): [True: 322, False: 39.2k]
  |  Branch (167:50): [True: 17.9k, False: 21.3k]
  ------------------
  168|  18.2k|			entries[i].name[k--] = '\0';
  169|  21.3k|		entries[i].fid = (unsigned)data[off + 8] | ((unsigned)data[off + 9] << 8);
  170|  21.3k|		entries[i].is_dir = (data[off + 10] != 0);
  171|  21.3k|	}
  172|       |
  173|    238|	*entries_out = entries;
  174|    238|	return (int)count;
  175|    238|}
pkcs15-srbeid.c:srbeid_read_cert_der:
  350|    184|{
  351|    184|	u8 *raw = NULL;
  352|    184|	size_t raw_len = 0;
  353|    184|	const u8 *data;
  354|    184|	size_t dlen;
  355|    184|	int r;
  356|       |
  357|    184|	*der_out = NULL;
  358|    184|	*der_len_out = 0;
  359|       |
  360|    184|	r = srbeid_read_file(card, cert_fid, &raw, &raw_len);
  361|    184|	if (r < 0)
  ------------------
  |  Branch (361:6): [True: 140, False: 44]
  ------------------
  362|    140|		return r;
  363|       |
  364|     44|	if (raw_len < 6) {
  ------------------
  |  Branch (364:6): [True: 14, False: 30]
  ------------------
  365|     14|		free(raw);
  366|     14|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     14|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  367|     14|	}
  368|       |
  369|       |	/* Skip 2-byte CardFS length prefix. */
  370|     30|	data = raw + 2;
  371|     30|	dlen = raw_len - 2;
  372|       |
  373|     30|	if (dlen >= 4 && data[0] == 0x01 && data[1] == 0x00) {
  ------------------
  |  Branch (373:6): [True: 30, False: 0]
  |  Branch (373:19): [True: 5, False: 25]
  |  Branch (373:38): [True: 4, False: 1]
  ------------------
  374|       |		/* zlib-compressed DER */
  375|      4|#ifdef ENABLE_ZLIB
  376|      4|		size_t uncompressed_len = (size_t)data[2] | ((size_t)data[3] << 8);
  377|      4|		u8 *der = NULL;
  378|       |
  379|      4|		r = sc_decompress_alloc(&der, &uncompressed_len,
  380|      4|				data + 4, dlen - 4, COMPRESSION_ZLIB);
  ------------------
  |  |   27|      4|#define COMPRESSION_ZLIB	1
  ------------------
  381|      4|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
  |  Branch (381:7): [True: 4, False: 0]
  ------------------
  382|      4|			sc_log(card->ctx, "srbeid: zlib decompress failed (ret=%d)", 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__
  |  |  ------------------
  ------------------
  383|      4|			free(raw);
  384|      4|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  385|      4|		}
  386|      0|		*der_out = der;
  387|      0|		*der_len_out = uncompressed_len;
  388|       |#else
  389|       |		sc_log(card->ctx, "srbeid: cert is zlib-compressed but zlib not available");
  390|       |		free(raw);
  391|       |		return SC_ERROR_NOT_SUPPORTED;
  392|       |#endif
  393|     26|	} else if (dlen >= 1 && data[0] == 0x30) {
  ------------------
  |  Branch (393:13): [True: 26, False: 0]
  |  Branch (393:26): [True: 1, False: 25]
  ------------------
  394|       |		/* Uncompressed DER (ASN.1 SEQUENCE tag). */
  395|      1|		u8 *der = malloc(dlen);
  396|      1|		if (!der) {
  ------------------
  |  Branch (396:7): [True: 0, False: 1]
  ------------------
  397|      0|			free(raw);
  398|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  399|      0|		}
  400|      1|		memcpy(der, data, dlen);
  401|      1|		*der_out = der;
  402|      1|		*der_len_out = dlen;
  403|     25|	} else {
  404|     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__
  |  |  ------------------
  ------------------
  405|     25|				"srbeid: cert FID 0x%04x: unknown format (byte0=0x%02x)",
  406|     25|				cert_fid, data[0]);
  407|     25|		free(raw);
  408|     25|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     25|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  409|     25|	}
  410|       |
  411|      1|	free(raw);
  412|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  413|     30|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

LLVMFuzzerTestOneInput:
   31|  16.9k|{
   32|  16.9k|    struct sc_context *ctx = NULL;
   33|  16.9k|    struct sc_card *card = NULL;
   34|  16.9k|    struct sc_pkcs15_card *p15card = NULL;
   35|  16.9k|    struct sc_reader *reader = NULL;
   36|  16.9k|    struct sc_pkcs15_object *obj;
   37|       |
   38|  16.9k|    sc_establish_context(&ctx, "fuzz");
   39|  16.9k|    if (!ctx)
  ------------------
  |  Branch (39:9): [True: 0, False: 16.9k]
  ------------------
   40|      0|        return 0;
   41|       |
   42|  16.9k|    if (fuzz_connect_card(ctx, &card, &reader, Data, Size) != SC_SUCCESS)
  ------------------
  |  |   28|  16.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (42:9): [True: 3.12k, False: 13.8k]
  ------------------
   43|  3.12k|        goto err;
   44|       |
   45|  13.8k|    if (SC_SUCCESS == sc_pkcs15_bind(card, NULL, &p15card)
  ------------------
  |  |   28|  13.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (45:9): [True: 6.19k, False: 7.63k]
  ------------------
   46|  6.19k|        && p15card) {
  ------------------
  |  Branch (46:12): [True: 6.19k, False: 0]
  ------------------
   47|  6.19k|        const uint8_t *in, *param;
   48|  6.19k|        uint16_t in_len, param_len;
   49|  6.19k|        fuzz_get_chunk(reader, &in, &in_len);
   50|  6.19k|        fuzz_get_chunk(reader, &param, &param_len);
   51|  49.9k|        for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (51:39): [True: 43.8k, False: 6.19k]
  ------------------
   52|  43.8k|            u8 buf[0xFFFF];
   53|  43.8k|            size_t i;
   54|       |
   55|  43.8k|            int decipher_flags[] = {SC_ALGORITHM_RSA_RAW,
  ------------------
  |  |  102|  43.8k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   56|  43.8k|                SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  110|  43.8k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  105|  43.8k|#define SC_ALGORITHM_RSA_PAD_ANSI	0x00000004
  ------------------
   57|  43.8k|                SC_ALGORITHM_RSA_PAD_ISO9796};
  ------------------
  |  |  106|  43.8k|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
   58|   219k|            for (i = 0; i < sizeof decipher_flags/sizeof *decipher_flags; i++) {
  ------------------
  |  Branch (58:25): [True: 175k, False: 43.8k]
  ------------------
   59|   175k|                sc_pkcs15_decipher(p15card, obj, decipher_flags[i],
   60|   175k|                        in, in_len, buf, sizeof buf, NULL);
   61|   175k|            }
   62|       |
   63|  43.8k|            i = sizeof buf;
   64|  43.8k|            sc_pkcs15_derive(p15card, obj, 0,
   65|  43.8k|                    in, in_len, buf, &i);
   66|       |
   67|  43.8k|            int wrap_flags[] = {0, SC_ALGORITHM_AES_ECB, SC_ALGORITHM_AES_CBC_PAD,
  ------------------
  |  |  206|  43.8k|#define SC_ALGORITHM_AES_ECB		 0x01000000
  ------------------
                          int wrap_flags[] = {0, SC_ALGORITHM_AES_ECB, SC_ALGORITHM_AES_CBC_PAD,
  ------------------
  |  |  208|  43.8k|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
   68|  43.8k|                SC_ALGORITHM_AES_CBC};
  ------------------
  |  |  207|  43.8k|#define SC_ALGORITHM_AES_CBC		 0x02000000
  ------------------
   69|   219k|            for (i = 0; i < sizeof wrap_flags/sizeof *wrap_flags; i++) {
  ------------------
  |  Branch (69:25): [True: 175k, False: 43.8k]
  ------------------
   70|       |                /* see `pkcs15_create_secret_key` in
   71|       |                 * `src/pkcs11/framework-pkc15.c` for creating a temporary
   72|       |                 * secret key for wrapping/unwrapping */
   73|   175k|                size_t l = sizeof buf;
   74|   175k|                struct sc_pkcs15_object target_key;
   75|   175k|                struct sc_pkcs15_skey_info skey_info;
   76|   175k|                uint16_t len;
   77|   175k|                memset(&target_key, 0, sizeof target_key);
   78|   175k|                memset(&skey_info, 0, sizeof skey_info);
   79|   175k|                target_key.type = SC_PKCS15_TYPE_SKEY;
  ------------------
  |  |  432|   175k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
   80|   175k|                target_key.flags = 2; /* TODO not sure what these mean */
   81|   175k|                target_key.session_object = 1;
   82|   175k|                target_key.data = &skey_info;
   83|   175k|                skey_info.usage = SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_WRAP
  ------------------
  |  |  310|   175k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
                              skey_info.usage = SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_WRAP
  ------------------
  |  |  309|   175k|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
   84|   175k|                    | SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  305|   175k|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
                                  | SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|   175k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
   85|   175k|                skey_info.native = 0; /* card can not use this */
   86|   175k|                skey_info.access_flags = 0; /* looks like not needed */
   87|   175k|                skey_info.key_type = 0x1fUL; /* CKK_AES */
   88|   175k|                skey_info.value_len = 128;
   89|   175k|                fuzz_get_chunk(reader, (const u8 **) &skey_info.data.value, &len);
   90|   175k|                skey_info.data.len = len;
   91|       |
   92|   175k|                sc_pkcs15_unwrap(p15card, obj, &target_key, wrap_flags[i],
   93|   175k|                        in, in_len, param, param_len);
   94|   175k|                sc_pkcs15_wrap(p15card, obj, &target_key, wrap_flags[i],
   95|   175k|                        buf, &l, in, in_len);
   96|   175k|            }
   97|       |
   98|  43.8k|            int signature_flags[] = {SC_ALGORITHM_RSA_RAW,
  ------------------
  |  |  102|  43.8k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   99|  43.8k|                SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  109|  43.8k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  105|  43.8k|#define SC_ALGORITHM_RSA_PAD_ANSI	0x00000004
  ------------------
  100|  43.8k|                SC_ALGORITHM_RSA_PAD_ISO9796,
  ------------------
  |  |  106|  43.8k|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  101|  43.8k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA1,
  ------------------
  |  |  107|  43.8k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA1,
  ------------------
  |  |  145|  43.8k|#define SC_ALGORITHM_MGF1_SHA1		0x00100000
  ------------------
  102|  43.8k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA256,
  ------------------
  |  |  107|  43.8k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA256,
  ------------------
  |  |  146|  43.8k|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
  103|  43.8k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA384,
  ------------------
  |  |  107|  43.8k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA384,
  ------------------
  |  |  147|  43.8k|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
  104|  43.8k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA512,
  ------------------
  |  |  107|  43.8k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA512,
  ------------------
  |  |  148|  43.8k|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
  105|  43.8k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA224,
  ------------------
  |  |  107|  43.8k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA224,
  ------------------
  |  |  149|  43.8k|#define SC_ALGORITHM_MGF1_SHA224	0x01000000
  ------------------
  106|  43.8k|                SC_ALGORITHM_ECDSA_RAW, SC_ALGORITHM_ECDSA_HASH_SHA1,
  ------------------
  |  |  174|  43.8k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
                              SC_ALGORITHM_ECDSA_RAW, SC_ALGORITHM_ECDSA_HASH_SHA1,
  ------------------
  |  |  176|  43.8k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|  43.8k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  107|  43.8k|                SC_ALGORITHM_ECDSA_HASH_SHA224, SC_ALGORITHM_ECDSA_HASH_SHA256,
  ------------------
  |  |  177|  43.8k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|  43.8k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
                              SC_ALGORITHM_ECDSA_HASH_SHA224, SC_ALGORITHM_ECDSA_HASH_SHA256,
  ------------------
  |  |  178|  43.8k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|  43.8k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  108|  43.8k|                SC_ALGORITHM_ECDSA_HASH_SHA384, SC_ALGORITHM_ECDSA_HASH_SHA512,
  ------------------
  |  |  179|  43.8k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|  43.8k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
                              SC_ALGORITHM_ECDSA_HASH_SHA384, SC_ALGORITHM_ECDSA_HASH_SHA512,
  ------------------
  |  |  180|  43.8k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|  43.8k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  109|  43.8k|                SC_ALGORITHM_GOSTR3410_RAW, SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411,
  ------------------
  |  |  156|  43.8k|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
                              SC_ALGORITHM_GOSTR3410_RAW, SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411,
  ------------------
  |  |  158|  43.8k|#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411	0x00080000
  ------------------
  110|  43.8k|                SC_ALGORITHM_GOSTR3410_HASHES,
  ------------------
  |  |  159|  43.8k|#define SC_ALGORITHM_GOSTR3410_HASHES		0x000A0000
  ------------------
  111|  43.8k|            };
  112|   832k|            for (i = 0; i < sizeof signature_flags/sizeof *signature_flags; i++) {
  ------------------
  |  Branch (112:25): [True: 788k, False: 43.8k]
  ------------------
  113|   788k|                sc_pkcs15_compute_signature(p15card, obj, signature_flags[i],
  114|   788k|                        in, in_len, buf, sizeof buf, NULL);
  115|   788k|            }
  116|       |
  117|  43.8k|            if (obj->type == SC_PKCS15_TYPE_AUTH_PIN) {
  ------------------
  |  |  445|  43.8k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  |  Branch (117:17): [True: 7.30k, False: 36.5k]
  ------------------
  118|  7.30k|                sc_pkcs15_verify_pin(p15card, obj, in, in_len);
  119|  7.30k|                sc_pkcs15_change_pin(p15card, obj, in, in_len, param, param_len);
  120|  7.30k|                sc_pkcs15_unblock_pin(p15card, obj, in, in_len, param, param_len);
  121|  7.30k|                sc_pkcs15_get_pin_info(p15card, obj);
  122|  7.30k|            }
  123|  43.8k|        }
  124|  6.19k|        sc_pkcs15_card_free(p15card);
  125|  6.19k|    }
  126|       |
  127|  16.9k|err:
  128|  16.9k|    sc_disconnect_card(card);
  129|  16.9k|    sc_release_context(ctx);
  130|       |
  131|  16.9k|    return 0;
  132|  13.8k|}

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

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

